Commit 847d0f3f authored by Kjetil Thuen's avatar Kjetil Thuen

Avoid using Calendar to prevent time zone issues.

Fixes #2093 (I hope)
parent 1b461967
......@@ -6,7 +6,6 @@ import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.util.Calendar;
import java.util.Date;
import org.junit.Before;
......@@ -27,7 +26,7 @@ public class ETagTest {
ETag tag = ETag.createETag(new ETagGenerator(data, "0.1.2"));
assertEquals("Tags don't match", expectedTagValue, tag.getValue());
}
@Test
public void testEmptyInput() {
ETagData data = new ETagData();
......@@ -35,7 +34,7 @@ public class ETagTest {
ETag tag = ETag.createETag(new ETagGenerator(data, "0.1.2"));
assertFalse(tag.getValue().isEmpty());
}
@Test
public void testNullInput() {
ETagData data = new ETagData();
......@@ -43,7 +42,7 @@ public class ETagTest {
ETag tag = ETag.createETag(new ETagGenerator(data, "0.1.2"));
assertFalse(tag.equals(null));
}
@Test
public void compareETags() throws Exception {
ETagData data = new ETagData();
......@@ -51,22 +50,22 @@ public class ETagTest {
ETag first = ETag.createETag(new ETagGenerator(data, "0.1.2"));
ETag second = ETag.createETag(new ETagGenerator(data, "0.1.2"));
assertTrue(first.equals(second));
Variable variable = mock(Variable.class);
when(variable.getId()).thenReturn("variable1234");
when(variable.getTimeStamp()).thenReturn(createDate());
ETagData variableData = new ETagData();
variableData.add(url).add(variable);
ETag variableEtag = ETag.createETag(new ETagGenerator(data, "0.1.3"));
assertFalse(variableEtag.equals(first));
}
@Test
public void testETagInvalidatesWhenVersionIsUpdated() throws Exception {
ETagData data = new ETagData();
data.add(url).add(study);
ETag original = ETag.createETag(new ETagGenerator(data, "0.1.2"));
ETag afterVersionBump = ETag.createETag(new ETagGenerator(data, "0.1.3"));
assertFalse("ETags should not be equal", original.equals(afterVersionBump));
......@@ -75,15 +74,12 @@ public class ETagTest {
@Before
public void setUp() throws Exception {
study = mock(Study.class);
when(study.getId()).thenReturn("ABC1234");
when(study.getTimeStamp()).thenReturn(createDate());
}
private Date createDate() throws Exception {
Calendar calendar = Calendar.getInstance();
calendar.set(2013, 9, 10, 13, 14, 0);
calendar.set(Calendar.MILLISECOND, 0);
return calendar.getTime();
return new Date(1381403640000L); //August 10th, 2013 13:14:00 CEST
}
}
......@@ -4,7 +4,6 @@ import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.util.Calendar;
import java.util.Date;
import javax.servlet.FilterChain;
......@@ -37,9 +36,6 @@ public class EntityTagFilterTest {
}
Date createDate() throws Exception {
Calendar calendar = Calendar.getInstance();
calendar.set(2013, 9, 10, 13, 14, 0);
calendar.set(Calendar.MILLISECOND, 0);
return calendar.getTime();
return new Date(1381403640000L); //August 10th, 2013 13:14:00 CEST
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment