Permalink
Browse files

Fix bug related to PAST and FUTURE hardcoded values and Views.

  • Loading branch information...
1 parent 536d7f2 commit 221adf8780fd4928135fc7fda63ee6adbc6f651b @andershessellund andershessellund committed May 31, 2011
@@ -23,6 +23,7 @@
package com.trifork.stamdata.util;
+import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import java.util.Calendar;
@@ -78,4 +79,16 @@ public void testGetCalendarFromMysqlDate() throws Exception {
assertEquals(cal.getTime().getTime(), DateUtils.toCalendar(date).getTime().getTime());
}
+ @Test
+ public void testNullIfPast() {
+ java.util.Date date = DateUtils.PAST.getTime();
+ assertNull(DateUtils.nullIfPast(date));
+ assertNotNull(DateUtils.nullIfPast(new java.util.Date()));
+ }
+ @Test
+ public void testNullIfFuture() {
+ java.util.Date date = DateUtils.FUTURE.getTime();
+ assertNull(DateUtils.nullIfFuture(date));
+ assertNotNull(DateUtils.nullIfFuture(new java.util.Date()));
+ }
}
@@ -1,5 +1,6 @@
package com.trifork.stamdata.lookup.dao;
+import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -13,6 +14,7 @@
import org.junit.Test;
import com.trifork.stamdata.replication.DatabaseHelper;
+import com.trifork.stamdata.util.DateUtils;
import com.trifork.stamdata.views.cpr.Foedselsregistreringsoplysninger;
import com.trifork.stamdata.views.cpr.Folkekirkeoplysninger;
import com.trifork.stamdata.views.cpr.Person;
@@ -103,6 +105,20 @@ public void getsCurrentPersonRecordIfRecordsInTheFuture() {
assertEquals(at(2010, Calendar.FEBRUARY, 10), person.getValidFrom());
}
+ @Test
+ public void pastAndFutureNotModified() {
+ Folkekirkeoplysninger fo = folkekirkeoplysninger("M");
+ fo.setValidFrom(DateUtils.PAST.getTime());
+ fo.setValidTo(DateUtils.FUTURE.getTime());
+ session.save(fo);
+ session.flush();
+ session.clear();
+ Folkekirkeoplysninger retrieved = (Folkekirkeoplysninger) session.get(Folkekirkeoplysninger.class, fo.getRecordID());
+ assertNull(retrieved.getValidFrom());
+
+ assertNull(retrieved.getValidTo());
+ }
+
private Person person(Date validFrom) {
Person result = new Person();
result.setCpr("1020304050");
@@ -114,13 +114,13 @@ public static String toMySQLdate(Calendar date) {
}
public static java.util.Date nullIfPast(java.util.Date date) {
- if(PAST.equals(date)) {
+ if(PAST.getTime().equals(date)) {
return null;
}
return date;
}
public static java.util.Date nullIfFuture(java.util.Date date) {
- if(FUTURE.equals(date)) {
+ if(FUTURE.getTime().equals(date)) {
return null;
}
return date;
@@ -79,7 +79,7 @@ public void setValidFrom(Date validFrom) {
@XmlElement(required = false)
public Date getValidTo() {
- return DateUtils.nullIfPast(validTo);
+ return DateUtils.nullIfFuture(validTo);
}
public void setValidTo(Date validTo) {

0 comments on commit 221adf8

Please sign in to comment.