/*
 * Copyright 2014 michael-simons.eu.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package ac.simons.biking2.tracker;

import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.math.BigDecimal;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Calendar;
import java.util.Date;
import org.junit.Assert;
import org.junit.Test;

/**
 * @author Michael J. Simons, 2014-05-20
 */
public class NewLocationCmdTest {
    private final ObjectMapper objectMapper = new ObjectMapper();
    
    /**
     * The command is primarly used through json mapping, so i choose
     * the same approach here.
     */
    @Test
    public void beanShouldWorkAsExpected() throws IOException {	
	NewLocationCmd newLocationCmd = objectMapper.readValue("{\"lon\":\"5\", \"lat\":\"50\"}", NewLocationCmd.class);
	Assert.assertEquals(BigDecimal.valueOf(5l), newLocationCmd.getLongitude());
	Assert.assertEquals(BigDecimal.valueOf(50l), newLocationCmd.getLatitude());
	Assert.assertNull(newLocationCmd.getCreatedAt());
	
	newLocationCmd = objectMapper.readValue("{\"lon\":\"5\", \"lat\":\"50\", \"tst\": \"1400577777\"}", NewLocationCmd.class);
	Calendar hlp = Calendar.getInstance();
	hlp.setTime(Date.from(ZonedDateTime.of(2014, 5, 20, 11, 22, 57, 0, ZoneId.systemDefault()).toInstant()));
	Assert.assertEquals(hlp, newLocationCmd.getCreatedAt());
	
	newLocationCmd = objectMapper.readValue("{\"lon\":\"5\", \"lat\":\"50\", \"tstMillis\": \"1400578694000\"}", NewLocationCmd.class);
	hlp = Calendar.getInstance();
	hlp.setTime(Date.from(ZonedDateTime.of(2014, 5, 20, 11, 38, 14, 0, ZoneId.systemDefault()).toInstant()));
	Assert.assertEquals(hlp, newLocationCmd.getCreatedAt());	
	
	newLocationCmd = objectMapper.readValue("{\"lon\":\"5\", \"lat\":\"50\", \"tst\": \"1400577777\", \"tstMillis\": \"1400578694000\"}", NewLocationCmd.class);
	hlp = Calendar.getInstance();
	hlp.setTime(Date.from(ZonedDateTime.of(2014, 5, 20, 11, 22, 57, 0, ZoneId.systemDefault()).toInstant()));
	Assert.assertEquals(hlp, newLocationCmd.getCreatedAt());
    }   
}

@@ -17,27 +17,32 @@
 2014
- m
+-2016 M
 ichael
--s
+ J. S
 imons.
-eu.
 %0A *%0A
@@ -601,17 +601,16 @@
 se.%0A */%0A
-%0A
 package 
@@ -641,60 +641,8 @@
 r;%0A%0A
-import com.fasterxml.jackson.databind.ObjectMapper;%0A
 impo
@@ -849,16 +849,234 @@
 t.Test;%0A
+import org.junit.runner.RunWith;%0Aimport org.springframework.boot.test.autoconfigure.json.JsonTest;%0Aimport org.springframework.boot.test.json.JacksonTester;%0Aimport org.springframework.test.context.junit4.SpringRunner;%0A%0A
 %0A/**%0A * 
@@ -1117,16 +1117,55 @@
 -20%0A */%0A
+@RunWith(SpringRunner.class)%0A@JsonTest%0A
 public c
@@ -1190,16 +1190,21 @@
 dTest %7B%0A
+    %0A
     priv
@@ -1211,60 +1211,42 @@
 ate 
-final ObjectMapper objectMapper = new ObjectMapper()
+JacksonTester%3CNewLocationCmd%3E json
 ;%0A  
@@ -1473,38 +1473,32 @@
 onCmd = 
-objectMapper.readValue
+json.parseObject
 (%22%7B%5C%22lon
@@ -1523,38 +1523,16 @@
 %5C%2250%5C%22%7D%22
-, NewLocationCmd.class
 );%0A%09Asse
@@ -1751,38 +1751,32 @@
 onCmd = 
-objectMapper.readValue
+json.parseObject
 (%22%7B%5C%22lon
@@ -1826,38 +1826,16 @@
 7777%5C%22%7D%22
-, NewLocationCmd.class
 );%0A%09Cale
@@ -2054,38 +2054,32 @@
 onCmd = 
-objectMapper.readValue
+json.parseObject
 (%22%7B%5C%22lon
@@ -2138,38 +2138,16 @@
 4000%5C%22%7D%22
-, NewLocationCmd.class
 );%0A%09hlp 
@@ -2362,30 +2362,24 @@
 d = 
-objectMapper.readValue
+json.parseObject
 (%22%7B%5C
@@ -2471,30 +2471,8 @@
 %5C%22%7D%22
-, NewLocationCmd.class
 );%0A%09

Use new @JsonTest annotation