Add oving 5
This commit is contained in:
58
src/test/java/oving5/named/Person2Test.java
Normal file
58
src/test/java/oving5/named/Person2Test.java
Normal file
@@ -0,0 +1,58 @@
|
||||
package oving5.named;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class Person2Test {
|
||||
|
||||
private Person2 person;
|
||||
private String given;
|
||||
private String family;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
given = "Hallvard";
|
||||
family = "Trætteberg";
|
||||
person = new Person2(String.format("%s %s", given, family));
|
||||
}
|
||||
|
||||
private static void testName(Person2 person, String givenName, String familyName) {
|
||||
assertEquals(givenName, person.getGivenName());
|
||||
assertEquals(familyName, person.getFamilyName());
|
||||
assertEquals(String.format("%s %s", givenName, familyName), person.getFullName());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Check that the constructor assigns the correct name to the person")
|
||||
public void testConstructor() {
|
||||
Person2Test.testName(person, given, family);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Check that setGivenName() assigns the correct name")
|
||||
public void testSetGivenName() {
|
||||
String newGiven = "Jens";
|
||||
person.setGivenName(newGiven);
|
||||
Person2Test.testName(person, newGiven, family);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Check that setFamilyName() assigns the correct name")
|
||||
public void testSetFamilyName() {
|
||||
String newFamily = "Olsen";
|
||||
person.setFamilyName(newFamily);
|
||||
Person2Test.testName(person, given, newFamily);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Check that setFullName() assigns the correct name")
|
||||
public void testSetFullName() {
|
||||
String newGiven = "Lisa";
|
||||
String newFamily = "Eriksen";
|
||||
String newFull = String.format("%s %s", newGiven, newFamily);
|
||||
person.setFullName(newFull);
|
||||
Person2Test.testName(person, newGiven, newFamily);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user