From 916572d937d25d39f852e211a4be6832713dfd9c Mon Sep 17 00:00:00 2001 From: "github-classroom[bot]" <66690702+github-classroom[bot]@users.noreply.github.com> Date: Mon, 25 Nov 2024 00:19:55 +0000 Subject: [PATCH 1/2] Setting up GitHub Classroom Feedback From 2c7d0f268ec89847139866fd8f6e41b3d88f1f09 Mon Sep 17 00:00:00 2001 From: cla1427 <182035543+ClarisseLa@users.noreply.github.com> Date: Mon, 25 Nov 2024 20:11:12 +1300 Subject: [PATCH 2/2] Assertions --- pom.xml | 8 ++--- .../WhenWritingReadableAssertions.java | 30 ++++++++++--------- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/pom.xml b/pom.xml index 96d6ad9..6359435 100644 --- a/pom.xml +++ b/pom.xml @@ -13,8 +13,8 @@ UTF-8 - 12 - 12 + 11 + 11 @@ -92,8 +92,8 @@ org.apache.maven.plugins maven-compiler-plugin - 12 - 12 + 11 + 11 diff --git a/src/test/java/com/serenitydojo/WhenWritingReadableAssertions.java b/src/test/java/com/serenitydojo/WhenWritingReadableAssertions.java index d4f2dc3..c43cd42 100644 --- a/src/test/java/com/serenitydojo/WhenWritingReadableAssertions.java +++ b/src/test/java/com/serenitydojo/WhenWritingReadableAssertions.java @@ -6,6 +6,7 @@ import java.util.List; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.withinPercentage; public class WhenWritingReadableAssertions { @@ -17,7 +18,7 @@ public void whenTwoNumbersAreEqual() { int sum = a + b + c; // Check that the sum is 35 - assertThat(true).isFalse(); + assertThat(sum).isEqualTo(35); } @Test @@ -28,7 +29,7 @@ public void whenANumberIsGreaterThanAnother() { int sum = a + b + c; // Check that the sum is greater than 30 - assertThat(true).isFalse(); + assertThat(sum).isGreaterThan(30); } @Test @@ -38,15 +39,15 @@ public void whenANumberIsInACertainInterval() { int sum = a + b; // Check that the sum is between 10 and 20 - assertThat(true).isFalse(); + assertThat(sum).isBetween(10,20); } @Test public void whenANumberIsCloseToAnotherValue() { - double roughlyOneHundred = 99; + double sum = 99; // Check that the sum is within 10% of 100 - assertThat(true).isFalse(); + assertThat(sum).isCloseTo(100,withinPercentage(10)); } @Test @@ -54,7 +55,7 @@ public void whenAStringIsEqualToAnother() { String color = "red"; // Check that the string has a value of 'red' - assertThat(true).isFalse(); + assertThat(color).isEqualTo("red"); } @Test @@ -62,7 +63,7 @@ public void whenAStringIsEqualIgnoringCase() { String color = "RED"; // Check that the string has a value of 'red' (ignoring case) - assertThat(true).isFalse(); + assertThat(color).isEqualToIgnoringCase("red"); } @Test @@ -70,7 +71,7 @@ public void whenAStringContainsOnlyDigits() { String licenseNumber = "12345"; // Check that the value contains only digits - assertThat(true).isFalse(); + assertThat(licenseNumber).containsOnlyDigits(); } @Test @@ -78,7 +79,7 @@ public void whenAStringStartsWithAValue() { String colors = "red,green,blue"; // Check that the value starts with 'red' - assertThat(true).isFalse(); + assertThat(colors).startsWith("red"); } @Test @@ -86,7 +87,7 @@ public void whenAStringEndsWithAValue() { String colors = "red,green,blue"; // Check that the value ends with 'blue' - assertThat(true).isFalse(); + assertThat(colors).endsWith("blue"); } @@ -95,6 +96,7 @@ public void whenAListContainsAValue() { List colors = Arrays.asList("red","green","blue"); // Check that the list contains "red" + assertThat(colors).contains("red"); } @Test @@ -102,7 +104,7 @@ public void whenAListContainsASetOfValues() { List colors = Arrays.asList("red","green","blue"); // Check that the list contains "red" and "blue - assertThat(true).isFalse(); + assertThat(colors).contains("red","blue"); } @Test @@ -110,7 +112,7 @@ public void whenAListHasASpecificSize() { List colors = Arrays.asList("red","green","blue"); // Check that the list contains 3 elements - assertThat(true).isFalse(); + assertThat(colors).hasSize(3); } @Test @@ -118,7 +120,7 @@ public void whenAListContainsExactlyASetOfValues() { List colors = Arrays.asList("red","green","blue"); // Check that the list contains "red","green" and "blue" - assertThat(true).isFalse(); + assertThat(colors).containsExactly("red","green","blue"); } @Test @@ -126,7 +128,7 @@ public void whenAListContainsExactlyASetOfValuesInAnyOrder() { List colors = Arrays.asList("red","green","blue"); // Check that the list contains "red","blue" and "green" in any order - assertThat(true).isFalse(); + assertThat(colors).containsExactlyInAnyOrder("green","blue","red"); }