<commit_before><commit_msg>PageTimeComparator unit tests<commit_after>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 ) );
    }

}
{'fraction_non_alphanumeric': 0.11764705882352941, 'fraction_numerical': 0.023017902813299233, 'mean_word_length': 3.0755208333333335, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2772220', 'n_tokens_mistral': 522, 'n_tokens_neox': 496, 'n_words': 112}