Skip to content

Commit

Permalink
#435 rename tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vjohnslhm committed Nov 21, 2024
1 parent f952b4d commit 106c80f
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class CacheControlConfigurationTest {

@Test
@Disabled
void testForCacheControlHeadersForEntityEndpoint() {
void should_returnExpectedHeaderValues_when_givenEndpoint() {
ResponseEntity<String> response = testRestTemplate.exchange(ENTITY_ENDPOINT_URL, HttpMethod.GET, null, String.class);
assertEquals(HttpStatus.OK, response.getStatusCode());
assertTrue(response.getHeaders().containsKey(HttpHeaders.CACHE_CONTROL));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public RestTemplate build() {
class LoadAuthorities {

@Test
void buildAuthoritiesFromTemplateResponseWithCollection() {
void should_loadAuthoritiesFromTemplate_when_givenAsCollection() {
val jwtTokenValue = "myTokenValue";

val expectedRequestHeaders = new HttpHeaders();
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -139,7 +141,7 @@ void buildAuthoritiesFromTemplateResponseWithUnhandledDataStructure() {
}

@Test
void buildAuthoritiesFromTemplateResponseWithoutAuthoritiesClaim() {
void should_returnEmptyList_when_noAuthoritiesFound() {
val jwtTokenValue = "myTokenValue";

val expectedRequestHeaders = new HttpHeaders();
Expand All @@ -159,7 +161,7 @@ void buildAuthoritiesFromTemplateResponseWithoutAuthoritiesClaim() {
}

@Test
void errorWhileLoadingViaTemplate() {
void should_returnEmptyList_when_errorThrownWhileLoadingViaTemplate() {
val jwtTokenValue = "myTokenValue";

val expectedRequestHeaders = new HttpHeaders();
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand All @@ -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());

Expand All @@ -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<String, String[]> nfdInput = new HashMap<>();
nfdInput.put(FIRST_NFD, NFD_INPUT);
nfdInput.put(SECOND_NFD, NFD_INPUT);
Expand All @@ -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());
Expand All @@ -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);
Expand All @@ -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 -> {
Expand All @@ -114,7 +114,7 @@ void nfcConverterCookieArray() {
}

@Test
void nfcConverterCookieArrayNullReturnNull() {
void should_returnNull_when_givenEmptyArrayOfCookies() {
assertNull(NfcHelper.nfcConverter((Cookie[]) null));
}

Expand Down

0 comments on commit 106c80f

Please sign in to comment.