Add oving 4

This commit is contained in:
Andreas Omholt Olsen
2026-02-02 10:57:55 +01:00
parent 37b0f931ce
commit 7dd68c1ed8
41 changed files with 1702 additions and 0 deletions

View File

@@ -0,0 +1,74 @@
package oving4;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
public class PartnerTest {
private Partner p1;
private Partner p2;
@BeforeEach
public void setUp() {
p1 = new Partner("P1");
p2 = new Partner("P2");
}
@Test
@DisplayName("Check that the constructor initializes correctly")
public void testConstructor() {
assertNull(p1.getPartner());
assertNull(p2.getPartner());
assertThrows(IllegalArgumentException.class, () -> {
new Partner(null);
}, "Name cannot be null");
}
@Test
@DisplayName("Check that P1 and P2 are partners after p1.setPartner(p2)")
public void simplePartnership() {
assertNull(p1.getPartner());
assertNull(p2.getPartner());
p1.setPartner(p2);
assertEquals(p1.getPartner(), p2, "P1 should be partner to P2");
assertEquals(p2.getPartner(), p1, "P2 should be partner to P1");
}
@Test
@DisplayName("Check that one can split up a partnership")
public void partnershipWithDivorce() {
p1.setPartner(p2);
assertEquals(p1.getPartner(), p2, "P1 should be partner to P2");
assertEquals(p2.getPartner(), p1, "P2 should be partner to P1");
p1.setPartner(null);
assertNull(p1.getPartner());
assertNull(p2.getPartner());
}
@Test
@DisplayName("Check that combined breakup followed by the creation of a new partnership works")
public void swinger() {
Partner p3 = new Partner("P3");
Partner p4 = new Partner("P4");
p1.setPartner(p2);
p3.setPartner(p4);
assertEquals(p1.getPartner(), p2, "P1 should be the partner of P2");
assertEquals(p2.getPartner(), p1, "P2 should be the partner of P1");
assertEquals(p3.getPartner(), p4, "P3 should be the partner of P4");
assertEquals(p4.getPartner(), p3, "P4 should be the partner of P3");
p1.setPartner(p4);
assertEquals(p1.getPartner(), p4, "P4 should be the partner of P1");
assertEquals(p4.getPartner(), p1, "P1 should be the partner of P4");
assertNull(p2.getPartner());
assertNull(p3.getPartner());
}
}