From 9690a53d262e2695a2c5f3322666793343aeb56c Mon Sep 17 00:00:00 2001 From: Marcus Fihlon Date: Mon, 4 Nov 2024 17:33:29 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=85=20Add=20a=20tests=20for=20compare=20b?= =?UTF-8?q?y=20ID=20(on=20same=20date=20and=20time)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marcus Fihlon --- .../swiss/fihlon/apus/social/PostTest.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/test/java/swiss/fihlon/apus/social/PostTest.java b/src/test/java/swiss/fihlon/apus/social/PostTest.java index ffd042e..7d92f42 100644 --- a/src/test/java/swiss/fihlon/apus/social/PostTest.java +++ b/src/test/java/swiss/fihlon/apus/social/PostTest.java @@ -18,17 +18,13 @@ package swiss.fihlon.apus.social; import org.junit.jupiter.api.Test; -import swiss.fihlon.apus.event.Language; -import swiss.fihlon.apus.event.Room; -import swiss.fihlon.apus.event.Session; -import swiss.fihlon.apus.event.Speaker; import java.time.LocalDateTime; import java.util.ArrayList; import java.util.Collections; import java.util.List; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; class PostTest { @@ -42,18 +38,24 @@ void compareTo() { final var postFour = new Post("P4", now.minusHours(3), "", "", "", "", List.of(), false, false); final var postFive = new Post("P5", now.minusHours(4), "", "", "", "", List.of(), false, false); final var postSix = new Post("P6", now.minusHours(5), "", "", "", "", List.of(), false, false); + final var postSeven = new Post("P7", now.minusHours(6), "", "", "", "", List.of(), false, false); + final var postEight = new Post("P8", now.minusHours(6), "", "", "", "", List.of(), false, false); final var unsortedPosts = new ArrayList<>(List.of(postTwo, postSix, postThree, postFour, postFive, postOne)); Collections.shuffle(unsortedPosts); - final var sortedPosts = unsortedPosts.stream().sorted().toList(); - System.out.println(sortedPosts); - assertEquals(postOne, sortedPosts.get(0)); + unsortedPosts.add(postEight); // P8 before P7 + unsortedPosts.add(postSeven); // both have the same date and time + + final var sortedPosts = unsortedPosts.stream().sorted().toList(); + assertEquals(postOne, sortedPosts.get(0)); // P1 to P6 ordered by date and time assertEquals(postTwo, sortedPosts.get(1)); assertEquals(postThree, sortedPosts.get(2)); assertEquals(postFour, sortedPosts.get(3)); assertEquals(postFive, sortedPosts.get(4)); assertEquals(postSix, sortedPosts.get(5)); + assertEquals(postSeven, sortedPosts.get(6)); // P7 before P8, order by ID + assertEquals(postEight, sortedPosts.get(7)); // both have the same date and time } @Test