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; ...@@ -6,7 +6,6 @@ import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import java.util.Calendar;
import java.util.Date; import java.util.Date;
import org.junit.Before; import org.junit.Before;
...@@ -27,7 +26,7 @@ public class ETagTest { ...@@ -27,7 +26,7 @@ public class ETagTest {
ETag tag = ETag.createETag(new ETagGenerator(data, "0.1.2")); ETag tag = ETag.createETag(new ETagGenerator(data, "0.1.2"));
assertEquals("Tags don't match", expectedTagValue, tag.getValue()); assertEquals("Tags don't match", expectedTagValue, tag.getValue());
} }
@Test @Test
public void testEmptyInput() { public void testEmptyInput() {
ETagData data = new ETagData(); ETagData data = new ETagData();
...@@ -35,7 +34,7 @@ public class ETagTest { ...@@ -35,7 +34,7 @@ public class ETagTest {
ETag tag = ETag.createETag(new ETagGenerator(data, "0.1.2")); ETag tag = ETag.createETag(new ETagGenerator(data, "0.1.2"));
assertFalse(tag.getValue().isEmpty()); assertFalse(tag.getValue().isEmpty());
} }
@Test @Test
public void testNullInput() { public void testNullInput() {
ETagData data = new ETagData(); ETagData data = new ETagData();
...@@ -43,7 +42,7 @@ public class ETagTest { ...@@ -43,7 +42,7 @@ public class ETagTest {
ETag tag = ETag.createETag(new ETagGenerator(data, "0.1.2")); ETag tag = ETag.createETag(new ETagGenerator(data, "0.1.2"));
assertFalse(tag.equals(null)); assertFalse(tag.equals(null));
} }
@Test @Test
public void compareETags() throws Exception { public void compareETags() throws Exception {
ETagData data = new ETagData(); ETagData data = new ETagData();
...@@ -51,22 +50,22 @@ public class ETagTest { ...@@ -51,22 +50,22 @@ public class ETagTest {
ETag first = ETag.createETag(new ETagGenerator(data, "0.1.2")); ETag first = ETag.createETag(new ETagGenerator(data, "0.1.2"));
ETag second = ETag.createETag(new ETagGenerator(data, "0.1.2")); ETag second = ETag.createETag(new ETagGenerator(data, "0.1.2"));
assertTrue(first.equals(second)); assertTrue(first.equals(second));
Variable variable = mock(Variable.class); Variable variable = mock(Variable.class);
when(variable.getId()).thenReturn("variable1234"); when(variable.getId()).thenReturn("variable1234");
when(variable.getTimeStamp()).thenReturn(createDate()); when(variable.getTimeStamp()).thenReturn(createDate());
ETagData variableData = new ETagData(); ETagData variableData = new ETagData();
variableData.add(url).add(variable); variableData.add(url).add(variable);
ETag variableEtag = ETag.createETag(new ETagGenerator(data, "0.1.3")); ETag variableEtag = ETag.createETag(new ETagGenerator(data, "0.1.3"));
assertFalse(variableEtag.equals(first)); assertFalse(variableEtag.equals(first));
} }
@Test @Test
public void testETagInvalidatesWhenVersionIsUpdated() throws Exception { public void testETagInvalidatesWhenVersionIsUpdated() throws Exception {
ETagData data = new ETagData(); ETagData data = new ETagData();
data.add(url).add(study); data.add(url).add(study);
ETag original = ETag.createETag(new ETagGenerator(data, "0.1.2")); ETag original = ETag.createETag(new ETagGenerator(data, "0.1.2"));
ETag afterVersionBump = ETag.createETag(new ETagGenerator(data, "0.1.3")); ETag afterVersionBump = ETag.createETag(new ETagGenerator(data, "0.1.3"));
assertFalse("ETags should not be equal", original.equals(afterVersionBump)); assertFalse("ETags should not be equal", original.equals(afterVersionBump));
...@@ -75,15 +74,12 @@ public class ETagTest { ...@@ -75,15 +74,12 @@ public class ETagTest {
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
study = mock(Study.class); study = mock(Study.class);
when(study.getId()).thenReturn("ABC1234"); when(study.getId()).thenReturn("ABC1234");
when(study.getTimeStamp()).thenReturn(createDate()); when(study.getTimeStamp()).thenReturn(createDate());
} }
private Date createDate() throws Exception { private Date createDate() throws Exception {
Calendar calendar = Calendar.getInstance(); return new Date(1381403640000L); //August 10th, 2013 13:14:00 CEST
calendar.set(2013, 9, 10, 13, 14, 0);
calendar.set(Calendar.MILLISECOND, 0);
return calendar.getTime();
} }
} }
...@@ -4,7 +4,6 @@ import static org.mockito.Matchers.any; ...@@ -4,7 +4,6 @@ import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import java.util.Calendar;
import java.util.Date; import java.util.Date;
import javax.servlet.FilterChain; import javax.servlet.FilterChain;
...@@ -37,9 +36,6 @@ public class EntityTagFilterTest { ...@@ -37,9 +36,6 @@ public class EntityTagFilterTest {
} }
Date createDate() throws Exception { Date createDate() throws Exception {
Calendar calendar = Calendar.getInstance(); return new Date(1381403640000L); //August 10th, 2013 13:14:00 CEST
calendar.set(2013, 9, 10, 13, 14, 0);
calendar.set(Calendar.MILLISECOND, 0);
return calendar.getTime();
} }
} }
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