2222import java .nio .file .Path ;
2323import java .nio .file .Paths ;
2424import java .sql .SQLException ;
25- import java .text .DateFormat ;
26- import java .text .SimpleDateFormat ;
2725import java .time .Instant ;
26+ import java .time .LocalDate ;
27+ import java .time .ZoneId ;
2828import java .time .temporal .ChronoUnit ;
29- import java .util .Date ;
3029import java .util .List ;
3130
3231import org .dspace .authorize .ResourcePolicy ;
@@ -73,14 +72,14 @@ public void setup() throws SQLException {
7372
7473 @ Test
7574 public void getPolicyForAdmin () throws Exception {
76- final DateFormat dateFormat = new SimpleDateFormat ("yyyy-MM-dd" );
77-
78- // Setup group
75+ // Set up the Group
7976 final Group adminGroup = mock (Group .class );
8077 when (adminGroup .getName ()).thenReturn (Group .ADMIN );
8178
82- // set up an admin ResourcePolicy for the Community
83- final Date groupDate = Date .from (Instant .now ().minus (1 , ChronoUnit .DAYS ));
79+ // Set up an admin ResourcePolicy for the Community
80+ final LocalDate groupDate = Instant .now ().minus (1 , ChronoUnit .DAYS )
81+ .atZone (ZoneId .systemDefault ())
82+ .toLocalDate ();
8483 final ResourcePolicy adminGroupPolicy = initReloadable (ResourcePolicy .class );
8584 adminGroupPolicy .setGroup (adminGroup );
8685 adminGroupPolicy .setRpType (TYPE_CUSTOM );
@@ -102,7 +101,7 @@ public void getPolicyForAdmin() throws Exception {
102101 assertThat (child .getAction ()).isEqualTo ("READ" );
103102 assertThat (child .getType ()).isEqualTo (TYPE_CUSTOM );
104103 assertThat (child .getGroup ()).isEqualTo (Group .ADMIN );
105- assertThat (child .getStartDate ()).isEqualTo (dateFormat . format ( groupDate ));
104+ assertThat (child .getStartDate ()).isEqualTo (groupDate . toString ( ));
106105
107106 assertThat (child .getName ()).isNull ();
108107 assertThat (child .getEndDate ()).isNull ();
@@ -114,14 +113,14 @@ public void getPolicyForAdmin() throws Exception {
114113
115114 @ Test
116115 public void getPolicyForAnonymous () throws Exception {
117- final DateFormat dateFormat = new SimpleDateFormat ("yyyy-MM-dd" );
118-
119- // setup the Group
116+ // Set up the Group
120117 final Group anonGroup = mock (Group .class );
121118 when (anonGroup .getName ()).thenReturn (Group .ANONYMOUS );
122119
123120 // set up the ResourcePolicy
124- final Date groupDate = Date .from (Instant .now ().minus (1 , ChronoUnit .DAYS ));
121+ final LocalDate groupDate = Instant .now ().minus (1 , ChronoUnit .DAYS )
122+ .atZone (ZoneId .systemDefault ())
123+ .toLocalDate ();
125124 final ResourcePolicy anonGroupPolicy = initReloadable (ResourcePolicy .class );
126125 anonGroupPolicy .setGroup (anonGroup );
127126 anonGroupPolicy .setRpType (TYPE_CUSTOM );
@@ -142,7 +141,7 @@ public void getPolicyForAnonymous() throws Exception {
142141 assertThat (child .getAction ()).isEqualTo ("READ" );
143142 assertThat (child .getType ()).isEqualTo (TYPE_CUSTOM );
144143 assertThat (child .getGroup ()).isEqualTo (Group .ANONYMOUS );
145- assertThat (child .getEndDate ()).isEqualTo (dateFormat . format ( groupDate ));
144+ assertThat (child .getEndDate ()).isEqualTo (groupDate . toString ( ));
146145
147146 assertThat (child .getName ()).isNull ();
148147 assertThat (child .getEperson ()).isNull ();
@@ -154,15 +153,15 @@ public void getPolicyForAnonymous() throws Exception {
154153
155154 @ Test
156155 public void getPolicyForEPerson () throws Exception {
157- final DateFormat dateFormat = new SimpleDateFormat ("yyyy-MM-dd" );
158-
159- // setup the EPerson
156+ // Set up the EPerson
160157 final String epersonEmail = "bagit-policy-util-test" ;
161158 final EPerson ePerson = mock (EPerson .class );
162159 when (ePerson .getEmail ()).thenReturn (epersonEmail );
163160
164161 // Create the ePerson policy
165- final Date ePersonDate = Date .from (Instant .now ().plus (1 , ChronoUnit .DAYS ));
162+ final LocalDate ePersonDate = Instant .now ().plus (1 , ChronoUnit .DAYS )
163+ .atZone (ZoneId .systemDefault ())
164+ .toLocalDate ();
166165 final ResourcePolicy ePersonPolicy = initReloadable (ResourcePolicy .class );
167166 ePersonPolicy .setEPerson (ePerson );
168167 ePersonPolicy .setRpType (TYPE_CUSTOM );
@@ -183,7 +182,7 @@ public void getPolicyForEPerson() throws Exception {
183182 assertThat (child .getAction ()).isEqualTo ("READ" );
184183 assertThat (child .getType ()).isEqualTo (TYPE_CUSTOM );
185184 assertThat (child .getEperson ()).isEqualTo (epersonEmail );
186- assertThat (child .getStartDate ()).isEqualTo (dateFormat . format ( ePersonDate ));
185+ assertThat (child .getStartDate ()).isEqualTo (ePersonDate . toString ( ));
187186
188187 assertThat (child .getName ()).isNull ();
189188 assertThat (child .getGroup ()).isNull ();
@@ -195,7 +194,7 @@ public void getPolicyForEPerson() throws Exception {
195194
196195 @ Test
197196 public void registerPolicies () throws Exception {
198- // Read an aip in order to load a policy.xml
197+ // Read an AIP in order to load a policy.xml
199198 final URL resources = BagItPolicyUtilTest .class .getClassLoader ().getResource ("" );
200199 assertThat (resources ).isNotNull ();
201200
0 commit comments