diff --git a/core-java-modules/core-java/src/main/java/com/baeldung/java/booleanoperators/Car.java b/core-java-modules/core-java/src/main/java/com/baeldung/java/booleanoperators/Car.java index 8043b6dd93..7394895325 100644 --- a/core-java-modules/core-java/src/main/java/com/baeldung/java/booleanoperators/Car.java +++ b/core-java-modules/core-java/src/main/java/com/baeldung/java/booleanoperators/Car.java @@ -17,4 +17,20 @@ public class Car { public boolean isManual() { return manual; } + + static Car dieselAndManualCar() { + return new Car(true, true); + } + + static Car dieselAndAutomaticCar() { + return new Car(true, false); + } + + static Car oilAndManualCar() { + return new Car(false, true); + } + + static Car oilAndAutomaticCar() { + return new Car(false, false); + } } diff --git a/core-java-modules/core-java/src/test/java/com/baeldung/java/booleanoperators/XorUnitTest.java b/core-java-modules/core-java/src/test/java/com/baeldung/java/booleanoperators/XorUnitTest.java index 0654d07f4f..70abc0266d 100644 --- a/core-java-modules/core-java/src/test/java/com/baeldung/java/booleanoperators/XorUnitTest.java +++ b/core-java-modules/core-java/src/test/java/com/baeldung/java/booleanoperators/XorUnitTest.java @@ -8,56 +8,56 @@ class XorUnitTest { @Test void givenDieselManualCar_whenXorOldSchool_ThenFalse() { - Car car = new Car(true, true); + Car car = Car.dieselAndManualCar(); boolean dieselXorManual = (car.isDiesel() && !car.isManual()) || (!car.isDiesel() && car.isManual()); assertThat(dieselXorManual).isFalse(); } @Test void givenDieselAutomaticCar_whenXorOldSchool_ThenTrue() { - Car car = new Car(true, false); + Car car = Car.dieselAndAutomaticCar(); boolean dieselXorManual = (car.isDiesel() && !car.isManual()) || (!car.isDiesel() && car.isManual()); assertThat(dieselXorManual).isTrue(); } @Test void givenNonDieselManualCar_whenXorOldSchool_ThenTrue() { - Car car = new Car(false, true); + Car car = Car.oilAndManualCar(); boolean dieselXorManual = (car.isDiesel() && !car.isManual()) || (!car.isDiesel() && car.isManual()); assertThat(dieselXorManual).isTrue(); } @Test void givenNonDieselAutomaticCar_whenXorOldSchool_ThenFalse() { - Car car = new Car(false, false); + Car car = Car.oilAndAutomaticCar(); boolean dieselXorManual = (car.isDiesel() && !car.isManual()) || (!car.isDiesel() && car.isManual()); assertThat(dieselXorManual).isFalse(); } @Test void givenDieselManualCar_whenXor_ThenFalse() { - Car car = new Car(true, true); + Car car = Car.dieselAndManualCar(); boolean dieselXorManual = car.isDiesel() ^ car.isManual(); assertThat(dieselXorManual).isFalse(); } @Test void givenDieselAutomaticCar_whenXor_ThenTrue() { - Car car = new Car(true, false); + Car car = Car.dieselAndAutomaticCar(); boolean dieselXorManual = car.isDiesel() ^ car.isManual(); assertThat(dieselXorManual).isTrue(); } @Test void givenNonDieselManualCar_whenXor_ThenTrue() { - Car car = new Car(false, true); + Car car = Car.oilAndManualCar(); boolean dieselXorManual = car.isDiesel() ^ car.isManual(); assertThat(dieselXorManual).isTrue(); } @Test void givenNonDieselAutomaticCar_whenXor_ThenFalse() { - Car car = new Car(false, false); + Car car = Car.oilAndAutomaticCar(); boolean dieselXorManual = car.isDiesel() ^ car.isManual(); assertThat(dieselXorManual).isFalse(); }