mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-17 02:31:14 +01:00
Use Instant in DTO
This commit is contained in:
@@ -12,6 +12,7 @@ import sonia.scm.user.User;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.time.Instant;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
@@ -84,4 +85,19 @@ public class User2UserDtoMapperTest {
|
||||
|
||||
assertEquals(UserResource.DUMMY_PASSWORT, userDto.getPassword());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldMapTimes() {
|
||||
User user = new User();
|
||||
user.setName("abc");
|
||||
Instant expectedCreationDate = Instant.ofEpochSecond(6666666);
|
||||
Instant expectedModificationDate = expectedCreationDate.plusSeconds(1);
|
||||
user.setCreationDate(expectedCreationDate.toEpochMilli());
|
||||
user.setLastModified(expectedModificationDate.toEpochMilli());
|
||||
|
||||
UserDto userDto = mapper.userToUserDto(user, uriInfo);
|
||||
|
||||
assertEquals(expectedCreationDate, userDto.getCreationDate());
|
||||
assertEquals(expectedModificationDate, userDto.getLastModified());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,8 @@ import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import sonia.scm.user.User;
|
||||
|
||||
import java.time.Instant;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.mockito.MockitoAnnotations.initMocks;
|
||||
@@ -36,6 +38,21 @@ public class UserDto2UserMapperTest {
|
||||
assertEquals("encrypted" , user.getPassword());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldMapTimes() {
|
||||
UserDto dto = new UserDto();
|
||||
dto.setName("abc");
|
||||
Instant expectedCreationDate = Instant.ofEpochMilli(66666660000L);
|
||||
Instant expectedModificationDate = null;
|
||||
dto.setCreationDate(expectedCreationDate);
|
||||
dto.setLastModified(expectedModificationDate);
|
||||
|
||||
User user = mapper.userDtoToUser(dto, "original password");
|
||||
|
||||
assertEquals((Long) expectedCreationDate.toEpochMilli(), user.getCreationDate());
|
||||
assertEquals(null, user.getLastModified());
|
||||
}
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
initMocks(this);
|
||||
|
||||
Reference in New Issue
Block a user