File tree 4 files changed +8
-6
lines changed
main/java/guru/springframework
test/java/guru/springframework/repositories
4 files changed +8
-6
lines changed Original file line number Diff line number Diff line change 14
14
<parent >
15
15
<groupId >org.springframework.boot</groupId >
16
16
<artifactId >spring-boot-starter-parent</artifactId >
17
- <version >1.5.3 .RELEASE</version >
17
+ <version >2.0.0 .RELEASE</version >
18
18
<relativePath /> <!-- lookup parent from repository -->
19
19
</parent >
20
20
Original file line number Diff line number Diff line change 2
2
3
3
import guru .springframework .domain .Product ;
4
4
import guru .springframework .repositories .ProductRepository ;
5
- import org .apache .log4j .Logger ;
5
+
6
+ import org .apache .logging .log4j .LogManager ;
7
+ import org .apache .logging .log4j .Logger ;
6
8
import org .springframework .beans .factory .annotation .Autowired ;
7
9
import org .springframework .context .ApplicationListener ;
8
10
import org .springframework .context .event .ContextRefreshedEvent ;
@@ -15,7 +17,7 @@ public class ProductLoader implements ApplicationListener<ContextRefreshedEvent>
15
17
16
18
private ProductRepository productRepository ;
17
19
18
- private Logger log = Logger .getLogger (ProductLoader .class );
20
+ private Logger log = LogManager .getLogger (ProductLoader .class );
19
21
20
22
@ Autowired
21
23
public void setProductRepository (ProductRepository productRepository ) {
Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ public Iterable<Product> listAllProducts() {
21
21
22
22
@ Override
23
23
public Product getProductById (Integer id ) {
24
- return productRepository .findOne (id );
24
+ return productRepository .findById (id ). orElse ( null );
25
25
}
26
26
27
27
@ Override
Original file line number Diff line number Diff line change @@ -36,7 +36,7 @@ public void testSaveProduct(){
36
36
productRepository .save (product );
37
37
assertNotNull (product .getId ()); //not null after save
38
38
//fetch from DB
39
- Product fetchedProduct = productRepository .findOne (product .getId ());
39
+ Product fetchedProduct = productRepository .findById (product .getId ()). orElse ( null );
40
40
41
41
//should not be null
42
42
assertNotNull (fetchedProduct );
@@ -50,7 +50,7 @@ public void testSaveProduct(){
50
50
productRepository .save (fetchedProduct );
51
51
52
52
//get from DB, should be updated
53
- Product fetchedUpdatedProduct = productRepository .findOne (fetchedProduct .getId ());
53
+ Product fetchedUpdatedProduct = productRepository .findById (fetchedProduct .getId ()). orElse ( null );
54
54
assertEquals (fetchedProduct .getDescription (), fetchedUpdatedProduct .getDescription ());
55
55
56
56
//verify count of products in DB
You can’t perform that action at this time.
0 commit comments