mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 01:54:22 +00:00
[DS-3217] modified DCDateTest and InstallItemTest to use Calendar instead of Date for getting a date value for testing, explicitly set the timezone of the new calendar object to UTC, thanks to LuizClaudioSantos and Helix84 for the hints
This commit is contained in:
@@ -398,7 +398,8 @@ public class DCDateTest
|
||||
public void testGetCurrent()
|
||||
{
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTimeInMillis(System.currentTimeMillis());
|
||||
calendar.setTimeInMillis(System.currentTimeMillis());
|
||||
calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
assertTrue("testGetCurrent 0", DateUtils.isSameDay(DCDate.getCurrent().toDate(), calendar.getTime()));
|
||||
}
|
||||
|
||||
|
@@ -25,12 +25,14 @@ import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.List;
|
||||
import java.util.Calendar;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
|
||||
/**
|
||||
* Unit Tests for class InstallItem
|
||||
* @author pvillega
|
||||
@@ -246,10 +248,13 @@ public class InstallItemTest extends AbstractUnitTest
|
||||
itemService.addMetadata(context, is.getItem(), "dc", "date", "issued", Item.ANY, "2011-01-01");
|
||||
|
||||
//get current date
|
||||
DCDate now = DCDate.getCurrent();
|
||||
String dayAndTime = now.toString();
|
||||
//parse out just the date, remove the time (format: yyyy-mm-ddT00:00:00Z)
|
||||
String date = dayAndTime.substring(0, dayAndTime.indexOf("T"));
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTimeInMillis(System.currentTimeMillis());
|
||||
calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||
|
||||
String date = sdf.format(calendar.getTime());
|
||||
|
||||
Item result = installItemService.installItem(context, is, handle);
|
||||
context.restoreAuthSystemState();
|
||||
@@ -296,10 +301,11 @@ public class InstallItemTest extends AbstractUnitTest
|
||||
itemService.addMetadata(context, is.getItem(), "dc", "date", "issued", Item.ANY, "2011-01-01");
|
||||
|
||||
//get current date
|
||||
DCDate now = DCDate.getCurrent();
|
||||
String dayAndTime = now.toString();
|
||||
//parse out just the date, remove the time (format: yyyy-mm-ddT00:00:00Z)
|
||||
String date = dayAndTime.substring(0, dayAndTime.indexOf("T"));
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTimeInMillis(System.currentTimeMillis());
|
||||
calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||
String date = sdf.format(calendar.getTime());
|
||||
|
||||
Item result = installItemService.restoreItem(context, is, handle);
|
||||
context.restoreAuthSystemState();
|
||||
|
Reference in New Issue
Block a user