diff --git a/pom.xml b/pom.xml
index 8f6b076..4d8d01c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -39,6 +39,12 @@
joda-time
${joda.time.version}
+
+ org.apache.commons
+ commons-text
+ 1.9
+ compile
+
diff --git a/src/main/java/com/github/archarithms/.vs/ProjectSettings.json b/src/main/java/com/github/archarithms/.vs/ProjectSettings.json
new file mode 100644
index 0000000..f8b4888
--- /dev/null
+++ b/src/main/java/com/github/archarithms/.vs/ProjectSettings.json
@@ -0,0 +1,3 @@
+{
+ "CurrentProjectSetting": null
+}
\ No newline at end of file
diff --git a/src/main/java/com/github/archarithms/.vs/slnx.sqlite b/src/main/java/com/github/archarithms/.vs/slnx.sqlite
new file mode 100644
index 0000000..ac8d956
Binary files /dev/null and b/src/main/java/com/github/archarithms/.vs/slnx.sqlite differ
diff --git a/src/main/java/com/github/archarithms/App.java b/src/main/java/com/github/archarithms/App.java
index dcb6723..4e9689c 100644
--- a/src/main/java/com/github/archarithms/App.java
+++ b/src/main/java/com/github/archarithms/App.java
@@ -1,15 +1,64 @@
package com.github.archarithms;
+import org.apache.commons.text.*;// external library
+import java.time.Instant;
+import java.time.LocalDateTime;
+import java.time.ZoneId;
+import java.time.format.DateTimeFormatter;
+
+import java.util.Date;
+import java.text.SimpleDateFormat;
+
public class App
{
+ // convert string to title case
public static String convertToTitleCase(final String inpStr)
{
- return inpStr;
+ //check for null
+ if (inpStr == null)
+ {
+ throw new NullPointerException();
+ }
+
+ //lowercase conversion
+ String tempStr = inpStr.toLowerCase();
+
+ //remove non alphaNum chars with regex
+ tempStr = tempStr.replaceAll("[^a-zA-Z0-9]"," ");
+
+ //remove standard whitespace chars
+ tempStr = tempStr.trim();
+
+ String outStr = WordUtils.capitalize(tempStr);
+
+ return outStr;
+
}
+ //convert epoch tome value in seconds to Date format
public static String convertUnixToDateString(final Long inpUnixSeconds)
{
- return String.valueOf(inpUnixSeconds);
+ //check for null
+ if(inpUnixSeconds==null)
+ {
+ throw new NullPointerException();
+ }
+ else //convert from epoch time
+ {
+ return LocalDateTime.ofInstant(Instant.ofEpochSecond(inpUnixSeconds),
+ ZoneId.systemDefault()).format(DateTimeFormatter.ofPattern("MMMM d, YYYY"));
+ }
+
+ }
+
+ // get todays date and return as string
+ public static String convertUnixToDateString()
+ {
+ Date date = new Date();
+
+ long date_sec = date.getTime()/1000;
+
+ return convertUnixToDateString(date_sec);
}
}
diff --git a/src/test/java/com/github/archarithms/test/DateStringTests.java b/src/test/java/com/github/archarithms/test/DateStringTests.java
index 04e9943..cef70f6 100644
--- a/src/test/java/com/github/archarithms/test/DateStringTests.java
+++ b/src/test/java/com/github/archarithms/test/DateStringTests.java
@@ -4,7 +4,6 @@
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;
-
import com.github.archarithms.App;
/**
@@ -33,4 +32,26 @@ public void testConvertUnixToDateString() {
public void testNullCase() {
assertThrows(Exception.class, () -> App.convertUnixToDateString(null));
}
+
+// @Test
+// public void testestConvertUnixToDateStringWrongType() {
+// int wrongType = 50000;
+// assertThrows(Exception.class, () -> App.convertUnixToDateString(wrongType));
+
+//NOTE: cant test for wrong type as the function being tested does not accept generic types
+// will produce a compile time error due to strong tlyping rules
+//}
+
+ /**
+ * Test overloaded convertUnixToDateString no params
+ * NOTE: The testStr variable needs set to today's date or the test will fail
+ * Set testStr to todays date and then uncomment to run test.
+ */
+ /* @Test
+ public void testToday() {
+ String testStr = "May 12, 2021";
+ assertTrue(testStr.equals(App.convertUnixToDateString()));
+ } */
+
+
}
diff --git a/src/test/java/com/github/archarithms/test/TitleCaseTests.java b/src/test/java/com/github/archarithms/test/TitleCaseTests.java
index bd3bb2d..1b2db92 100644
--- a/src/test/java/com/github/archarithms/test/TitleCaseTests.java
+++ b/src/test/java/com/github/archarithms/test/TitleCaseTests.java
@@ -1,9 +1,7 @@
package com.github.archarithms.test;
import static org.junit.jupiter.api.Assertions.assertTrue;
-
import org.junit.jupiter.api.Test;
-
import com.github.archarithms.App;
/**
@@ -16,12 +14,22 @@ public class TitleCaseTests
* UNCOMMENT THE UNIT TESTS TO RUN THEM. FEEL FREE TO ADD MORE!
*/
+ /**
+ * Test the testConvertToTitleCase method
+ */
+ @Test
+ public void testConvertToTitleCaseNoWhitespace() {
+ String testStr = "Title Case";
+ assertTrue(testStr.equals(App.convertToTitleCase(" TITLE_CASE ")));
+ }
+
/**
* Test the testConvertToTitleCase method
*/
@Test
public void testConvertToTitleCase() {
String testStr = "Title Case";
+ System.out.println(App.convertToTitleCase("TITLE_CASE"));
assertTrue(testStr.equals(App.convertToTitleCase("TITLE_CASE")));
}