You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jspwiki.apache.org by ju...@apache.org on 2019/10/12 17:12:12 UTC
[jspwiki] 02/05: PageTimeComparator unit tests
This is an automated email from the ASF dual-hosted git repository.
juanpablo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jspwiki.git
commit d1a2adcea9dc86165531ca9863e2f8a4e0c5aac4
Author: juanpablo <ju...@apache.org>
AuthorDate: Sat Oct 12 19:09:39 2019 +0200
PageTimeComparator unit tests
---
.../apache/wiki/pages/PageTimeComparatorTest.java | 52 ++++++++++++++++++++++
1 file changed, 52 insertions(+)
diff --git a/jspwiki-main/src/test/java/org/apache/wiki/pages/PageTimeComparatorTest.java b/jspwiki-main/src/test/java/org/apache/wiki/pages/PageTimeComparatorTest.java
new file mode 100644
index 0000000..ccc86e0
--- /dev/null
+++ b/jspwiki-main/src/test/java/org/apache/wiki/pages/PageTimeComparatorTest.java
@@ -0,0 +1,52 @@
+package org.apache.wiki.pages;
+
+import org.apache.wiki.TestEngine;
+import org.apache.wiki.WikiPage;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+import java.util.Date;
+
+
+/**
+ * Unit tests corresponding to {@link PageTimeComparator}.
+ */
+public class PageTimeComparatorTest {
+
+ TestEngine engine = TestEngine.build();
+ PageTimeComparator comparator = new PageTimeComparator();
+ WikiPage p1 = new WikiPage( engine, "A" );
+ WikiPage p2 = new WikiPage( engine, "B" );
+ WikiPage p3 = new WikiPage( engine, "A" );
+
+ @Test
+ void shouldCheckCompareByTimeGetsMoreRecentOnTop() {
+ p1.setLastModified( new Date( 0L ) );
+ p2.setLastModified( new Date( 1L ) );
+
+ Assertions.assertEquals( 1, comparator.compare( p1, p2 ) );
+ Assertions.assertEquals( -1, comparator.compare( p2, p1 ) );
+ }
+
+ @Test
+ void shouldCheckCompareByEqualsTimeUsesPageName() {
+ p1.setLastModified( new Date( 0L ) );
+ p2.setLastModified( new Date( 0L ) );
+
+ Assertions.assertEquals( -1, comparator.compare( p1, p2 ) );
+ }
+
+ @Test
+ void shouldCheckCompareByEqualsTimeAndNameUsesPageVersion() {
+ p1.setLastModified( new Date( 0L ) );
+ p3.setLastModified( new Date( 0L ) );
+ p1.setVersion( 1 );
+ p3.setVersion( 2 );
+
+ Assertions.assertEquals( -1, comparator.compare( p1, p3 ) );
+
+ p3.setVersion( 1 );
+ Assertions.assertEquals( 0, comparator.compare( p1, p3 ) );
+ }
+
+}