/*
 * 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 org.junit.Test;

import java.util.TimeZone;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.spine3.protobuf.Timestamps.MILLIS_PER_SECOND;
import static org.spine3.protobuf.Timestamps.MINUTES_PER_HOUR;
import static org.spine3.protobuf.Timestamps.SECONDS_PER_MINUTE;
import static org.spine3.test.Tests.hasPrivateParameterlessCtor;

@SuppressWarnings("InstanceMethodNamingConvention")
public class ZoneOffsetsShould {

    @Test
    public void has_private_constructor() {
        assertTrue(hasPrivateParameterlessCtor(ZoneOffsets.class));
    }

    @Test
    public void have_private_utility_constructor() {
        assertTrue(hasPrivateParameterlessCtor(ZoneOffsets.class));
    }

    @Test
    public void create_default_instance_according_to_place() {
        final int currentOffset = TimeZone.getDefault().getRawOffset()/(int)MILLIS_PER_SECOND;
        assertEquals(currentOffset, ZoneOffsets.getDefault().getAmountSeconds());
    }

    @Test
    public void create_instance_by_hours_offset() {
        final int secondsInTwoHours = secondsIn(2);
        assertEquals(secondsInTwoHours, ZoneOffsets.ofHours(2)
                                                   .getAmountSeconds());
    }

    @Test
    public void create_instance_by_hours_and_minutes_offset() {
        final int secondsIn8Hours45Minutes = secondsIn(8, 45);
        final int secondsInEuclaOffset = ZoneOffsets.ofHoursMinutes(8, 45)
                                                    .getAmountSeconds();
        assertEquals(secondsIn8Hours45Minutes, secondsInEuclaOffset);
    }

    @Test(expected = IllegalArgumentException.class)
    public void do_not_accept_more_than_18_hours() {
        ZoneOffsets.ofHours(15);
    }

    @Test(expected = IllegalArgumentException.class)
    public void do_not_accept_more_than_18_hours_by_abs() {
        ZoneOffsets.ofHours(-12);
    }

    @Test(expected = IllegalArgumentException.class)
    public void do_not_accept_more_than_60_minutes() {
        ZoneOffsets.ofHoursMinutes(10, 61);
    }

    @Test(expected = IllegalArgumentException.class)
    public void do_not_accept_more_than_17_hours_and_60_minutes() {
        ZoneOffsets.ofHoursMinutes(18, 30);
    }

    private int secondsIn(int hours) {
        return SECONDS_PER_MINUTE * MINUTES_PER_HOUR * hours;
    }

    private int secondsIn(int hours, int minutes) {
        return SECONDS_PER_MINUTE * MINUTES_PER_HOUR * hours + SECONDS_PER_MINUTE * minutes;
    }
}

@@ -1520,16 +1520,229 @@
 ould %7B%0A%0A
+    private static final int MIN_HOURS_OFFSET = -11;%0A    private static final int MAX_HOURS_OFFSET = 14;%0A    private static final int MIN_MINUTES_OFFSET = 0;%0A    private static final int MAX_MINUTES_OFFSET = 60;%0A%0A
     @Tes
@@ -2966,25 +2966,25 @@
 _more_than_1
-8
+4
 _hours() %7B%0A 
@@ -3014,10 +3014,28 @@
 urs(
+MAX_HOURS_OFFSET + 
 1
-5
 );%0A 
@@ -3134,17 +3134,17 @@
 e_than_1
-8
+1
 _hours_b
@@ -3185,11 +3185,28 @@
 urs(
--12
+MIN_HOURS_OFFSET - 1
 );%0A 
@@ -3358,17 +3358,37 @@
 tes(10, 
-6
+MAX_MINUTES_OFFSET + 
 1);%0A    
@@ -3550,14 +3550,33 @@
 tes(
-18, 30
+3, MIN_MINUTES_OFFSET - 1
 );%0A 
@@ -3585,32 +3585,39 @@
  %7D%0A%0A    private 
+static 
 int secondsIn(in
@@ -3708,16 +3708,23 @@
 private 
+static 
 int seco

Fix `ZoneOffsetShould` warnings.