Created
July 9, 2016 14:57
-
-
Save rooZzz/d1c710c2d9a0cfd94c7fbe663d671b57 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
package pet; | |
class Dog { | |
private static final String DEFAULT_NAME = "Spot"; | |
private String name; | |
Dog(String name) { | |
if (null == name) { | |
name = DEFAULT_NAME; | |
} | |
this.name = name; | |
} | |
String getName() { | |
return name; | |
} | |
} |
This file contains hidden or 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
package pet; | |
import org.junit.Test; | |
import org.junit.runner.RunWith; | |
import org.junit.runners.JUnit4; | |
import static org.junit.Assert.assertEquals; | |
@RunWith(JUnit4.class) | |
public class DogTest { | |
@Test | |
public void whenNullNameProvided_thenNameIsSpot() { | |
final String expected = "Spot"; | |
final String actual = (new Dog(null)).getName(); | |
assertEquals(expected, actual); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment