Created
February 13, 2016 10:58
-
-
Save anonymous/3e948798a709b9b1f7a0 to your computer and use it in GitHub Desktop.
StefMa @Medium - Developers, please write tests!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ""; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"))); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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