File tree Expand file tree Collapse file tree
main/java/org/baeldung/boot
test/java/org/baeldung/boot Expand file tree Collapse file tree Original file line number Diff line number Diff line change 66@ SpringBootApplication
77public class DemoApplication {
88
9- public static void main (String [] args ) {
10- System .setProperty ("spring.config.name" , "demo" );
11- SpringApplication .run (DemoApplication .class , args );
12- }
9+ public static void main (String [] args ) {
10+ System .setProperty ("spring.config.name" , "demo" );
11+ SpringApplication .run (DemoApplication .class , args );
12+ }
13+
1314}
Original file line number Diff line number Diff line change 88
99@ Entity
1010public class Foo implements Serializable {
11- private static final long serialVersionUID = 1L ;
12- @ Id
13- @ GeneratedValue
14- private Integer id ;
15- private String name ;
16-
17- public Foo () {
18- }
19-
20- public Foo (String name ) {
21- this .name = name ;
22- }
23-
24- public Integer getId () {
25- return id ;
26- }
27-
28- public void setId (Integer id ) {
29- this .id = id ;
30- }
31-
32- public String getName () {
33- return name ;
34- }
35-
36- public void setName (String name ) {
37- this .name = name ;
38- }
39-
11+ private static final long serialVersionUID = 1L ;
12+ @ Id
13+ @ GeneratedValue
14+ private Integer id ;
15+ private String name ;
16+
17+ public Foo () {
18+ }
19+
20+ public Foo (String name ) {
21+ this .name = name ;
22+ }
23+
24+ public Integer getId () {
25+ return id ;
26+ }
27+
28+ public void setId (Integer id ) {
29+ this .id = id ;
30+ }
31+
32+ public String getName () {
33+ return name ;
34+ }
35+
36+ public void setName (String name ) {
37+ this .name = name ;
38+ }
4039}
Original file line number Diff line number Diff line change 44import org .springframework .data .jpa .repository .JpaRepository ;
55
66public interface FooRepository extends JpaRepository <Foo , Integer > {
7- public Foo findByName (String name );
7+ public Foo findByName (String name );
88}
Original file line number Diff line number Diff line change 1111@ WebAppConfiguration
1212public class DemoApplicationTests {
1313
14- @ Test
15- public void contextLoads () {
16- }
17-
14+ @ Test
15+ public void contextLoads () {
16+ }
1817}
Original file line number Diff line number Diff line change 1515
1616@ Transactional
1717public class FooRepositoryTest extends DemoApplicationTests {
18- @ Autowired
19- private FooRepository fooRepository ;
20-
21- @ Before
22- public void setUp () {
23- fooRepository .save (new Foo ("Foo" ));
24- fooRepository .save (new Foo ("Bar" ));
25- }
26-
27- @ Test
28- public void testFindByName () {
29- Foo foo = fooRepository .findByName ("Bar" );
30- assertThat (foo , notNullValue ());
31- assertThat (foo .getId (), is (2 ));
32- }
18+ @ Autowired
19+ private FooRepository fooRepository ;
20+
21+ @ Before
22+ public void setUp () {
23+ fooRepository .save (new Foo ("Foo" ));
24+ fooRepository .save (new Foo ("Bar" ));
25+ }
26+
27+ @ Test
28+ public void testFindByName () {
29+ Foo foo = fooRepository .findByName ("Bar" );
30+ assertThat (foo , notNullValue ());
31+ assertThat (foo .getId (), is (2 ));
32+ }
33+
3334}
You can’t perform that action at this time.
0 commit comments