Fix DST issue in serializer tests
This commit is contained in:
@@ -1,70 +0,0 @@
|
||||
package org.springframework.batch.core.repository.dao;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author trisberg
|
||||
*/
|
||||
public class ComplexObject {
|
||||
private String name;
|
||||
private BigDecimal number;
|
||||
private ComplexObject obj;
|
||||
private Map map;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public BigDecimal getNumber() {
|
||||
return number;
|
||||
}
|
||||
|
||||
public void setNumber(BigDecimal number) {
|
||||
this.number = number;
|
||||
}
|
||||
|
||||
public ComplexObject getObj() {
|
||||
return obj;
|
||||
}
|
||||
|
||||
public void setObj(ComplexObject obj) {
|
||||
this.obj = obj;
|
||||
}
|
||||
|
||||
public Map getMap() {
|
||||
return map;
|
||||
}
|
||||
|
||||
public void setMap(Map map) {
|
||||
this.map = map;
|
||||
}
|
||||
|
||||
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
ComplexObject that = (ComplexObject) o;
|
||||
|
||||
if (map != null ? !map.equals(that.map) : that.map != null) return false;
|
||||
if (name != null ? !name.equals(that.name) : that.name != null) return false;
|
||||
if (number != null ? !number.equals(that.number) : that.number != null) return false;
|
||||
if (obj != null ? !obj.equals(that.obj) : that.obj != null) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
int result;
|
||||
result = (name != null ? name.hashCode() : 0);
|
||||
result = 31 * result + (number != null ? number.hashCode() : 0);
|
||||
result = 31 * result + (obj != null ? obj.hashCode() : 0);
|
||||
result = 31 * result + (map != null ? map.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright 2006-2007 the original author or authors.
|
||||
*
|
||||
* 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 org.springframework.batch.core.repository.dao;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.junit.runners.Parameterized.Parameters;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
@RunWith(Parameterized.class)
|
||||
public class DateFormatTests {
|
||||
|
||||
private final SimpleDateFormat format;
|
||||
|
||||
private final String value;
|
||||
|
||||
private final int hour;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public DateFormatTests(String pattern, String value, int hour) {
|
||||
this.format = new SimpleDateFormat(pattern);
|
||||
this.value = value;
|
||||
this.hour = hour;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDateFormat() throws Exception {
|
||||
Date date = format.parse(value);
|
||||
System.err.println(format.toPattern() + " + " + value + " --> " + date);
|
||||
GregorianCalendar calendar = new GregorianCalendar();
|
||||
calendar.setTime(date);
|
||||
assertEquals(hour, calendar.get(Calendar.HOUR_OF_DAY));
|
||||
}
|
||||
|
||||
@Parameters
|
||||
public static List<Object[]> data() {
|
||||
List<Object[]> params = new ArrayList<Object[]>();
|
||||
params.add(new Object[] { "yyyy-MM-dd HH:mm:ss.S z", "1970-01-01 11:20:34.0 GMT", 12 });
|
||||
params.add(new Object[] { "yyyy-MM-dd HH:mm:ss.S z", "1971-02-01 11:20:34.0 GMT", 12 });
|
||||
// After 1972 you get the right answer
|
||||
params.add(new Object[] { "yyyy-MM-dd HH:mm:ss.S z", "1972-02-01 11:20:34.0 GMT", 11 });
|
||||
params.add(new Object[] { "yyyy-MM-dd HH:mm:ss.S z", "1976-02-01 11:20:34.0 GMT", 11 });
|
||||
params.add(new Object[] { "yyyy-MM-dd HH:mm:ss.S z", "1982-02-01 11:20:34.0 GMT", 11 });
|
||||
params.add(new Object[] { "yyyy-MM-dd HH:mm:ss.S z", "2008-02-01 11:20:34.0 GMT", 11 });
|
||||
return params;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,13 +2,13 @@ package org.springframework.batch.core.repository.dao;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.Before;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
import java.util.Date;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author Thomas Risberg
|
||||
@@ -22,13 +22,14 @@ public class XStreamExecutionContextStringSerializerTests {
|
||||
serializer = new XStreamExecutionContextStringSerializer();
|
||||
((XStreamExecutionContextStringSerializer)serializer).afterPropertiesSet();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSerializeAMap() {
|
||||
Map<String, Object> m1 = new HashMap<String, Object>();
|
||||
m1.put("object1", Long.valueOf(12345L));
|
||||
m1.put("object2", "OBJECT TWO");
|
||||
m1.put("object3", new Date(1234567L));
|
||||
// Use a date after 1971 (otherwise daylight saving screws up)...
|
||||
m1.put("object3", new Date(123456790123L));
|
||||
m1.put("object4", new Double(1234567.1234D));
|
||||
|
||||
String s = serializer.serialize(m1);
|
||||
@@ -68,4 +69,66 @@ public class XStreamExecutionContextStringSerializerTests {
|
||||
}
|
||||
}
|
||||
|
||||
private static class ComplexObject {
|
||||
private String name;
|
||||
private BigDecimal number;
|
||||
private ComplexObject obj;
|
||||
private Map<String,Object> map;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public BigDecimal getNumber() {
|
||||
return number;
|
||||
}
|
||||
|
||||
public void setNumber(BigDecimal number) {
|
||||
this.number = number;
|
||||
}
|
||||
|
||||
public ComplexObject getObj() {
|
||||
return obj;
|
||||
}
|
||||
|
||||
public void setObj(ComplexObject obj) {
|
||||
this.obj = obj;
|
||||
}
|
||||
|
||||
public Map<String,Object> getMap() {
|
||||
return map;
|
||||
}
|
||||
|
||||
public void setMap(Map<String,Object> map) {
|
||||
this.map = map;
|
||||
}
|
||||
|
||||
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
ComplexObject that = (ComplexObject) o;
|
||||
|
||||
if (map != null ? !map.equals(that.map) : that.map != null) return false;
|
||||
if (name != null ? !name.equals(that.name) : that.name != null) return false;
|
||||
if (number != null ? !number.equals(that.number) : that.number != null) return false;
|
||||
if (obj != null ? !obj.equals(that.obj) : that.obj != null) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
int result;
|
||||
result = (name != null ? name.hashCode() : 0);
|
||||
result = 31 * result + (number != null ? number.hashCode() : 0);
|
||||
result = 31 * result + (obj != null ? obj.hashCode() : 0);
|
||||
result = 31 * result + (map != null ? map.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user