From 106c80f69d2bb7a83d6bd51ee7ee7d164cadf755 Mon Sep 17 00:00:00 2001 From: vjohnslhm <145964798+vjohnslhm@users.noreply.github.com> Date: Thu, 21 Nov 2024 09:54:42 +0100 Subject: [PATCH] #435 rename tests --- .../CacheControlConfigurationTest.java | 2 +- .../SecurityConfigurationTest.java | 14 +++++----- .../SwaggerConfigurationTest.java | 2 +- .../UnicodeConfigurationTest.java | 2 +- .../UserInfoAuthoritiesServiceTest.java | 27 ++++++++++--------- .../nfcconverter/NfcConverterTest.java | 4 +-- .../nfcconverter/NfcHelperTest.java | 16 +++++------ 7 files changed, 35 insertions(+), 32 deletions(-) diff --git a/wls-wahlvorstand-service/src/test/java/de/muenchen/oss/wahllokalsystem/wahlvorstandservice/configuration/CacheControlConfigurationTest.java b/wls-wahlvorstand-service/src/test/java/de/muenchen/oss/wahllokalsystem/wahlvorstandservice/configuration/CacheControlConfigurationTest.java index 07f102d3c..e2ab13777 100644 --- a/wls-wahlvorstand-service/src/test/java/de/muenchen/oss/wahllokalsystem/wahlvorstandservice/configuration/CacheControlConfigurationTest.java +++ b/wls-wahlvorstand-service/src/test/java/de/muenchen/oss/wahllokalsystem/wahlvorstandservice/configuration/CacheControlConfigurationTest.java @@ -41,7 +41,7 @@ class CacheControlConfigurationTest { @Test @Disabled - void testForCacheControlHeadersForEntityEndpoint() { + void should_returnExpectedHeaderValues_when_givenEndpoint() { ResponseEntity response = testRestTemplate.exchange(ENTITY_ENDPOINT_URL, HttpMethod.GET, null, String.class); assertEquals(HttpStatus.OK, response.getStatusCode()); assertTrue(response.getHeaders().containsKey(HttpHeaders.CACHE_CONTROL)); diff --git a/wls-wahlvorstand-service/src/test/java/de/muenchen/oss/wahllokalsystem/wahlvorstandservice/configuration/SecurityConfigurationTest.java b/wls-wahlvorstand-service/src/test/java/de/muenchen/oss/wahllokalsystem/wahlvorstandservice/configuration/SecurityConfigurationTest.java index ff19e429e..2907111b4 100644 --- a/wls-wahlvorstand-service/src/test/java/de/muenchen/oss/wahllokalsystem/wahlvorstandservice/configuration/SecurityConfigurationTest.java +++ b/wls-wahlvorstand-service/src/test/java/de/muenchen/oss/wahllokalsystem/wahlvorstandservice/configuration/SecurityConfigurationTest.java @@ -23,43 +23,43 @@ class SecurityConfigurationTest { MockMvc api; @Test - void accessSecuredResourceRootThenUnauthorized() throws Exception { + void should_returnStatusUnauthorized_when_accessingSecuredResourceRoot() throws Exception { api.perform(get("/")) .andExpect(status().isUnauthorized()); } @Test - void accessSecuredResourceActuatorThenUnauthorized() throws Exception { + void should_returnStatusUnauthorized_when_accessingSecuredResourceActuator() throws Exception { api.perform(get("/actuator")) .andExpect(status().isUnauthorized()); } @Test - void accessUnsecuredResourceActuatorHealthThenOk() throws Exception { + void should_returnStatusOk_when_accessingUnsecuredResourceActuatorHealth() throws Exception { api.perform(get("/actuator/health")) .andExpect(status().isOk()); } @Test - void accessUnsecuredResourceActuatorInfoThenOk() throws Exception { + void should_returnStatusOk_when_accessingUnsecuredResourceActuatorInfo() throws Exception { api.perform(get("/actuator/info")) .andExpect(status().isOk()); } @Test - void accessUnsecuredResourceActuatorMetricsThenOk() throws Exception { + void should_returnStatusOk_when_accessingUnsecuredResourceActuatorMetrics() throws Exception { api.perform(get("/actuator/metrics")) .andExpect(status().isOk()); } @Test - void accessUnsecuredResourceV3ApiDocsThenOk() throws Exception { + void should_returnStatusOk_when_accessingUnsecuredResourceV3ApiDocs() throws Exception { api.perform(get("/v3/api-docs")) .andExpect(status().isOk()); } @Test - void accessUnsecuredResourceSwaggerUiThenOk() throws Exception { + void should_returnStatusOk_when_accessingUnsecuredResourceSwaggerUi() throws Exception { api.perform(get("/swagger-ui/index.html")) .andExpect(status().isOk()); } diff --git a/wls-wahlvorstand-service/src/test/java/de/muenchen/oss/wahllokalsystem/wahlvorstandservice/configuration/SwaggerConfigurationTest.java b/wls-wahlvorstand-service/src/test/java/de/muenchen/oss/wahllokalsystem/wahlvorstandservice/configuration/SwaggerConfigurationTest.java index 3b27b898b..1538026e5 100644 --- a/wls-wahlvorstand-service/src/test/java/de/muenchen/oss/wahllokalsystem/wahlvorstandservice/configuration/SwaggerConfigurationTest.java +++ b/wls-wahlvorstand-service/src/test/java/de/muenchen/oss/wahllokalsystem/wahlvorstandservice/configuration/SwaggerConfigurationTest.java @@ -34,7 +34,7 @@ class SwaggerConfigurationTest { String version; @Test - void versionIsSetInDoc() throws Exception { + void should_returnVersion_when_setInApiDoc() throws Exception { val request = MockMvcRequestBuilders.get("/v3/api-docs/public-apis").contentType(MediaType.APPLICATION_JSON); val response = mockMvc.perform(request).andReturn(); diff --git a/wls-wahlvorstand-service/src/test/java/de/muenchen/oss/wahllokalsystem/wahlvorstandservice/configuration/UnicodeConfigurationTest.java b/wls-wahlvorstand-service/src/test/java/de/muenchen/oss/wahllokalsystem/wahlvorstandservice/configuration/UnicodeConfigurationTest.java index b53d0e121..8387cad71 100644 --- a/wls-wahlvorstand-service/src/test/java/de/muenchen/oss/wahllokalsystem/wahlvorstandservice/configuration/UnicodeConfigurationTest.java +++ b/wls-wahlvorstand-service/src/test/java/de/muenchen/oss/wahllokalsystem/wahlvorstandservice/configuration/UnicodeConfigurationTest.java @@ -53,7 +53,7 @@ class UnicodeConfigurationTest { @Test @Disabled - void testForNfcNormalization() { + void should_returnComposedString_when_givenDecomposedString() { // Persist entity with decomposed string. final TheEntityDto theEntityDto = new TheEntityDto(); theEntityDto.setTextAttribute(TEXT_ATTRIBUTE_DECOMPOSED); diff --git a/wls-wahlvorstand-service/src/test/java/de/muenchen/oss/wahllokalsystem/wahlvorstandservice/configuration/UserInfoAuthoritiesServiceTest.java b/wls-wahlvorstand-service/src/test/java/de/muenchen/oss/wahllokalsystem/wahlvorstandservice/configuration/UserInfoAuthoritiesServiceTest.java index b1362736f..68f30d1a7 100644 --- a/wls-wahlvorstand-service/src/test/java/de/muenchen/oss/wahllokalsystem/wahlvorstandservice/configuration/UserInfoAuthoritiesServiceTest.java +++ b/wls-wahlvorstand-service/src/test/java/de/muenchen/oss/wahllokalsystem/wahlvorstandservice/configuration/UserInfoAuthoritiesServiceTest.java @@ -56,7 +56,7 @@ public RestTemplate build() { class LoadAuthorities { @Test - void buildAuthoritiesFromTemplateResponseWithCollection() { + void should_loadAuthoritiesFromTemplate_when_givenAsCollection() { val jwtTokenValue = "myTokenValue"; val expectedRequestHeaders = new HttpHeaders(); @@ -81,12 +81,13 @@ void buildAuthoritiesFromTemplateResponseWithCollection() { val authorities = unitUnderTest.loadAuthorities(jwt); - Assertions.assertThat(authorities).hasSize(claimAuthorityValues.size()); - Assertions.assertThat(authorities).containsAll(expectedAuthorities); + Assertions.assertThat(authorities) + .hasSize(claimAuthorityValues.size()) + .containsAll(expectedAuthorities); } @Test - void buildAuthoritiesFromTemplateResponseWithArray() { + void should_loadAuthoritiesFromTemplate_when_givenAsArray() { val jwtTokenValue = "myTokenValue"; val expectedRequestHeaders = new HttpHeaders(); @@ -111,12 +112,13 @@ void buildAuthoritiesFromTemplateResponseWithArray() { val authorities = unitUnderTest.loadAuthorities(jwt); - Assertions.assertThat(authorities).hasSize(claimAuthorityValues.length); - Assertions.assertThat(authorities).containsAll(expctedAuthorities); + Assertions.assertThat(authorities) + .hasSize(claimAuthorityValues.length) + .containsAll(expctedAuthorities); } @Test - void buildAuthoritiesFromTemplateResponseWithUnhandledDataStructure() { + void should_returnEmptyList_when_givenAsUnhandledDataStructure() { val jwtTokenValue = "myTokenValue"; val expectedRequestHeaders = new HttpHeaders(); @@ -139,7 +141,7 @@ void buildAuthoritiesFromTemplateResponseWithUnhandledDataStructure() { } @Test - void buildAuthoritiesFromTemplateResponseWithoutAuthoritiesClaim() { + void should_returnEmptyList_when_noAuthoritiesFound() { val jwtTokenValue = "myTokenValue"; val expectedRequestHeaders = new HttpHeaders(); @@ -159,7 +161,7 @@ void buildAuthoritiesFromTemplateResponseWithoutAuthoritiesClaim() { } @Test - void errorWhileLoadingViaTemplate() { + void should_returnEmptyList_when_errorThrownWhileLoadingViaTemplate() { val jwtTokenValue = "myTokenValue"; val expectedRequestHeaders = new HttpHeaders(); @@ -176,7 +178,7 @@ void errorWhileLoadingViaTemplate() { } @Test - void loadedAuthoritiesAsPlacedInCache() { + void should_loadAuthoritiesFromCache_when_givenValidJwtToken() { val jwtSubject = "subject"; val jwtTokenValue = "myTokenValue"; val jwtForCachMethodCall = Mockito.mock(Jwt.class); @@ -206,8 +208,9 @@ void loadedAuthoritiesAsPlacedInCache() { val authoritiesThatShouldComeFromCache = unitUnderTest.loadAuthorities(jwtForCachMethodCall); - Assertions.assertThat(authorities).hasSize(claimAuthorityValues.size()); - Assertions.assertThat(authorities).containsAll(expectedAuthorities); + Assertions.assertThat(authorities) + .hasSize(claimAuthorityValues.size()) + .containsAll(expectedAuthorities); Assertions.assertThat(authoritiesThatShouldComeFromCache).isSameAs(authorities); Mockito.verify(restTemplate, Mockito.times(1)).exchange(userInfoUri, HttpMethod.GET, expectedRequestEntity, Map.class); diff --git a/wls-wahlvorstand-service/src/test/java/de/muenchen/oss/wahllokalsystem/wahlvorstandservice/configuration/nfcconverter/NfcConverterTest.java b/wls-wahlvorstand-service/src/test/java/de/muenchen/oss/wahllokalsystem/wahlvorstandservice/configuration/nfcconverter/NfcConverterTest.java index 44377ac94..b7f74c5e4 100644 --- a/wls-wahlvorstand-service/src/test/java/de/muenchen/oss/wahllokalsystem/wahlvorstandservice/configuration/nfcconverter/NfcConverterTest.java +++ b/wls-wahlvorstand-service/src/test/java/de/muenchen/oss/wahllokalsystem/wahlvorstandservice/configuration/nfcconverter/NfcConverterTest.java @@ -76,7 +76,7 @@ class NfcConverterTest { // Test, das Request mit konfigriertem ContentType auf NFC normalisiert wird. // @Test - void testFilterIfContenttypeInWhitelist() throws ServletException, IOException { + void should_executeFilter_when_contenttypeInWhitelist() throws ServletException, IOException { mockRequest("text/plain"); filter.setContentTypes("text/plain;text/html;application/json"); @@ -105,7 +105,7 @@ void testFilterIfContenttypeInWhitelist() throws ServletException, IOException { // auf NFC normalisiert wird. // @Test - void testSkipFilterIfContenttypeNotInWhitelist() throws ServletException, IOException { + void should_skipFilter_when_contenttypeNotInWhitelist() throws ServletException, IOException { mockRequest("application/postscript"); filter.setContentTypes("text/plain;text/html"); diff --git a/wls-wahlvorstand-service/src/test/java/de/muenchen/oss/wahllokalsystem/wahlvorstandservice/configuration/nfcconverter/NfcHelperTest.java b/wls-wahlvorstand-service/src/test/java/de/muenchen/oss/wahllokalsystem/wahlvorstandservice/configuration/nfcconverter/NfcHelperTest.java index c47f2d504..16fc5c4af 100644 --- a/wls-wahlvorstand-service/src/test/java/de/muenchen/oss/wahllokalsystem/wahlvorstandservice/configuration/nfcconverter/NfcHelperTest.java +++ b/wls-wahlvorstand-service/src/test/java/de/muenchen/oss/wahllokalsystem/wahlvorstandservice/configuration/nfcconverter/NfcHelperTest.java @@ -34,7 +34,7 @@ class NfcHelperTest { private static final String[] NFC_OUTPUT_EXPECTED = new String[] { FIRST_NFC, SECOND_NFC, THIRD_NFC }; @Test - void nfcConverterString() { + void should_convertCorrectly_when_givenString() { assertEquals(FIRST_NFC, NfcHelper.nfcConverter(FIRST_NFD)); assertEquals(FIRST_NFC.length(), NfcHelper.nfcConverter(FIRST_NFD).length()); @@ -48,7 +48,7 @@ void nfcConverterString() { } @Test - void nfcConverterStringBuffer() { + void should_convertCorrectly_when_givenStringBuffer() { assertEquals(FIRST_NFC, NfcHelper.nfcConverter(new StringBuffer(FIRST_NFD)).toString()); assertEquals(FIRST_NFC.length(), NfcHelper.nfcConverter(new StringBuffer(FIRST_NFD)).length()); @@ -60,13 +60,13 @@ void nfcConverterStringBuffer() { } @Test - void nfcConverterStringArray() { + void should_convertCorrectly_when_givenArrayOfStrings() { assertArrayEquals(NFC_OUTPUT_EXPECTED, NfcHelper.nfcConverter(NFD_INPUT)); assertEquals(NFC_OUTPUT_EXPECTED.length, NfcHelper.nfcConverter(NFD_INPUT).length); } @Test - void nfcConverterMapOfStrings() { + void should_convertCorrectly_when_givenMapOfStrings() { final Map nfdInput = new HashMap<>(); nfdInput.put(FIRST_NFD, NFD_INPUT); nfdInput.put(SECOND_NFD, NFD_INPUT); @@ -80,7 +80,7 @@ void nfcConverterMapOfStrings() { } @Test - void nfcConverterCookie() { + void should_convertCorrectly_when_givenCookie() { final Cookie nfcCookie = NfcHelper.nfcConverter(createNfdCookie()); assertEquals(NfcConverterTest.TOKEN, nfcCookie.getName()); @@ -90,7 +90,7 @@ void nfcConverterCookie() { } @Test - void nfcConverterCookieWithoutDomain() { + void should_convertCorrectly_when_givenCookieWithoutDomain() { final Cookie cookieToConvert = createNfdCookie(); cookieToConvert.setDomain(null); final Cookie nfcCookie = NfcHelper.nfcConverter(cookieToConvert); @@ -102,7 +102,7 @@ void nfcConverterCookieWithoutDomain() { } @Test - void nfcConverterCookieArray() { + void should_convertCorrectly_when_givenArrayOfCookies() { final Cookie[] nfdCookies = Collections.nCopies(3, createNfdCookie()).toArray(new Cookie[3]); final Cookie[] nfcCookies = NfcHelper.nfcConverter(nfdCookies); Arrays.asList(nfcCookies).forEach(nfcCookie -> { @@ -114,7 +114,7 @@ void nfcConverterCookieArray() { } @Test - void nfcConverterCookieArrayNullReturnNull() { + void should_returnNull_when_givenEmptyArrayOfCookies() { assertNull(NfcHelper.nfcConverter((Cookie[]) null)); }