Skip to content

Commit

Permalink
add preliminary test scaffolding for #204
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Nov 18, 2016
1 parent b1026af commit 81c694b
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,7 @@ protected java.util.Date _parseDate(JsonParser p, DeserializationContext ctxt)
}
return parsed;
}
return (java.util.Date) ctxt.handleUnexpectedToken(_valueClass, p);
return (java.util.Date) ctxt.handleUnexpectedToken(_valueClass, p);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.fasterxml.jackson.databind.deser.jdk;

import java.util.Calendar;
import java.util.TimeZone;

import com.fasterxml.jackson.databind.*;

public class DateAdjustment204Test extends BaseMapTest
{
/*
/**********************************************************
/* Unit tests
/**********************************************************
*/

private final ObjectMapper MAPPER = new ObjectMapper();

// for [databind#204]
public void testContextTimezone() throws Exception
{
String inputStr = "1997-07-16T19:20:30.45+0100";

// this is enabled by default:
assertTrue(MAPPER.isEnabled(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE));
final ObjectReader r = MAPPER
.readerFor(Calendar.class)
.with(TimeZone.getTimeZone("PST"));

// by default use contextual timezone:
Calendar cal = r.readValue(quote(inputStr));
TimeZone tz = cal.getTimeZone();
assertEquals("PST", tz.getID());

assertEquals(1997, cal.get(Calendar.YEAR));
assertEquals(Calendar.JULY, cal.get(Calendar.MONTH));
assertEquals(16, cal.get(Calendar.DAY_OF_MONTH));

// Translated from original into PST differs:
assertEquals(11, cal.get(Calendar.HOUR_OF_DAY));
assertEquals(20, cal.get(Calendar.MINUTE));
assertEquals(30, cal.get(Calendar.SECOND));

// but if disabled, should use what's been sent in:
cal = r.without(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE)
.readValue(quote(inputStr));


// !!! TODO: would not yet pass
/*
System.err.println("CAL/2 == "+cal);
System.err.println("tz == "+cal.getTimeZone());
*/

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,6 @@ public void testDatesWithEmptyStrings() throws Exception
assertNull(MAPPER.readValue(quote(""), java.sql.Date.class));
}

// for [JACKSON-334]
public void test8601DateTimeNoMilliSecs() throws Exception
{
// ok, Zebra, no milliseconds
Expand Down

0 comments on commit 81c694b

Please sign in to comment.