### Question:
PageTimeComparator implements Comparator< Page >, Serializable { public int compare( final Page p1, final Page p2 ) { if( p1 == null || p2 == null ) { log.error( "W1 or W2 is NULL in PageTimeComparator!"); return 0; } final Date w1LastMod = p1.getLastModified(); final Date w2LastMod = p2.getLastModified(); if( w1LastMod == null ) { log.error( "NULL MODIFY DATE WITH " + p1.getName() ); return 0; } else if( w2LastMod == null ) { log.error( "NULL MODIFY DATE WITH " + p2.getName() ); return 0; } final int timecomparison = w2LastMod.compareTo( w1LastMod ); if( timecomparison == 0 ) { return p1.compareTo( p2 ); } return timecomparison; }  int compare( final Page p1, final Page p2 );  }### Answer:
@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 ) ); }