Skip to content
Snippets Groups Projects
Commit e7aa1e11 authored by OZGCloud's avatar OZGCloud
Browse files

OZG-5988 [test] use constant from test factory

parent 8229477f
No related branches found
No related tags found
No related merge requests found
...@@ -33,7 +33,8 @@ public class UserProfileTestFactory { ...@@ -33,7 +33,8 @@ public class UserProfileTestFactory {
private static final LoremIpsum LOREM_IPSUM = LoremIpsum.getInstance(); private static final LoremIpsum LOREM_IPSUM = LoremIpsum.getInstance();
public static final UserId ID = UserId.from(UUID.randomUUID().toString()); public static final String ID_STR = UUID.randomUUID().toString();
public static final UserId ID = UserId.from(ID_STR);
public static final String FIRST_NAME = LOREM_IPSUM.getFirstName(); public static final String FIRST_NAME = LOREM_IPSUM.getFirstName();
public static final String LAST_NAME = LOREM_IPSUM.getLastName(); public static final String LAST_NAME = LOREM_IPSUM.getLastName();
......
...@@ -61,8 +61,6 @@ import de.ozgcloud.document.DocumentTestFactory; ...@@ -61,8 +61,6 @@ import de.ozgcloud.document.DocumentTestFactory;
class BescheidServiceTest { class BescheidServiceTest {
private static final String USER_ID = "user-id";
@Spy @Spy
@InjectMocks @InjectMocks
private BescheidService service; private BescheidService service;
...@@ -135,8 +133,6 @@ class BescheidServiceTest { ...@@ -135,8 +133,6 @@ class BescheidServiceTest {
@Captor @Captor
private ArgumentCaptor<VorgangId> vorgangIdCaptor; private ArgumentCaptor<VorgangId> vorgangIdCaptor;
@Captor
private ArgumentCaptor<List<OzgCloudCommand>> subCommandsCaptor;
private final AttachedItem bescheidItem = AttachedItemTestFactory.createBescheid(); private final AttachedItem bescheidItem = AttachedItemTestFactory.createBescheid();
...@@ -144,7 +140,7 @@ class BescheidServiceTest { ...@@ -144,7 +140,7 @@ class BescheidServiceTest {
void init() { void init() {
doNothing().when(service).validateBescheidSendManually(any(), anyLong()); doNothing().when(service).validateBescheidSendManually(any(), anyLong());
doNothing().when(service).addSubCommands(any(), any()); doNothing().when(service).addSubCommands(any(), any());
doReturn(USER_ID).when(service).getUserId(); doReturn(UserProfileTestFactory.ID_STR).when(service).getUserId();
doReturn(List.of(subCommand)).when(service).buildSetBescheidSentSubCommands(any(), any(), any()); doReturn(List.of(subCommand)).when(service).buildSetBescheidSentSubCommands(any(), any(), any());
when(vorgangService.getById(any())).thenReturn(VORGANG); when(vorgangService.getById(any())).thenReturn(VORGANG);
} }
...@@ -175,7 +171,7 @@ class BescheidServiceTest { ...@@ -175,7 +171,7 @@ class BescheidServiceTest {
void shouldCallBuildSetBescheidSentSubCommands() { void shouldCallBuildSetBescheidSentSubCommands() {
sendBescheid(); sendBescheid();
verify(service).buildSetBescheidSentSubCommands(bescheidItem, VORGANG, USER_ID); verify(service).buildSetBescheidSentSubCommands(bescheidItem, VORGANG, UserProfileTestFactory.ID_STR);
} }
@Test @Test
...@@ -245,7 +241,7 @@ class BescheidServiceTest { ...@@ -245,7 +241,7 @@ class BescheidServiceTest {
void init() { void init() {
doNothing().when(service).validateBescheidSendPostfach(any(), anyLong()); doNothing().when(service).validateBescheidSendPostfach(any(), anyLong());
doNothing().when(service).addSubCommands(any(), any()); doNothing().when(service).addSubCommands(any(), any());
doReturn(USER_ID).when(service).getUserId(); doReturn(UserProfileTestFactory.ID_STR).when(service).getUserId();
var subCommands = new ArrayList<OzgCloudCommand>(); var subCommands = new ArrayList<OzgCloudCommand>();
subCommands.add(setBescheidSentSubCommand); subCommands.add(setBescheidSentSubCommand);
doReturn(subCommands).when(service).buildSetBescheidSentSubCommands(any(), any(), any()); doReturn(subCommands).when(service).buildSetBescheidSentSubCommands(any(), any(), any());
...@@ -279,14 +275,14 @@ class BescheidServiceTest { ...@@ -279,14 +275,14 @@ class BescheidServiceTest {
void shouldCallBuildSetBescheidSentSubCommands() { void shouldCallBuildSetBescheidSentSubCommands() {
sendBescheid(); sendBescheid();
verify(service).buildSetBescheidSentSubCommands(BESCHEID_ITEM, VORGANG, USER_ID); verify(service).buildSetBescheidSentSubCommands(BESCHEID_ITEM, VORGANG, UserProfileTestFactory.ID_STR);
} }
@Test @Test
void shouldCallBuildSendPostfachNachrichtCommand() { void shouldCallBuildSendPostfachNachrichtCommand() {
sendBescheid(); sendBescheid();
verify(service).buildSendPostfachNachrichtCommand(BESCHEID_ITEM, SERVICE_KONTO, USER_ID); verify(service).buildSendPostfachNachrichtCommand(BESCHEID_ITEM, SERVICE_KONTO, UserProfileTestFactory.ID_STR);
} }
@Test @Test
...@@ -589,7 +585,7 @@ class BescheidServiceTest { ...@@ -589,7 +585,7 @@ class BescheidServiceTest {
void shouldReturnUserId() { void shouldReturnUserId() {
var result = service.getUserId(); var result = service.getUserId();
assertThat(result).isEqualTo(UserProfileTestFactory.ID.toString()); assertThat(result).isEqualTo(UserProfileTestFactory.ID_STR);
} }
} }
...@@ -622,7 +618,7 @@ class BescheidServiceTest { ...@@ -622,7 +618,7 @@ class BescheidServiceTest {
void shouldCallBuildSetBescheidSentStatusCommand() { void shouldCallBuildSetBescheidSentStatusCommand() {
buildSetBescheidSentCommands(); buildSetBescheidSentCommands();
verify(service).buildSetBescheidSentStatusCommand(bescheidItem, USER_ID); verify(service).buildSetBescheidSentStatusCommand(bescheidItem, UserProfileTestFactory.ID_STR);
} }
@Test @Test
...@@ -633,7 +629,7 @@ class BescheidServiceTest { ...@@ -633,7 +629,7 @@ class BescheidServiceTest {
} }
private List<OzgCloudCommand> buildSetBescheidSentCommands() { private List<OzgCloudCommand> buildSetBescheidSentCommands() {
return service.buildSetBescheidSentSubCommands(bescheidItem, vorgang, USER_ID); return service.buildSetBescheidSentSubCommands(bescheidItem, vorgang, UserProfileTestFactory.ID_STR);
} }
} }
...@@ -746,7 +742,7 @@ class BescheidServiceTest { ...@@ -746,7 +742,7 @@ class BescheidServiceTest {
void shouldCallBuildBescheidSentStatusItem() { void shouldCallBuildBescheidSentStatusItem() {
buildSetBescheidSentStatusCommand(); buildSetBescheidSentStatusCommand();
verify(service).buildBescheidSentStatusItem(USER_ID); verify(service).buildBescheidSentStatusItem(UserProfileTestFactory.ID_STR);
} }
@Test @Test
...@@ -760,7 +756,7 @@ class BescheidServiceTest { ...@@ -760,7 +756,7 @@ class BescheidServiceTest {
} }
private OzgCloudCommand buildSetBescheidSentStatusCommand() { private OzgCloudCommand buildSetBescheidSentStatusCommand() {
return service.buildSetBescheidSentStatusCommand(BESCHEID_ITEM, USER_ID); return service.buildSetBescheidSentStatusCommand(BESCHEID_ITEM, UserProfileTestFactory.ID_STR);
} }
} }
...@@ -769,16 +765,16 @@ class BescheidServiceTest { ...@@ -769,16 +765,16 @@ class BescheidServiceTest {
@Test @Test
void shouldSetStatus() { void shouldSetStatus() {
var result = service.buildBescheidSentStatusItem(USER_ID); var result = service.buildBescheidSentStatusItem(UserProfileTestFactory.ID_STR);
assertThat(result).containsEntry(Bescheid.FIELD_STATUS, Bescheid.Status.SENT.name()); assertThat(result).containsEntry(Bescheid.FIELD_STATUS, Bescheid.Status.SENT.name());
} }
@Test @Test
void shouldCallBuildSentInfoMap() { void shouldCallBuildSentInfoMap() {
service.buildBescheidSentStatusItem(USER_ID); service.buildBescheidSentStatusItem(UserProfileTestFactory.ID_STR);
verify(service).buildSentInfoMap(USER_ID); verify(service).buildSentInfoMap(UserProfileTestFactory.ID_STR);
} }
@Test @Test
...@@ -786,7 +782,7 @@ class BescheidServiceTest { ...@@ -786,7 +782,7 @@ class BescheidServiceTest {
var sentInfoMap = Map.of("key", "value"); var sentInfoMap = Map.of("key", "value");
doReturn(sentInfoMap).when(service).buildSentInfoMap(any()); doReturn(sentInfoMap).when(service).buildSentInfoMap(any());
var result = service.buildBescheidSentStatusItem(USER_ID); var result = service.buildBescheidSentStatusItem(UserProfileTestFactory.ID_STR);
assertThat(result).containsEntry(Bescheid.FIELD_SENT_INFO, sentInfoMap); assertThat(result).containsEntry(Bescheid.FIELD_SENT_INFO, sentInfoMap);
} }
...@@ -797,16 +793,16 @@ class BescheidServiceTest { ...@@ -797,16 +793,16 @@ class BescheidServiceTest {
@Test @Test
void shouldSetSentAt() { void shouldSetSentAt() {
var result = service.buildSentInfoMap(USER_ID); var result = service.buildSentInfoMap(UserProfileTestFactory.ID_STR);
assertThat(getSentAt(result)).isCloseTo(ZonedDateTime.now(), within(1, ChronoUnit.SECONDS)); assertThat(getSentAt(result)).isCloseTo(ZonedDateTime.now(), within(1, ChronoUnit.SECONDS));
} }
@Test @Test
void shouldSetSentBy() { void shouldSetSentBy() {
var result = service.buildSentInfoMap(USER_ID); var result = service.buildSentInfoMap(UserProfileTestFactory.ID_STR);
assertThat(result).containsEntry(Bescheid.FIELD_SENT_BY, USER_ID); assertThat(result).containsEntry(Bescheid.FIELD_SENT_BY, UserProfileTestFactory.ID_STR);
} }
private ZonedDateTime getSentAt(Map<String, Object> sentInfoMap) { private ZonedDateTime getSentAt(Map<String, Object> sentInfoMap) {
...@@ -821,7 +817,7 @@ class BescheidServiceTest { ...@@ -821,7 +817,7 @@ class BescheidServiceTest {
private static final Vorgang.PostfachAddress POSTFACH_ADDRESS = PostfachAddressTestFactory.create(); private static final Vorgang.PostfachAddress POSTFACH_ADDRESS = PostfachAddressTestFactory.create();
private static final Vorgang.ServiceKonto SERVICE_KONTO = ServiceKontoTestFactory.createBuilder().clearPostfachAddresses() private static final Vorgang.ServiceKonto SERVICE_KONTO = ServiceKontoTestFactory.createBuilder().clearPostfachAddresses()
.postfachAddress(POSTFACH_ADDRESS).build(); .postfachAddress(POSTFACH_ADDRESS).build();
private static final OzgCloudUserId OZG_CLOUD_USER_ID = OzgCloudUserId.from(USER_ID); private static final OzgCloudUserId OZG_CLOUD_ID = OzgCloudUserId.from(UserProfileTestFactory.ID_STR);
private static final Map<String, Object> OBJECT_MAP = Map.of("key", "value"); private static final Map<String, Object> OBJECT_MAP = Map.of("key", "value");
private static final OzgCloudVorgangId VORGANG_ID = OzgCloudVorgangId.from(VorgangTestFactory.ID.toString()); private static final OzgCloudVorgangId VORGANG_ID = OzgCloudVorgangId.from(VorgangTestFactory.ID.toString());
private static final StringBasedValue RELATION_ID = GenericId.from(VorgangTestFactory.ID.toString()); private static final StringBasedValue RELATION_ID = GenericId.from(VorgangTestFactory.ID.toString());
...@@ -830,7 +826,7 @@ class BescheidServiceTest { ...@@ -830,7 +826,7 @@ class BescheidServiceTest {
void init() { void init() {
when(commandMapper.toOzgCloudVorgangId(anyString())).thenReturn(VORGANG_ID); when(commandMapper.toOzgCloudVorgangId(anyString())).thenReturn(VORGANG_ID);
when(commandMapper.mapRelationId(anyString())).thenReturn(RELATION_ID); when(commandMapper.mapRelationId(anyString())).thenReturn(RELATION_ID);
when(commandMapper.toOzgCloudUserId(anyString())).thenReturn(OZG_CLOUD_USER_ID); when(commandMapper.toOzgCloudUserId(anyString())).thenReturn(OZG_CLOUD_ID);
doReturn(OBJECT_MAP).when(service).buildSendNachrichtCommandBody(any(), any()); doReturn(OBJECT_MAP).when(service).buildSendNachrichtCommandBody(any(), any());
} }
...@@ -897,18 +893,18 @@ class BescheidServiceTest { ...@@ -897,18 +893,18 @@ class BescheidServiceTest {
void shouldCallMapToOzgCloudUserId() { void shouldCallMapToOzgCloudUserId() {
buildSendPostfachNachrichtCommand(); buildSendPostfachNachrichtCommand();
verify(commandMapper).toOzgCloudUserId(USER_ID); verify(commandMapper).toOzgCloudUserId(UserProfileTestFactory.ID_STR);
} }
@Test @Test
void shouldSetCreatedBy() { void shouldSetCreatedBy() {
var result = buildSendPostfachNachrichtCommand(); var result = buildSendPostfachNachrichtCommand();
assertThat(result.getCreatedBy()).isEqualTo(OZG_CLOUD_USER_ID); assertThat(result.getCreatedBy()).isEqualTo(OZG_CLOUD_ID);
} }
private OzgCloudCommand buildSendPostfachNachrichtCommand() { private OzgCloudCommand buildSendPostfachNachrichtCommand() {
return service.buildSendPostfachNachrichtCommand(BESCHEID_ITEM, SERVICE_KONTO, USER_ID); return service.buildSendPostfachNachrichtCommand(BESCHEID_ITEM, SERVICE_KONTO, UserProfileTestFactory.ID_STR);
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment