Skip to content

Commit d4e3b68

Browse files
committed
Update unit test so that the cache it tested in one test.
1 parent 2e0ddfd commit d4e3b68

File tree

3 files changed

+10
-22
lines changed

3 files changed

+10
-22
lines changed

springdoc-openapi-webmvc-core/src/test/java/test/org/springdoc/api/app170/SpringDocApp170Test.java

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -38,48 +38,36 @@
3838

3939
import test.org.springdoc.api.AbstractSpringDocTest;
4040

41-
//@TestPropertySource(properties = Constants.SPRINGDOC_CACHE_DISABLED + "=true")
41+
@TestPropertySource(properties = Constants.SPRINGDOC_CACHE_DISABLED + "=false")
4242
public class SpringDocApp170Test extends AbstractSpringDocTest {
4343

4444
@SpringBootApplication
45-
static class SpringDocTestApp {}
45+
static class SpringDocTestApp {
46+
}
4647

4748
@Bean
4849
public LocaleResolver localeResolver() {
4950
SessionLocaleResolver localeResolver = new SessionLocaleResolver();
50-
localeResolver.setDefaultLocale(Locale.US);
5151
return localeResolver;
5252
}
5353

5454
@Test
55-
@Override
55+
@Override
5656
public void testApp() throws Exception {
57-
Locale locale = new Locale("en","US");
58-
Locale.setDefault(locale);
59-
60-
className = getClass().getSimpleName();
61-
String testNumber = className.replaceAll("[^0-9]", "");
62-
MvcResult mockMvcResult =
63-
mockMvc.perform(get(Constants.DEFAULT_API_DOCS_URL).locale(locale).header(HttpHeaders.ACCEPT_LANGUAGE, locale.toLanguageTag())).andExpect(status().isOk())
64-
.andExpect(jsonPath("$.openapi", is("3.0.1"))).andReturn();
65-
String result = mockMvcResult.getResponse().getContentAsString();
66-
String expected = getContent("results/app" + testNumber + "-1.json");
67-
assertEquals(expected, result, true);
57+
testApp(Locale.US);
58+
testApp(Locale.FRANCE);
6859
}
6960

70-
@Test
71-
public void testAppFr() throws Exception {
72-
Locale locale = new Locale("fr","FR");
61+
private void testApp(Locale locale) throws Exception {
7362
Locale.setDefault(locale);
7463

7564
className = getClass().getSimpleName();
7665
String testNumber = className.replaceAll("[^0-9]", "");
7766
MvcResult mockMvcResult =
7867
mockMvc.perform(get(Constants.DEFAULT_API_DOCS_URL).locale(locale).header(HttpHeaders.ACCEPT_LANGUAGE, locale.toLanguageTag())).andExpect(status().isOk())
79-
.andExpect(jsonPath("$.openapi", is("3.0.1"))).andReturn();
68+
.andExpect(jsonPath("$.openapi", is("3.0.1"))).andReturn();
8069
String result = mockMvcResult.getResponse().getContentAsString();
81-
String expected = getContent("results/app" + testNumber + "-2.json");
70+
String expected = getContent("results/app" + testNumber + "-" + locale.getLanguage() + ".json");
8271
assertEquals(expected, result, true);
8372
}
84-
85-
}
73+
}

0 commit comments

Comments
 (0)