Skip to content
This repository was archived by the owner on Jan 13, 2023. It is now read-only.

Commit 7dbae9c

Browse files
committed
GP-6: remove redundant public accessor in test methods declaration
1 parent c29436f commit 7dbae9c

File tree

7 files changed

+121
-96
lines changed

7 files changed

+121
-96
lines changed

account-jsp/src/test/java/com/bobocode/AccountControllerTest.java

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,32 +14,36 @@
1414
import org.springframework.web.context.WebApplicationContext;
1515

1616
import static org.hamcrest.MatcherAssert.assertThat;
17-
import static org.hamcrest.Matchers.*;
17+
import static org.hamcrest.Matchers.arrayContaining;
18+
import static org.hamcrest.Matchers.arrayWithSize;
19+
import static org.hamcrest.Matchers.hasSize;
1820
import static org.hamcrest.core.IsNull.notNullValue;
1921
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
20-
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
22+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.model;
23+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
24+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view;
2125

2226
@SpringJUnitWebConfig(classes = {RootConfig.class, WebConfig.class})
23-
public class AccountControllerTest {
27+
class AccountControllerTest {
2428
@Autowired
2529
private WebApplicationContext applicationContext;
2630

2731
private MockMvc mockMvc;
2832

2933
@BeforeEach
30-
public void setup() {
34+
void setup() {
3135
mockMvc = MockMvcBuilders.webAppContextSetup(applicationContext).build();
3236
}
3337

3438
@Test
35-
public void testAccountControllerAnnotation() {
39+
void testAccountControllerAnnotation() {
3640
Controller controller = AccountController.class.getAnnotation(Controller.class);
3741

3842
assertThat(controller, notNullValue());
3943
}
4044

4145
@Test
42-
public void testAccountControllerRequestMapping() {
46+
void testAccountControllerRequestMapping() {
4347
RequestMapping requestMapping = AccountController.class.getAnnotation(RequestMapping.class);
4448

4549
assertThat(requestMapping, notNullValue());
@@ -48,30 +52,30 @@ public void testAccountControllerRequestMapping() {
4852
}
4953

5054
@Test
51-
public void testGetAccountsResponseStatusCode() throws Exception {
55+
void testGetAccountsResponseStatusCode() throws Exception {
5256
mockMvc.perform(get("/accounts")).andExpect(status().isOk());
5357
}
5458

5559
@Test
56-
public void testGetAccountsViewName() throws Exception {
60+
void testGetAccountsViewName() throws Exception {
5761
mockMvc.perform(get("/accounts"))
5862
.andExpect(view().name("accounts"));
5963
}
6064

6165
@Test
62-
public void testGetAccountsModelContainsAccountList() throws Exception {
66+
void testGetAccountsModelContainsAccountList() throws Exception {
6367
mockMvc.perform(get("/accounts"))
6468
.andExpect(model().attributeExists("accountList"));
6569
}
6670

6771
@Test
68-
public void testAccountsResponseDefaultListSize() throws Exception {
72+
void testAccountsResponseDefaultListSize() throws Exception {
6973
mockMvc.perform(get("/accounts"))
7074
.andExpect(model().attribute("accountList", hasSize(10)));
7175
}
7276

7377
@Test
74-
public void testAccountsResponseListSize() throws Exception {
78+
void testAccountsResponseListSize() throws Exception {
7579
mockMvc.perform(get("/accounts").param("size", "20"))
7680
.andExpect(model().attribute("accountList", hasSize(20)));
7781
}

account-jsp/src/test/java/com/bobocode/WebAppConfigTest.java

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,58 +21,62 @@
2121
import java.util.stream.Stream;
2222

2323
import static org.hamcrest.MatcherAssert.assertThat;
24-
import static org.hamcrest.Matchers.*;
24+
import static org.hamcrest.Matchers.arrayContaining;
25+
import static org.hamcrest.Matchers.arrayWithSize;
26+
import static org.hamcrest.Matchers.containsInAnyOrder;
27+
import static org.hamcrest.Matchers.equalTo;
28+
import static org.hamcrest.Matchers.notNullValue;
2529

2630
@SpringJUnitConfig(classes = RootConfig.class)
27-
public class WebAppConfigTest {
31+
class WebAppConfigTest {
2832

2933
@Autowired
3034
private ApplicationContext applicationContext;
3135

3236
@Test
33-
public void testDispatcherServletMapping() {
37+
void testDispatcherServletMapping() {
3438
WebAppInitializerWrapper webAppInitializerWrapper = new WebAppInitializerWrapper();
3539

3640
assertThat(webAppInitializerWrapper.getServletMappings(), arrayContaining("/"));
3741
}
3842

3943
@Test
40-
public void testInitializerRootConfigClasses() {
44+
void testInitializerRootConfigClasses() {
4145
WebAppInitializerWrapper webAppInitializerWrapper = new WebAppInitializerWrapper();
4246

4347
assertThat(webAppInitializerWrapper.getRootConfigClasses(), arrayContaining(RootConfig.class));
4448
}
4549

4650
@Test
47-
public void testInitializerWebConfigClasses() {
51+
void testInitializerWebConfigClasses() {
4852
WebAppInitializerWrapper webAppInitializerWrapper = new WebAppInitializerWrapper();
4953

5054
assertThat(webAppInitializerWrapper.getServletConfigClasses(), arrayContaining(WebConfig.class));
5155
}
5256

5357
@Test
54-
public void testRootConfigClassIsMarkedAsConfiguration() {
58+
void testRootConfigClassIsMarkedAsConfiguration() {
5559
Configuration configuration = RootConfig.class.getAnnotation(Configuration.class);
5660

5761
assertThat(configuration, notNullValue());
5862
}
5963

6064
@Test
61-
public void testRootConfigClassEnablesComponentScan() {
65+
void testRootConfigClassEnablesComponentScan() {
6266
ComponentScan componentScan = RootConfig.class.getAnnotation(ComponentScan.class);
6367

6468
assertThat(componentScan, notNullValue());
6569
}
6670

6771
@Test
68-
public void testRootConfigComponentScanPackages() {
72+
void testRootConfigComponentScanPackages() {
6973
ComponentScan componentScan = RootConfig.class.getAnnotation(ComponentScan.class);
7074

7175
assertThat(componentScan.basePackages(), arrayContaining("com.bobocode"));
7276
}
7377

7478
@Test
75-
public void testRootConfigComponentScanFilters() {
79+
void testRootConfigComponentScanFilters() {
7680
ComponentScan componentScan = RootConfig.class.getAnnotation(ComponentScan.class);
7781
Filter[] filters = componentScan.excludeFilters();
7882
List<Class> filteredClasses = getFilteredClasses(filters);
@@ -88,42 +92,42 @@ private List<Class> getFilteredClasses(Filter[] filters) {
8892
}
8993

9094
@Test
91-
public void testWebConfigIsMarkedAsConfiguration() {
95+
void testWebConfigIsMarkedAsConfiguration() {
9296
Configuration configuration = WebConfig.class.getAnnotation(Configuration.class);
9397

9498
assertThat(configuration, notNullValue());
9599
}
96100

97101
@Test
98-
public void testWebConfigEnablesComponentScan() {
102+
void testWebConfigEnablesComponentScan() {
99103
ComponentScan componentScan = WebConfig.class.getAnnotation(ComponentScan.class);
100104

101105
assertThat(componentScan, notNullValue());
102106
}
103107

104108
@Test
105-
public void testWebConfigComponentScanPackages() {
109+
void testWebConfigComponentScanPackages() {
106110
ComponentScan componentScan = WebConfig.class.getAnnotation(ComponentScan.class);
107111

108112
assertThat(componentScan.value(), arrayContaining("com.bobocode.web"));
109113
}
110114

111115
@Test
112-
public void testWebConfigEnablesWebMvc() {
116+
void testWebConfigEnablesWebMvc() {
113117
EnableWebMvc enableWebMvc = WebConfig.class.getAnnotation(EnableWebMvc.class);
114118

115119
assertThat(enableWebMvc, notNullValue());
116120
}
117121

118122
@Test
119-
public void testDataGeneratorBeanName() {
123+
void testDataGeneratorBeanName() {
120124
TestDataGenerator dataGenerator = applicationContext.getBean("dataGenerator", TestDataGenerator.class);
121125

122126
assertThat(dataGenerator, notNullValue());
123127
}
124128

125129
@Test
126-
public void testDataGeneratorBeanNameIsNotSpecifiedExplicitly() {
130+
void testDataGeneratorBeanNameIsNotSpecifiedExplicitly() {
127131
Method[] methods = RootConfig.class.getMethods();
128132
Method testDataGeneratorBeanMethod = findTestDataGeneratorBeanMethod(methods);
129133
Bean bean = testDataGeneratorBeanMethod.getDeclaredAnnotation(Bean.class);

account-jsp/src/test/java/com/bobocode/WelcomeControllerTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,31 +15,31 @@
1515
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view;
1616

1717
@SpringJUnitWebConfig(classes = {RootConfig.class, WebConfig.class})
18-
public class WelcomeControllerTest {
18+
class WelcomeControllerTest {
1919
@Autowired
2020
private WebApplicationContext applicationContext;
2121

2222
private MockMvc mockMvc;
2323

2424
@BeforeEach
25-
public void setup() {
25+
void setup() {
2626
mockMvc = MockMvcBuilders.webAppContextSetup(applicationContext).build();
2727
}
2828

2929
@Test
30-
public void testWelcomeUrl() throws Exception {
30+
void testWelcomeUrl() throws Exception {
3131
mockMvc.perform(get("/welcome"))
3232
.andExpect(status().isOk());
3333
}
3434

3535
@Test
36-
public void testRootUrl() throws Exception {
36+
void testRootUrl() throws Exception {
3737
mockMvc.perform(get("/"))
3838
.andExpect(status().isOk());
3939
}
4040

4141
@Test
42-
public void testWelcomeViewName() throws Exception {
42+
void testWelcomeViewName() throws Exception {
4343
mockMvc.perform(get("/"))
4444
.andExpect(view().name("welcome"));
4545
}

account-rest-api/src/test/java/com/bobocode/AccountRestControllerTest.java

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,19 @@
1717
import org.springframework.web.context.WebApplicationContext;
1818

1919
import static org.hamcrest.MatcherAssert.assertThat;
20-
import static org.hamcrest.Matchers.*;
20+
import static org.hamcrest.Matchers.arrayContaining;
21+
import static org.hamcrest.Matchers.arrayWithSize;
22+
import static org.hamcrest.Matchers.hasItems;
2123
import static org.hamcrest.core.IsNull.notNullValue;
22-
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
24+
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
25+
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
26+
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
27+
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put;
2328
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
2429
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
2530

2631
@SpringJUnitWebConfig(classes = {RootConfig.class, WebConfig.class})
27-
public class AccountRestControllerTest {
32+
class AccountRestControllerTest {
2833
@Autowired
2934
private WebApplicationContext applicationContext;
3035

@@ -34,20 +39,20 @@ public class AccountRestControllerTest {
3439
private MockMvc mockMvc;
3540

3641
@BeforeEach
37-
public void setup() {
42+
void setup() {
3843
mockMvc = MockMvcBuilders.webAppContextSetup(applicationContext).build();
3944
accountDao.clear();
4045
}
4146

4247
@Test
43-
public void testAccountRestControllerAnnotation() {
48+
void testAccountRestControllerAnnotation() {
4449
RestController restController = AccountRestController.class.getAnnotation(RestController.class);
4550

4651
assertThat(restController, notNullValue());
4752
}
4853

4954
@Test
50-
public void testAccountRestControllerRequestMapping() {
55+
void testAccountRestControllerRequestMapping() {
5156
RequestMapping requestMapping = AccountRestController.class.getAnnotation(RequestMapping.class);
5257

5358
assertThat(requestMapping, notNullValue());
@@ -56,7 +61,7 @@ public void testAccountRestControllerRequestMapping() {
5661
}
5762

5863
@Test
59-
public void testHttpStatusCodeOnCreate() throws Exception {
64+
void testHttpStatusCodeOnCreate() throws Exception {
6065
mockMvc.perform(
6166
post("/accounts")
6267
.contentType(MediaType.APPLICATION_JSON)
@@ -65,7 +70,7 @@ public void testHttpStatusCodeOnCreate() throws Exception {
6570
}
6671

6772
@Test
68-
public void testCreateAccountReturnsAssignedId() throws Exception {
73+
void testCreateAccountReturnsAssignedId() throws Exception {
6974
mockMvc.perform(
7075
post("/accounts")
7176
.contentType(MediaType.APPLICATION_JSON)
@@ -74,13 +79,13 @@ public void testCreateAccountReturnsAssignedId() throws Exception {
7479
}
7580

7681
@Test
77-
public void testGetAccountsResponseStatusCode() throws Exception {
82+
void testGetAccountsResponseStatusCode() throws Exception {
7883
mockMvc.perform(get("/accounts").accept(MediaType.APPLICATION_JSON_UTF8))
7984
.andExpect(status().isOk());
8085
}
8186

8287
@Test
83-
public void testGetAllAccounts() throws Exception {
88+
void testGetAllAccounts() throws Exception {
8489
Account account1 = create("Johnny", "Boy", "jboy@gmail.com");
8590
Account account2 = create("Okko", "Bay", "obay@gmail.com");
8691
accountDao.save(account1);
@@ -91,7 +96,7 @@ public void testGetAllAccounts() throws Exception {
9196
.andExpect(jsonPath("$.[*].email").value(hasItems("jboy@gmail.com", "obay@gmail.com")));
9297
}
9398

94-
private Account create(String firstName, String lastName, String email){
99+
private Account create(String firstName, String lastName, String email) {
95100
Account account = new Account();
96101
account.setFirstName(firstName);
97102
account.setLastName(lastName);
@@ -100,7 +105,7 @@ private Account create(String firstName, String lastName, String email){
100105
}
101106

102107
@Test
103-
public void testGetById() throws Exception {
108+
void testGetById() throws Exception {
104109
Account account = create("Johnny", "Boy", "jboy@gmail.com");
105110
accountDao.save(account);
106111

@@ -113,7 +118,7 @@ public void testGetById() throws Exception {
113118
}
114119

115120
@Test
116-
public void testRemoveAccount() throws Exception {
121+
void testRemoveAccount() throws Exception {
117122
Account account = create("Johnny", "Boy", "jboy@gmail.com");
118123
accountDao.save(account);
119124

@@ -122,7 +127,7 @@ public void testRemoveAccount() throws Exception {
122127
}
123128

124129
@Test
125-
public void testUpdateAccount() throws Exception {
130+
void testUpdateAccount() throws Exception {
126131
Account account = create("Johnny", "Boy", "jboy@gmail.com");
127132
accountDao.save(account);
128133

0 commit comments

Comments
 (0)