package de.philipphager.disclosure.database.util.adapters;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.runners.MockitoJUnitRunner;
import org.threeten.bp.LocalDateTime;

import static org.assertj.core.api.Assertions.assertThat;
import static org.threeten.bp.temporal.ChronoUnit.MILLIS;

@RunWith(MockitoJUnitRunner.class) public class LocalDateTimeColumnAdapterShould {
  @InjectMocks protected LocalDateTimeColumnAdapter adapter;

  @Test public void encodeMillisToStartOfAtUtcStandard() {
    LocalDateTime utcStartOfTime = LocalDateTime.of(1970, 1, 1, 1, 0, 0, 0);

    Long millis = adapter.encode(utcStartOfTime);

    assertThat(millis).isEqualTo(0);
  }

  @Test public void encodeMillisWithCorrectDuration() {
    LocalDateTime start = LocalDateTime.of(1970, 1, 1, 1, 0, 0, 0);
    LocalDateTime end = LocalDateTime.of(2016, 1, 1, 1, 0, 0, 0);
    long duration = start.until(end, MILLIS);

    Long millis = adapter.encode(end);

    assertThat(millis).isEqualTo(duration);
  }

  @Test public void decodeDateFromMillisStartCorrectly() {
    LocalDateTime utcStartOfTime = LocalDateTime.of(1970, 1, 1, 1, 0, 0, 0);
    LocalDateTime date = adapter.decode(0L);

    assertThat(date).isEqualTo(utcStartOfTime);
  }

  @Test public void decodeDateFromMillisDurationCorrectly() {
    LocalDateTime start = LocalDateTime.of(1970, 1, 1, 1, 0, 0, 0);
    LocalDateTime end = LocalDateTime.of(2016, 1, 1, 1, 0, 0, 0);

    long duration = start.until(end, MILLIS);

    LocalDateTime date = adapter.decode(duration);
    assertThat(date).isEqualTo(end);
  }
}

@@ -604,33 +604,33 @@
 .of(1970, 1, 1, 
-1
+0
 , 0, 0, 0);%0A%0A   
@@ -822,33 +822,33 @@
 .of(1970, 1, 1, 
-1
+0
 , 0, 0, 0);%0A    
@@ -1160,33 +1160,33 @@
 .of(1970, 1, 1, 
-1
+0
 , 0, 0, 0);%0A    
@@ -1389,33 +1389,33 @@
 .of(1970, 1, 1, 
-1
+0
 , 0, 0, 0);%0A    

Fix LocalDateTime in tests