Skip to content
Snippets Groups Projects
Commit fe0c4ff8 authored by Jan Zickermann's avatar Jan Zickermann
Browse files

OZG-7978 servicekonto: Cleanup test

parent f1360a3e
Branches
Tags
1 merge request!18OZG-7978 servicekonto: Catch runtime-exception in getPostfachAddressType
...@@ -31,6 +31,7 @@ import static org.mockito.Mockito.*; ...@@ -31,6 +31,7 @@ import static org.mockito.Mockito.*;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.assertj.core.api.InstanceOfAssertFactories;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Nested;
...@@ -116,7 +117,7 @@ class ServiceKontoFactoryTest { ...@@ -116,7 +117,7 @@ class ServiceKontoFactoryTest {
} }
@Test @Test
void shouldReturnPostfachAddresses() { void shouldBuildPostfachAddresses() {
var addresses = getPostfachAddresses(); var addresses = getPostfachAddresses();
assertThat(addresses).hasSize(1); assertThat(addresses).hasSize(1);
...@@ -127,10 +128,10 @@ class ServiceKontoFactoryTest { ...@@ -127,10 +128,10 @@ class ServiceKontoFactoryTest {
assertThat(addresses.get(0).getType()).isEqualTo(PostfachAddressTestFactory.POSTFACH_ADDRESS_TYPE); assertThat(addresses.get(0).getType()).isEqualTo(PostfachAddressTestFactory.POSTFACH_ADDRESS_TYPE);
} }
@DisplayName("should return with postfach address type") @DisplayName("should build with postfach address type")
@ParameterizedTest @ParameterizedTest
@ValueSource(ints = { 1, 2, 3 }) @ValueSource(ints = { 1, 2, 3 })
void shouldReturnWithPostfachAddressType(int postfachAddressType) { void shouldBuildWithPostfachAddressType(int postfachAddressType) {
var formDataWithPostfachAddressType = FormDataUtils.from(FORM_DATA) var formDataWithPostfachAddressType = FormDataUtils.from(FORM_DATA)
.put(ServiceKontoFactory.REST_RESPONSE_NAME, List.of(Map.of( .put(ServiceKontoFactory.REST_RESPONSE_NAME, List.of(Map.of(
ServiceKontoFactory.REST_RESPONSE_NAME_MEMBER_SCOPE, ServiceKontoFactory.REST_RESPONSE_NAME_MEMBER_SCOPE,
...@@ -139,13 +140,12 @@ class ServiceKontoFactoryTest { ...@@ -139,13 +140,12 @@ class ServiceKontoFactoryTest {
) )
.build(); .build();
var addresses = buildServiceKonto(formDataWithPostfachAddressType); var serviceKonto = buildServiceKonto(formDataWithPostfachAddressType);
var types = addresses.getPostfachAddresses() assertThat(serviceKonto)
.stream() .extracting(ServiceKonto::getPostfachAddresses, InstanceOfAssertFactories.list(PostfachAddress.class))
.map(PostfachAddress::getType) .extracting(PostfachAddress::getType)
.toList(); .containsExactly(postfachAddressType);
assertThat(types).containsExactly(postfachAddressType);
} }
private List<PostfachAddress> getPostfachAddresses() { private List<PostfachAddress> getPostfachAddresses() {
...@@ -153,34 +153,31 @@ class ServiceKontoFactoryTest { ...@@ -153,34 +153,31 @@ class ServiceKontoFactoryTest {
} }
} }
@DisplayName("with bad rest_response_name") @DisplayName("with unexpected rest_response_name")
@Nested @Nested
class TestWithBadRestResponseName { class TestWithUnexpectedRestResponseName {
private final FormData formDataWithBadRestResponseName = FormDataUtils.from(FORM_DATA) private final FormData formDataWithUnexpectedRestResponseName = FormDataUtils.from(FORM_DATA)
.put(ServiceKontoFactory.REST_RESPONSE_NAME, List.of(Map.of())).build(); .put(ServiceKontoFactory.REST_RESPONSE_NAME, List.of(Map.of())).build();
@DisplayName("should call buildOsiPostfachV1Address") @DisplayName("should call buildOsiPostfachV1Address")
@Test @Test
void shouldCallBuildOsiPostfachV1Address() { void shouldCallBuildOsiPostfachV1Address() {
getPostfachAddresses(); buildServiceKonto(formDataWithUnexpectedRestResponseName);
verify(factory).buildOsiPostfachV1Address(any(), anyInt()); verify(factory).buildOsiPostfachV1Address(any(), anyInt());
} }
@DisplayName("should return postfach address with default type") @DisplayName("should build postfach address with default type")
@Test @Test
void shouldReturnPostfachAddressWithDefaultType() { void shouldBuildPostfachAddressWithDefaultType() {
var addresses = getPostfachAddresses(); var serviceKonto = buildServiceKonto(formDataWithUnexpectedRestResponseName);
assertThat(addresses) assertThat(serviceKonto)
.extracting("type") .extracting(ServiceKonto::getPostfachAddresses, InstanceOfAssertFactories.list(PostfachAddress.class))
.extracting(PostfachAddress::getType)
.containsExactly(POSTFACH_ADDRESS_DEFAULT); .containsExactly(POSTFACH_ADDRESS_DEFAULT);
} }
private List<PostfachAddress> getPostfachAddresses() {
return buildServiceKonto(formDataWithBadRestResponseName).getPostfachAddresses();
}
} }
@DisplayName("without rest_response_name") @DisplayName("without rest_response_name")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment