From 15baa09453edb1ca424d2e11a83a4a4360d52fd7 Mon Sep 17 00:00:00 2001 From: PPemberton Date: Wed, 12 May 2021 02:44:00 -0500 Subject: [PATCH 1/2] completed code challenge --- pom.xml | 6 ++ .../archarithms/.vs/ProjectSettings.json | 3 + .../com/github/archarithms/.vs/slnx.sqlite | Bin 0 -> 90112 bytes src/main/java/com/github/archarithms/App.java | 53 +++++++++++++++++- .../archarithms/test/DateStringTests.java | 23 +++++++- .../archarithms/test/TitleCaseTests.java | 12 +++- 6 files changed, 92 insertions(+), 5 deletions(-) create mode 100644 src/main/java/com/github/archarithms/.vs/ProjectSettings.json create mode 100644 src/main/java/com/github/archarithms/.vs/slnx.sqlite 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 0000000000000000000000000000000000000000..ac8d956261717fa30055c97187aca549f07384ef GIT binary patch literal 90112 zcmeI5U2G%Qb%19$TvDW@9XYa=ZWT9!z`=^y9W6Qh_r^fE)M%GpE+z42*9(;(=I3&k zHbt(+B5}RpsC?L^xpa5 z{BXFGwXJrIo`EFJ%suDcbH97enR{nOQhl$|)ezSi3=brYOHnHnO;dl$aTG;;h`%r3 zZ);n{J3;FJf6|WqS-T%no0oUb5n=WVBJ(x&i=~g3Ru*qYKZv})@ar%W+GBng_&iVx zygsW6IRBL)us|#wzj8htyTjAty>4Gc59`MV@}RecI^BL(>kj&DW4C{AyW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x|8yxm6UxMm_Ls{#k9t}*fhj9+&7LI((oSA{H{VX?$ne9eGNT4i3V9X z2ruBf4k_1N2Yq^2Lmh;Zfr8qTJ>n16jYr!zCdDt#3YLk4e^tKWGSR`KHQ6@|zzYUp zWuDPn=mF}hQeT^6^y+-0eXE*lv`4EIe{Y=)$5JW!eaGDrH)$WHE3?9V!o)Y`C#BPY zdxBN0b^pW)8^8GSk9$jFexQBnTb5p)|GSyU?#^j$0Zwq64r<%>Y!@OfyU2vF#ZA)7 zjO6ium~AF^p4|7P%zI9+oDajpk1~0t<47&uhZZweYVhy_9)6taPRCPD!K~*R|NkC- zkl+7@_y5oQMh7$q1b_e#00KY&2mk>f00e*l5C8%|;7kd?`u|LELt{Vy2mk>f00e*l z5C8%|00;m9AOHlO2?6-~f6oLvGztWO01yBIKmZ5;0U!VbfB+Bx0zlwQ3BdFJGsO*! d0RbQY1b_e#00KY&2mk>f00e*l5O^j8{s;O=9q0f6 literal 0 HcmV?d00001 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..a8be7b4 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 . + * 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"))); } From 635791661f9b67ad8f75ebe9a99d4f5faba59452 Mon Sep 17 00:00:00 2001 From: PPemberton Date: Wed, 12 May 2021 02:46:05 -0500 Subject: [PATCH 2/2] added comment code --- src/test/java/com/github/archarithms/test/DateStringTests.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/com/github/archarithms/test/DateStringTests.java b/src/test/java/com/github/archarithms/test/DateStringTests.java index a8be7b4..cef70f6 100644 --- a/src/test/java/com/github/archarithms/test/DateStringTests.java +++ b/src/test/java/com/github/archarithms/test/DateStringTests.java @@ -43,7 +43,7 @@ public void testNullCase() { //} /** - * Test . + * 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. */