<commit_before>/*
 * Copyright 2017, TeamDev Ltd. All rights reserved.
 *
 * Redistribution and use in source and/or binary forms, with or without
 * modification, must retain the above copyright notice and the following
 * disclaimer.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

package org.spine3.time;

import com.google.common.testing.NullPointerTester;
import org.junit.Test;

import java.text.ParseException;
import java.util.Calendar;

import static java.util.Calendar.getInstance;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.spine3.test.Tests.assertHasPrivateParameterlessCtor;
import static org.spine3.time.Calendars.getDay;
import static org.spine3.time.Calendars.getMonth;
import static org.spine3.time.Calendars.getYear;

public class LocalDatesShould {

    private static final int year = 2014;
    private static final MonthOfYear month = MonthOfYear.JULY;
    private static final int day = 20;

    @Test
    public void have_private_constructor() {
        assertHasPrivateParameterlessCtor(LocalDates.class);
    }

    @Test
    public void obtain_current_date() {
        final LocalDate today = LocalDates.now();
        final Calendar cal = getInstance();

        assertEquals(getYear(cal), today.getYear());
        assertEquals(getMonth(cal), today.getMonthValue());
        assertEquals(getDay(cal), today.getDay());
    }

    @Test
    public void obtain_date_from_year_month_day_values() {
        final LocalDate localDate = LocalDates.of(year, month, day);

        assertTrue(year == localDate.getYear());
        assertTrue(month == localDate.getMonth());
        assertTrue(day == localDate.getDay());
    }

    @Test
    public void obtain_date_in_past_before_specified_number_of_years() {
        final int yearsToSubstract = 2;
        final LocalDate localDate = LocalDates.of(year, month, day);
        final LocalDate fewYearsAgo = LocalDates.subtractYears(localDate, yearsToSubstract);

        assertTrue(year - yearsToSubstract == fewYearsAgo.getYear());
        assertTrue(month == fewYearsAgo.getMonth());
        assertTrue(day == fewYearsAgo.getDay());
    }

    @Test
    public void obtain_date_in_past_before_specified_number_of_months() {
        final int monthsToSubstract = 2;
        final LocalDate localDate = LocalDates.of(year, month, day);
        final LocalDate fewMonthsAgo = LocalDates.subtractMonths(localDate, monthsToSubstract);

        assertTrue(year == fewMonthsAgo.getYear());
        assertTrue(month.getNumber() - monthsToSubstract ==
                   fewMonthsAgo.getMonth().getNumber());
        assertTrue(day == fewMonthsAgo.getDay());
    }

    @Test
    public void obtain_date_in_past_before_specified_number_of_days() {
        final int daysToSubstract = 15;
        final LocalDate localDate = LocalDates.of(year, month, day);
        final LocalDate fewDaysAgo = LocalDates.subtractDays(localDate, daysToSubstract);

        assertTrue(year == fewDaysAgo.getYear());
        assertTrue(month == fewDaysAgo.getMonth());
        assertTrue(day - daysToSubstract == fewDaysAgo.getDay());
    }

    @Test
    public void obtain_date_in_future_after_specified_number_of_years() {
        final int yearsToAdd = 2;
        final LocalDate localDate = LocalDates.of(year, month, day);
        final LocalDate plusYears = LocalDates.addYears(localDate, yearsToAdd);

        assertTrue(year + yearsToAdd == plusYears.getYear());
        assertTrue(month == plusYears.getMonth());
        assertTrue(day == plusYears.getDay());
    }

    @Test
    public void obtain_date_in_future_after_specified_number_of_months() {
        final int monthsToAdd = 2;
        final LocalDate localDate = LocalDates.of(year, month, day);
        final LocalDate plusMonths = LocalDates.addMonths(localDate, monthsToAdd);

        assertTrue(year == plusMonths.getYear());
        assertTrue(month.getNumber() + monthsToAdd == plusMonths.getMonth().getNumber());
        assertTrue(day == plusMonths.getDay());
    }

    @Test
    public void obtain_date_in_future_after_specified_number_of_days() {
        final int daysToAdd = 8;
        final LocalDate localDate = LocalDates.of(year, month, day);
        final LocalDate plusDays = LocalDates.addDays(localDate, daysToAdd);

        assertTrue(year == plusDays.getYear());
        assertTrue(month == plusDays.getMonth());
        assertTrue(day + daysToAdd == plusDays.getDay());
    }

    @Test
    public void pass_null_tolerance_test() {
        new NullPointerTester()
                .setDefault(LocalDate.class, LocalDates.now())
                .setDefault(int.class, 1)
                .testAllPublicStaticMethods(LocalDates.class);
    }
<commit_msg>Change constant case naming at `LocalDatesShould`.<commit_after>/*
 * Copyright 2017, TeamDev Ltd. All rights reserved.
 *
 * Redistribution and use in source and/or binary forms, with or without
 * modification, must retain the above copyright notice and the following
 * disclaimer.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

package org.spine3.time;

import com.google.common.testing.NullPointerTester;
import org.junit.Test;

import java.text.ParseException;
import java.util.Calendar;

import static java.util.Calendar.getInstance;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.spine3.test.Tests.assertHasPrivateParameterlessCtor;
import static org.spine3.time.Calendars.getDay;
import static org.spine3.time.Calendars.getMonth;
import static org.spine3.time.Calendars.getYear;

public class LocalDatesShould {

    private static final int YEAR = 2014;
    private static final MonthOfYear MONTH = MonthOfYear.JULY;
    private static final int DAY = 20;

    @Test
    public void have_private_constructor() {
        assertHasPrivateParameterlessCtor(LocalDates.class);
    }

    @Test
    public void obtain_current_date() {
        final LocalDate today = LocalDates.now();
        final Calendar cal = getInstance();

        assertEquals(getYear(cal), today.getYear());
        assertEquals(getMonth(cal), today.getMonthValue());
        assertEquals(getDay(cal), today.getDay());
    }

    @Test
    public void obtain_date_from_year_month_day_values() {
        final LocalDate localDate = LocalDates.of(YEAR, MONTH, DAY);

        assertTrue(YEAR == localDate.getYear());
        assertTrue(MONTH == localDate.getMonth());
        assertTrue(DAY == localDate.getDay());
    }

    /*
     * Math with years
     */
    @Test
    public void subtract_years() {
        final int yearsToSubstract = 2;
        final LocalDate localDate = LocalDates.of(YEAR, MONTH, DAY);
        final LocalDate fewYearsAgo = LocalDates.subtractYears(localDate, yearsToSubstract);

        assertTrue(YEAR - yearsToSubstract == fewYearsAgo.getYear());
        assertTrue(MONTH == fewYearsAgo.getMonth());
        assertTrue(DAY == fewYearsAgo.getDay());
    }

    @Test
    public void add_years() {
        final int yearsToAdd = 2;
        final LocalDate localDate = LocalDates.of(YEAR, MONTH, DAY);
        final LocalDate plusYears = LocalDates.addYears(localDate, yearsToAdd);

        assertTrue(YEAR + yearsToAdd == plusYears.getYear());
        assertTrue(MONTH == plusYears.getMonth());
        assertTrue(DAY == plusYears.getDay());
    }

    /*
     * Math with months
     */
    @Test
    public void subtract_months() {
        final int monthsToSubstract = 2;
        final LocalDate localDate = LocalDates.of(YEAR, MONTH, DAY);
        final LocalDate fewMonthsAgo = LocalDates.subtractMonths(localDate, monthsToSubstract);

        assertTrue(YEAR == fewMonthsAgo.getYear());
        assertTrue(MONTH.getNumber() - monthsToSubstract ==
                   fewMonthsAgo.getMonth().getNumber());
        assertTrue(DAY == fewMonthsAgo.getDay());
    }

    @Test
    public void add_months() {
        final int monthsToAdd = 2;
        final LocalDate localDate = LocalDates.of(YEAR, MONTH, DAY);
        final LocalDate plusMonths = LocalDates.addMonths(localDate, monthsToAdd);

        assertTrue(YEAR == plusMonths.getYear());
        assertTrue(MONTH.getNumber() + monthsToAdd == plusMonths.getMonth().getNumber());
        assertTrue(DAY == plusMonths.getDay());
    }

    /*
     * Math with days
     */
    @Test
    public void subtract_days() {
        final int daysToSubstract = 15;
        final LocalDate localDate = LocalDates.of(YEAR, MONTH, DAY);
        final LocalDate fewDaysAgo = LocalDates.subtractDays(localDate, daysToSubstract);

        assertTrue(YEAR == fewDaysAgo.getYear());
        assertTrue(MONTH == fewDaysAgo.getMonth());
        assertTrue(DAY - daysToSubstract == fewDaysAgo.getDay());
    }

    @Test
    public void add_days() {
        final int daysToAdd = 8;
        final LocalDate localDate = LocalDates.of(YEAR, MONTH, DAY);
        final LocalDate plusDays = LocalDates.addDays(localDate, daysToAdd);

        assertTrue(YEAR == plusDays.getYear());
        assertTrue(MONTH == plusDays.getMonth());
        assertTrue(DAY + daysToAdd == plusDays.getDay());
    }

    @Test
    public void pass_null_tolerance_test() {
        new NullPointerTester()
                .setDefault(LocalDate.class, LocalDates.now())
                .setDefault(int.class, 1)
                .testAllPublicStaticMethods(LocalDates.class);
    }

{'fraction_non_alphanumeric': 0.09465284784004402, 'fraction_numerical': 0.0042190222874438224, 'mean_word_length': 3.3738467709586843, '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': '5560766', 'n_tokens_mistral': 3272, 'n_tokens_neox': 3086, 'n_words': 822}