Skip to content

Instantly share code, notes, and snippets.

@rooZzz
Created July 9, 2016 14:57
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 rooZzz/d1c710c2d9a0cfd94c7fbe663d671b57 to your computer and use it in GitHub Desktop.
Save rooZzz/d1c710c2d9a0cfd94c7fbe663d671b57 to your computer and use it in GitHub Desktop.
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;
}
}
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