Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix tests that fail if you aren't in Pacific time zone.

These tests were comparing a java.util.Date.toString() (which falls in the default system time zone) to a hard-coded Pacific time zone string. Changed the hardcoded string to UTC and added a date formatter to spit out the comparison value in UTC as well.
  • Loading branch information...
commit 61c1fc08e44692123ef97b35b4047dc4321ef88f 1 parent 6397bce
@precipice precipice authored
View
9 src/test/java/com/wesabe/grendel/resources/tests/DocumentResourceTest.java
@@ -6,7 +6,10 @@
import static org.mockito.Mockito.*;
import java.security.SecureRandom;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
import java.util.Date;
+import java.util.TimeZone;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.EntityTag;
@@ -134,10 +137,14 @@ public void itChecksPreconditions() throws Exception {
public void itReturnsTheDecryptedDocument() throws Exception {
final Response response = resource.show(request, credentials, "bob", "document1.txt");
+ SimpleDateFormat formatter = (SimpleDateFormat) DateFormat.getDateTimeInstance();
+ formatter.setTimeZone(TimeZone.getTimeZone("UTC"));
+ formatter.applyPattern("EEE MMM dd HH:mm:ss z yyyy");
+
assertThat(response.getStatus()).isEqualTo(Status.OK.getStatusCode());
assertThat(response.getMetadata().getFirst("Content-Type")).isEqualTo(MediaType.valueOf("text/plain"));
assertThat(response.getMetadata().getFirst("Cache-Control").toString()).isEqualTo("private, no-cache, no-store, no-transform");
- assertThat(response.getMetadata().getFirst("Last-Modified").toString()).isEqualTo("Tue Dec 29 00:42:32 PST 2009");
+ assertThat(formatter.format(response.getMetadata().getFirst("Last-Modified"))).isEqualTo("Tue Dec 29 08:42:32 UTC 2009");
assertThat((byte[]) response.getEntity()).isEqualTo("yay for everyone".getBytes());
}
View
11 src/test/java/com/wesabe/grendel/resources/tests/LinkedDocumentResourceTest.java
@@ -4,6 +4,11 @@
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.TimeZone;
+
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
@@ -113,10 +118,14 @@ public void itThrowsA404IfTheDocumentIsNotLinkedToTheUser() throws Exception {
public void itReturnsTheDecryptedDocument() throws Exception {
final Response r = resource.show(credentials, "bob", "frank", "document1.txt");
+ SimpleDateFormat formatter = (SimpleDateFormat) DateFormat.getDateTimeInstance();
+ formatter.setTimeZone(TimeZone.getTimeZone("UTC"));
+ formatter.applyPattern("EEE MMM dd HH:mm:ss z yyyy");
+
assertThat(r.getStatus()).isEqualTo(Status.OK.getStatusCode());
assertThat(r.getMetadata().getFirst("Content-Type")).isEqualTo(MediaType.valueOf("text/plain"));
assertThat(r.getMetadata().getFirst("Cache-Control").toString()).isEqualTo("private, no-cache, no-store, no-transform");
- assertThat(r.getMetadata().getFirst("Last-Modified").toString()).isEqualTo("Tue Dec 29 00:42:32 PST 2009");
+ assertThat(formatter.format(r.getMetadata().getFirst("Last-Modified"))).isEqualTo("Tue Dec 29 08:42:32 UTC 2009");
assertThat((byte[]) r.getEntity()).isEqualTo("yay for everyone".getBytes());
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.