Skip to content

Instantly share code, notes, and snippets.

@AdamMc331
Created April 28, 2015 21:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AdamMc331/dccc3d38942ac6667b6f to your computer and use it in GitHub Desktop.
Save AdamMc331/dccc3d38942ac6667b6f to your computer and use it in GitHub Desktop.
public void test_getFormattedCurrency(){
// Test double without decimal points
assertEquals("$100.00", Utility.getFormattedCurrency(100));
// Test with one decimal point
assertEquals("$100.00", Utility.getFormattedCurrency(100.0));
// Test with two decimal points
assertEquals("$100.00", Utility.getFormattedCurrency(100.00));
// Test double with too many points
assertEquals("$100.00", Utility.getFormattedCurrency(100.001));
// Test with negative number
assertEquals("-$100.00", Utility.getFormattedCurrency(-100));
}
public void test_getDBDateString(){
// Test any date
assertEquals("2015-04-28", Utility.getDBDateString(new LocalDate(2015, 04, 28)));
// Test years under/over 4 digits
assertEquals("0123-04-28", Utility.getDBDateString(new LocalDate(123, 4, 28)));
assertEquals("12345-04-28", Utility.getDBDateString(new LocalDate(12345, 4, 28)));
}
public void test_getUIDateString(){
// Test any date
assertEquals("March 31, 2015", Utility.getUIDateString(new LocalDate(2015, 3, 31)));
// Test single digit day
assertEquals("March 01, 2015", Utility.getUIDateString(new LocalDate(2015, 3, 1)));
// Test year under 4 digits
assertEquals("March 01, 0001", Utility.getUIDateString(new LocalDate(1, 3, 1)));
// Test year over 4 digits
assertEquals("March 01, 12345", Utility.getUIDateString(new LocalDate(12345, 3, 1)));
}
public void test_getDateFromDb(){
// Test any date
assertEquals(new LocalDate(2015, 4, 28), Utility.getDateFromDb("2015-04-28"));
// Try with invalid string
try{
Utility.getDateFromDb("2015-0a4-31");
fail("Expected IllegalArgumentException.");
} catch(IllegalArgumentException expect){
// We have nothing to assert about this exception.
}
// Try with invalid date
try{
Utility.getDateFromDb("2015-04-31");
fail("Expected IllegalFieldValueException.");
} catch(IllegalArgumentException expect){
// Nothing to assert.
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment