Skip to content

Commit 124ec60

Browse files
committed
GP-67 Update tests
1 parent 45a97bb commit 124ec60

File tree

10 files changed

+283
-211
lines changed

10 files changed

+283
-211
lines changed

3-0-spring-framework/3-0-0-hello-spring-framework/pom.xml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,34 @@
1515
<dependency>
1616
<groupId>org.springframework</groupId>
1717
<artifactId>spring-context</artifactId>
18-
<version>5.0.7.RELEASE</version>
18+
<version>5.2.12.RELEASE</version>
1919
</dependency>
2020
<dependency>
2121
<groupId>org.springframework</groupId>
2222
<artifactId>spring-test</artifactId>
23-
<version>5.0.7.RELEASE</version>
23+
<version>5.2.12.RELEASE</version>
24+
</dependency>
25+
<dependency>
26+
<groupId>com.bobocode</groupId>
27+
<artifactId>spring-framework-exercises-util</artifactId>
28+
<version>1.0-SNAPSHOT</version>
2429
</dependency>
2530
<dependency>
2631
<groupId>org.hamcrest</groupId>
2732
<artifactId>hamcrest-all</artifactId>
2833
<version>1.3</version>
2934
<scope>test</scope>
3035
</dependency>
36+
<dependency>
37+
<groupId>org.slf4j</groupId>
38+
<artifactId>slf4j-simple</artifactId>
39+
<version>1.7.24</version>
40+
</dependency>
3141
<dependency>
3242
<groupId>com.bobocode</groupId>
33-
<artifactId>spring-framework-exercises-util</artifactId>
43+
<artifactId>spring-framework-exercises-model</artifactId>
3444
<version>1.0-SNAPSHOT</version>
45+
<scope>compile</scope>
3546
</dependency>
3647
</dependencies>
3748

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

Lines changed: 0 additions & 15 deletions
This file was deleted.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.bobocode.config;
2+
3+
import com.bobocode.TestDataGenerator;
4+
import org.springframework.context.annotation.*;
5+
import org.springframework.stereotype.Component;
6+
7+
/**
8+
* This class specify application context configuration. Basically, it's all about which instances of which classes
9+
* should be created and registered in the context. An instance that is registered in the context is called 'bean'.
10+
*
11+
* To tell the container, which bean should be created, you could either specify packages to scan using @{@link ComponentScan},
12+
* or declare your own beans using @{@link Bean}. When you use @{@link ComponentScan} the container will discover
13+
* specified package and its sub-folders, to find all classes marked @{@link Component}.
14+
*
15+
* If you want to import other configs from Java class or XML file, you could use @{@link Import}
16+
* and @{@link ImportResource} accordingly
17+
* <p>
18+
* todo 1: make this class a Spring configuration class
19+
* todo 2: enable component scanning for dao and service packages
20+
* 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;
22+
* todo 4: Don't specify bean name "dataGenerator" explicitly
23+
*/
24+
25+
public class ApplicationConfig {
26+
27+
}

3-0-spring-framework/3-0-0-hello-spring-framework/src/main/java/com/bobocode/dao/FakeAccountDao.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,21 @@
33
import com.bobocode.TestDataGenerator;
44
import com.bobocode.model.Account;
55
import org.springframework.beans.factory.annotation.Autowired;
6+
import org.springframework.stereotype.Component;
67

78
import java.util.List;
89
import java.util.stream.Stream;
910

1011
import static java.util.stream.Collectors.toList;
1112

1213
/**
13-
* Provides a fake {@link AccountDao} implementation that uses generated fake data.
14+
* This class should be marked with @{@link Component}, thus Spring container will create an instance
15+
* of {@link FakeAccountDao} class, and will register it the context.
1416
* <p>
1517
* todo: configure this class as Spring component with bean name "accountDao"
16-
* todo: use explicit (with {@link Autowired} annotation) constructor-based dependency injection
18+
* todo: use explicit (with {@link Autowired} annotation) constructor-based dependency injection for specific bean
1719
*/
20+
1821
public class FakeAccountDao implements AccountDao {
1922
private List<Account> accounts;
2023

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
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;
58

69
import java.util.Comparator;
710
import java.util.List;
@@ -12,6 +15,7 @@
1215
* todo: configure {@link AccountService} bean implicitly using special annotation for service classes
1316
* todo: use implicit constructor-based dependency injection (don't use {@link org.springframework.beans.factory.annotation.Autowired})
1417
*/
18+
1519
public class AccountService {
1620
private final AccountDao accountDao;
1721

@@ -25,5 +29,4 @@ public Account findRichestAccount() {
2529
.max(Comparator.comparing(Account::getBalance))
2630
.get();
2731
}
28-
2932
}

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

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

0 commit comments

Comments
 (0)