Skip to content

Instantly share code, notes, and snippets.

Created February 13, 2016 10:58
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 anonymous/3e948798a709b9b1f7a0 to your computer and use it in GitHub Desktop.
Save anonymous/3e948798a709b9b1f7a0 to your computer and use it in GitHub Desktop.
StefMa @Medium - Developers, please write tests!
public class MyClock {
public String getCurrentTime(TimeFormat format) {
switch (format) {
case GERMAN:
return "14:45 Uhr";
case AMERICAN:
return "2:45 PM";
case GERMAN_WITH_DATE:
return "14:45 Uhr, Freitag 12.02.2016";
case AMERICAN_WITH_DATE:
return "2:45 PM, Friday 02.12.2016";
default:
return "";
}
}
}
public class MyClockTest {
private MyClock mMyClock;
@Before
public void setUp() throws Exception {
mMyClock = new MyClock();
}
@Test
public void testGetCurrentName_ShouldReturnTimeInGermanFormat() throws Exception {
String germanTime = mMyClock.getCurrentTime(TimeFormat.GERMAN);
assertThat(germanTime, is(equalTo("14:45 Uhr")));
}
@Test
public void testGetCurrentName_ShouldReturnTimeInAmericanFormat() throws Exception {
String americanTime = mMyClock.getCurrentTime(TimeFormat.AMERICAN);
assertThat(americanTime, is(equalTo("2:45 PM")));
}
@Test
public void testGetCurrentName_ShouldReturnTimeInGermanFormatWithDate() throws Exception {
String americanTime = mMyClock.getCurrentTime(TimeFormat.GERMAN_WITH_DATE);
assertThat(americanTime, is(equalTo("14:45 Uhr, Freitag 12.02.2016")));
}
@Test
public void testGetCurrentName_ShouldReturnTimeInAmericanFormatWithDate() throws Exception {
String americanTime = mMyClock.getCurrentTime(TimeFormat.AMERICAN_WITH_DATE);
assertThat(americanTime, is(equalTo("2:45 PM, Friday 02.12.2016")));
}
}
public enum TimeFormat {
GERMAN, AMERICAN, GERMAN_WITH_DATE, AMERICAN_WITH_DATE
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment