package org.araymond.joal.web.config;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.araymond.joal.core.torrent.torrent.InfoHashTest;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.cglib.core.Local;
import org.springframework.test.context.junit4.SpringRunner;

import javax.inject.Inject;
import java.time.*;

import static org.assertj.core.api.Assertions.assertThat;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = {
        JacksonConfig.class,
               org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration.class
        },
        properties = {
                "spring.main.web-environment=true"
        }
)
public class JacksonConfigWebAppTest {

    @Inject
    private ObjectMapper mapper;

    @Test
    public void shouldSerializeDateAsYYYY_MM_DD() throws JsonProcessingException {
        final String dateValue = this.mapper.writeValueAsString(LocalDate.of(2010, 12, 30));

        assertThat(dateValue).isEqualTo("\"2010-12-30\"");
    }

    @Test
    public void shouldSerializeDateTimeWithTimeZone() throws JsonProcessingException {
        // Because of the serializer that transforms LocalDateTime into ZonedDateTime
        final LocalDateTime dateTime = LocalDateTime.of(2010, 12, 30, 23, 59);
        final String dateValue = this.mapper.writeValueAsString(dateTime);

        assertThat(dateValue).isEqualTo("\"2010-12-30T23:59:00+01:00\"");
    }

    @Test
    public void shouldSerializeInfoHash() throws JsonProcessingException {
        final String infohashValue = this.mapper.writeValueAsString(InfoHashTest.createOne("abcdefgh"));

        assertThat(infohashValue).isEqualTo("\"abcdefgh\"");
    }

}

@@ -324,53 +324,8 @@
 st;%0A
-import org.springframework.cglib.core.Local;%0A
 impo
@@ -431,9 +431,101 @@
 ime.
-*
+LocalDate;%0Aimport java.time.LocalDateTime;%0Aimport java.time.ZoneId;%0Aimport java.util.TimeZone
 ;%0A%0Ai
@@ -647,16 +647,20 @@
         
+    
 JacksonC
@@ -672,19 +672,16 @@
 .class,%0A
-   
         
@@ -1310,83 +1310,351 @@
  // 
-Because of the serializer that transforms LocalDateTime into ZonedDateTime%0A
+set default timezone for test scope%0A        final TimeZone defaultTimeZoneAtBeginningOfTest = TimeZone.getDefault();%0A        final String dateValue;%0A        try %7B%0A            // Because of the serializer that transforms LocalDateTime into ZonedDateTime%0A            TimeZone.setDefault(TimeZone.getTimeZone(ZoneId.of(%22Australia/Sydney%22)));%0A    
     
@@ -1732,36 +1732,27 @@
 9);%0A        
-final String
+   
  dateValue =
@@ -1791,24 +1791,215 @@
 dateTime);%0A%0A
+        %7D catch (final Throwable throwable) %7B%0A            // reset default timezone%0A            TimeZone.setDefault(defaultTimeZoneAtBeginningOfTest);%0A            throw throwable;%0A        %7D%0A%0A
         asse
@@ -2049,17 +2049,17 @@
 3:59:00+
-0
+1
 1:00%5C%22%22)

Fix a test in non Europe/Paris time-zoned environment