package net.time4j.scale;

import net.time4j.Moment;
import net.time4j.PlainTimestamp;
import net.time4j.SI;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.junit.Assert.assertThat;

// TODO: needs adjustment if any new leap second is announced
@RunWith(JUnit4.class)
public class NextLeapSecondTest {

    @Test
    public void nextLS() {
        if (LeapSeconds.getInstance().getCount() <= 25) {
            assertThat(
                Moment.nextLeapSecond(),
                nullValue());
        } else {
            System.out.println("Warning: NextLeapSecondTest not up-to-date.");
        }
    }

    @Test
    public void nextLSIfKnown() {
        if (LeapSeconds.getInstance().getCount() <= 25) {
            LeapSeconds.getInstance().registerPositiveLS(2115, 12, 31);
            assertThat(
                Moment.nextLeapSecond(),
                is(
                    PlainTimestamp.of(2115, 12, 31, 23, 59, 59).atUTC()
                    .plus(1, SI.SECONDS)));
        } else {
            System.out.println("Warning: NextLeapSecondTest not up-to-date.");
        }
    }

}
@@ -336,70 +336,8 @@
 t;%0A%0A
-// TODO: needs adjustment if any new leap second is announced%0A
 @Run
@@ -422,16 +422,20 @@
 d nextLS
+2012
 () %7B%0A   
@@ -443,246 +443,405 @@
     
-if (LeapSeconds.getInstance().getCount() %3C= 25) %7B%0A            assertThat(%0A                Moment.nextLeapSecond(),%0A                nullValue());%0A        %7D else %7B%0A            System.out.println(%22Warning: NextLeapSecondTest not up-to-date.%22
+Moment ref = PlainDate.of(2012, 1, 1).atTime(0, 0).atUTC();%0A        if (LeapSeconds.getInstance().isEnabled()) %7B%0A            Moment expected = %0A                PlainDate.of(2012, 6, 30).atTime(23, 59, 59).atUTC().plus(1, SI.SECONDS);%0A            assertThat(ref.with(Moment.nextLeapSecond()), is(expected));%0A        %7D else %7B%0A            assertThat(ref.with(Moment.nextLeapSecond()), is(nullValue())
 );%0A 
@@ -942,24 +942,19 @@
 e().
-getCount() %3C= 25
+isEnabled()
 ) %7B%0A
@@ -1025,16 +1025,88 @@
 2, 31);%0A
+            Moment ref = PlainDate.of(2100, 1, 1).atTime(0, 0).atUTC();%0A
         
@@ -1133,24 +1133,33 @@
             
+ref.with(
 Moment.nextL
@@ -1169,16 +1169,17 @@
 Second()
+)
 ,%0A      
@@ -1308,32 +1308,33 @@
 NDS)));%0A        
+ 
 %7D else %7B%0A       
@@ -1342,84 +1342,298 @@
     
-System.out.println(%22Warning: NextLeapSecondTest not up-to-date.%22);%0A        %7D
+assertThat(ref.with(Moment.nextLeapSecond()), is(nullValue()));%0A       %7D%0A    %7D%0A%0A    @Test%0A    public void nextLSIfUnknown() %7B%0A        Moment ref = PlainDate.of(2100, 1, 1).atTime(0, 0).atUTC();%0A        assertThat(%0A            ref.with(Moment.nextLeapSecond()),%0A            is(nullValue()));
 %0A   
@@ -1637,8 +1637,9 @@
     %7D%0A%0A%7D
+%0A

test adjustment