Skip to content

Instantly share code, notes, and snippets.

@rooZzz rooZzz/Dog.java
Created Jul 9, 2016

Embed
What would you like to do?
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
You can’t perform that action at this time.