Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@
<artifactId>joda-time</artifactId>
<version>${joda.time.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>1.9</version>
<scope>compile</scope>
</dependency>
</dependencies>

<build>
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/github/archarithms/.vs/ProjectSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"CurrentProjectSetting": null
}
Binary file not shown.
53 changes: 51 additions & 2 deletions src/main/java/com/github/archarithms/App.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
23 changes: 22 additions & 1 deletion src/test/java/com/github/archarithms/test/DateStringTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.junit.jupiter.api.Test;

import com.github.archarithms.App;

/**
Expand Down Expand Up @@ -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()));
} */


}
12 changes: 10 additions & 2 deletions src/test/java/com/github/archarithms/test/TitleCaseTests.java
Original file line number Diff line number Diff line change
@@ -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;

/**
Expand All @@ -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")));
}

Expand Down