Skip to content

Commit ecb63ee

Browse files
committed
GP-82 review updates
1 parent 124ec60 commit ecb63ee

File tree

9 files changed

+10
-198
lines changed

9 files changed

+10
-198
lines changed

3-0-spring-framework/3-0-0-hello-spring-framework/src/main/java/com/bobocode/config/ApplicationConfig.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,27 @@
11
package com.bobocode.config;
22

33
import com.bobocode.TestDataGenerator;
4-
import org.springframework.context.annotation.*;
4+
import org.springframework.context.annotation.Bean;
5+
import org.springframework.context.annotation.ComponentScan;
6+
import org.springframework.context.annotation.Import;
7+
import org.springframework.context.annotation.ImportResource;
58
import org.springframework.stereotype.Component;
69

710
/**
811
* This class specify application context configuration. Basically, it's all about which instances of which classes
912
* should be created and registered in the context. An instance that is registered in the context is called 'bean'.
10-
*
13+
* <p>
1114
* To tell the container, which bean should be created, you could either specify packages to scan using @{@link ComponentScan},
1215
* or declare your own beans using @{@link Bean}. When you use @{@link ComponentScan} the container will discover
1316
* specified package and its sub-folders, to find all classes marked @{@link Component}.
14-
*
17+
* <p>
1518
* If you want to import other configs from Java class or XML file, you could use @{@link Import}
1619
* and @{@link ImportResource} accordingly
1720
* <p>
1821
* todo 1: make this class a Spring configuration class
1922
* todo 2: enable component scanning for dao and service packages
2023
* todo 3: provide explicit configuration for a bean of type {@link TestDataGenerator} with name "dataGenerator" in this class.
21-
* hint: use method creation approach with @Bean annotation;
24+
* hint: use method creation approach with @Bean annotation;
2225
* todo 4: Don't specify bean name "dataGenerator" explicitly
2326
*/
2427

3-0-spring-framework/3-0-0-hello-spring-framework/src/main/java/com/bobocode/service/AccountService.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22

33
import com.bobocode.dao.AccountDao;
44
import com.bobocode.model.Account;
5-
import org.springframework.beans.factory.annotation.Autowired;
6-
import org.springframework.stereotype.Component;
7-
import org.springframework.stereotype.Service;
85

96
import java.util.Comparator;
107
import java.util.List;

3-0-spring-framework/3-0-0-hello-spring-framework/src/test/java/com/bobocode/ApplicationConfigTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ void componentScanIsEnabled() {
4040

4141
@Test
4242
@Order(3)
43-
@DisplayName("@ComponentScan packages are specified")
43+
@DisplayName("@ComponentScan configured for \"dao\" and \"service\" packages")
4444
void componentScanPackagesAreSpecified() {
4545
ComponentScan componentScan = ApplicationConfig.class.getAnnotation(ComponentScan.class);
4646
String[] packages = componentScan.basePackages();

3-0-spring-framework/3-0-0-hello-spring-framework/src/test/java/com/bobocode/ApplicationContextTest.java

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
package com.bobocode;
1+
package com.bobocode;
22

33
import com.bobocode.dao.AccountDao;
44
import com.bobocode.dao.FakeAccountDao;
5-
import com.bobocode.model.Account;
65
import com.bobocode.service.AccountService;
76
import org.junit.jupiter.api.*;
87
import org.springframework.beans.factory.annotation.Autowired;
@@ -11,7 +10,6 @@
1110
import org.springframework.context.annotation.Configuration;
1211
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
1312

14-
import java.util.Comparator;
1513
import java.util.Map;
1614

1715
import static org.assertj.core.api.Assertions.assertThat;
@@ -96,17 +94,4 @@ void accountServiceBeanName() {
9694

9795
assertThat(accountServiceMap.keySet()).contains("accountService");
9896
}
99-
100-
@Test
101-
@Order(8)
102-
@DisplayName("Find the richest account")
103-
void findRichestAccount() {
104-
Account richestAccount = accountService.findRichestAccount();
105-
106-
Account actualRichestAccount = accountDao.findAll().stream()
107-
.max(Comparator.comparing(Account::getBalance))
108-
.orElseThrow();
109-
110-
assertThat(richestAccount).isEqualTo(actualRichestAccount);
111-
}
11297
}

java-web-course-util/spring-framework-exercises-model/pom.xml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,4 @@
1111

1212
<artifactId>spring-framework-exercises-model</artifactId>
1313

14-
<dependencies>
15-
<dependency>
16-
<groupId>org.hibernate.javax.persistence</groupId>
17-
<artifactId>hibernate-jpa-2.1-api</artifactId>
18-
<version>1.0.2.Final</version>
19-
</dependency>
20-
</dependencies>
21-
2214
</project>

java-web-course-util/spring-framework-exercises-model/src/main/java/com/bobocode/model/jpa/Role.java

Lines changed: 0 additions & 56 deletions
This file was deleted.

java-web-course-util/spring-framework-exercises-model/src/main/java/com/bobocode/model/jpa/RoleType.java

Lines changed: 0 additions & 5 deletions
This file was deleted.

java-web-course-util/spring-framework-exercises-model/src/main/java/com/bobocode/model/jpa/User.java

Lines changed: 0 additions & 56 deletions
This file was deleted.

java-web-course-util/spring-framework-exercises-util/src/main/java/com/bobocode/TestDataGenerator.java

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,16 @@
22

33
import com.bobocode.model.Account;
44
import com.bobocode.model.Gender;
5-
import com.bobocode.model.jpa.Role;
6-
import com.bobocode.model.jpa.RoleType;
7-
import com.bobocode.model.jpa.User;
85
import io.codearte.jfairy.Fairy;
96
import io.codearte.jfairy.producer.person.Person;
107

118
import java.math.BigDecimal;
129
import java.time.LocalDate;
1310
import java.time.LocalDateTime;
1411
import java.util.Random;
15-
import java.util.Set;
16-
import java.util.function.Predicate;
17-
import java.util.stream.Collectors;
18-
import java.util.stream.Stream;
19-
20-
import static java.util.stream.Collectors.toSet;
2112

2213
public class TestDataGenerator {
23-
public Account generateAccount(){
14+
public Account generateAccount() {
2415
Fairy fairy = Fairy.create();
2516
Person person = fairy.person();
2617
Random random = new Random();
@@ -39,43 +30,4 @@ public Account generateAccount(){
3930

4031
return fakeAccount;
4132
}
42-
43-
public User generateUser() {
44-
User user = generateUserOnly();
45-
user.addRoles(generateRoleSet());
46-
return user;
47-
}
48-
49-
public User generateUser(RoleType... roleTypes) {
50-
Set<Role> roles = Stream.of(roleTypes).map(Role::valueOf).collect(Collectors.toSet());
51-
User user = generateUserOnly();
52-
user.addRoles(roles);
53-
return user;
54-
}
55-
56-
private User generateUserOnly() {
57-
Fairy fairy = Fairy.create();
58-
Person person = fairy.person();
59-
60-
User user = new User();
61-
user.setFirstName(person.getFirstName());
62-
user.setLastName(person.getLastName());
63-
user.setEmail(person.getEmail());
64-
user.setBirthday(LocalDate.of(
65-
person.getDateOfBirth().getYear(),
66-
person.getDateOfBirth().getMonthOfYear(),
67-
person.getDateOfBirth().getDayOfMonth()));
68-
user.setCreationDate(LocalDate.now());
69-
return user;
70-
}
71-
72-
public static Set<Role> generateRoleSet() {
73-
Random random = new Random();
74-
Predicate<RoleType> randomPredicate = i -> random.nextBoolean();
75-
76-
return Stream.of(RoleType.values())
77-
.filter(randomPredicate)
78-
.map(Role::valueOf)
79-
.collect(toSet());
80-
}
8133
}

0 commit comments

Comments
 (0)