11package com .baeldung .spring_data_tests ;
22
3- import org .junit .Test ;
4- import org .junit .runner .RunWith ;
5-
6- import com .baeldung .spring_data_app .MainApp ;
73import com .baeldung .spring_data .model .Book ;
84import com .baeldung .spring_data .model .JavaBook ;
95import com .baeldung .spring_data .repository .BookRepository ;
106import com .baeldung .spring_data .repository .JavaBookRepository ;
11-
7+ import com .baeldung .spring_data_app .MainApp ;
8+ import javaslang .collection .List ;
9+ import javaslang .collection .Seq ;
10+ import javaslang .control .Option ;
11+ import org .junit .Test ;
12+ import org .junit .runner .RunWith ;
1213import org .springframework .beans .factory .annotation .Autowired ;
1314import org .springframework .boot .test .context .SpringBootTest ;
1415import org .springframework .boot .test .context .SpringBootTest .WebEnvironment ;
1516import org .springframework .test .context .junit4 .SpringRunner ;
1617
17- import javaslang .collection .Seq ;
18- import javaslang .collection .List ;
19- import javaslang .control .Option ;
20-
2118import java .util .ArrayList ;
2219
20+ import static org .assertj .core .api .Assertions .assertThat ;
21+
2322@ RunWith (SpringRunner .class )
2423@ SpringBootTest (classes = MainApp .class ,webEnvironment = WebEnvironment .NONE )
25- public class SpringTests {
24+ public class SpringIntegrationTest {
2625
2726 @ Autowired
28- JavaBookRepository javaRepository ;
27+ private JavaBookRepository javaRepository ;
2928
3029 @ Autowired
31- BookRepository repository ;
30+ private BookRepository repository ;
3231
3332 @ Test
3433 public void should_return_seq (){
@@ -38,7 +37,8 @@ public void should_return_seq(){
3837 testBook .setAuthors (authors );
3938 Book book = repository .save (testBook );
4039 Option <Seq <Book >> books = repository .findByTitleContaining ("Seq Test" );
41- assert (!books .isEmpty ());
40+
41+ assertThat (books ).isNotEmpty ();
4242 }
4343
4444
@@ -50,8 +50,9 @@ public void should_return_option_with_book(){
5050 testBook .setAuthors (authors );
5151 Book book = repository .save (testBook );
5252 Option <Book > retBook = repository .findById (1L );
53- assert (retBook .isDefined () && !retBook .isEmpty ());
54- assert (retBook .get () != null );
53+
54+ assertThat (retBook .isDefined ()).isTrue ();
55+ assertThat (retBook ).isNotEmpty ();
5556 }
5657
5758 @ Test
@@ -64,9 +65,11 @@ public void should_return_list(){
6465 testBook .setAuthors (authors );
6566 JavaBook book = javaRepository .save (testBook );
6667 java .util .List <JavaBook > books = javaRepository .findByTitleContaining ("Seq" );
67- assert (!books .isEmpty ());
68- assert (books .size () == 1 );
69- assert (books .get (0 ).getTitle ().equals ("Javaslang in Spring Data Seq Return" ));
68+ assertThat (books )
69+ .isNotEmpty ()
70+ .hasSize (1 )
71+ .extracting ("title" )
72+ .contains ("Javaslang in Spring Data Seq Return" );
7073 }
7174
7275 @ Test
@@ -79,8 +82,8 @@ public void should_return_book(){
7982 testBook .setAuthors (authors );
8083 JavaBook book = javaRepository .save (testBook );
8184 JavaBook retBook = javaRepository .findById (1L );
82- assert ( retBook != null );
83- assert (retBook .getId () == 1L );
84- assert (retBook .getTitle (). contains ( " Data") );
85+
86+ assertThat (retBook .getId ()). isEqualTo ( 1L );
87+ assertThat (retBook .getTitle ()). isEqualTo ( "Javaslang in Spring Data" );
8588 }
8689}
0 commit comments