File tree Expand file tree Collapse file tree
main/java/org/baeldung/mockito/repository
test/java/org/baeldung/mockito Expand file tree Collapse file tree Original file line number Diff line number Diff line change 4646 <version >${hamcrest.version} </version >
4747 </dependency >
4848
49+ <dependency >
50+ <groupId >org.springframework.boot</groupId >
51+ <artifactId >spring-boot-starter</artifactId >
52+ <version >LATEST</version >
53+ <scope >test</scope >
54+ </dependency >
55+ <dependency >
56+ <groupId >org.springframework.boot</groupId >
57+ <artifactId >spring-boot-starter-test</artifactId >
58+ <version >LATEST</version >
59+ <scope >test</scope >
60+ </dependency >
61+ <dependency >
62+ <groupId >org.springframework</groupId >
63+ <artifactId >spring-core</artifactId >
64+ <version >LATEST</version >
65+ </dependency >
66+ <dependency >
67+ <groupId >org.springframework</groupId >
68+ <artifactId >spring-context</artifactId >
69+ <version >LATEST</version >
70+ </dependency >
71+ <dependency >
72+ <groupId >org.eclipse.persistence</groupId >
73+ <artifactId >javax.persistence</artifactId >
74+ <version >2.1.1</version >
75+ </dependency >
76+ <dependency >
77+ <groupId >org.springframework.data</groupId >
78+ <artifactId >spring-data-jpa</artifactId >
79+ <version >LATEST</version >
80+ </dependency >
4981 </dependencies >
5082
5183 <build >
6799 <!-- testing -->
68100 <powermock .version>1.7.0</powermock .version>
69101 <hamcrest .version>2.0.0.0</hamcrest .version>
70-
71102 </properties >
72103
73104</project >
Original file line number Diff line number Diff line change 1+ package org .baeldung .mockito .repository ;
2+
3+ import javax .persistence .Entity ;
4+ import javax .persistence .GeneratedValue ;
5+ import javax .persistence .Id ;
6+ import javax .persistence .Table ;
7+
8+ @ Entity
9+ @ Table (name = "users" )
10+ public class User {
11+
12+ @ Id
13+ @ GeneratedValue
14+ private Integer id ;
15+ private String name ;
16+ private Integer status ;
17+
18+ public User () {
19+ }
20+
21+ public User (String name , Integer status ) {
22+ this .name = name ;
23+ this .status = status ;
24+ }
25+
26+ public Integer getId () {
27+ return id ;
28+ }
29+
30+ public void setId (Integer id ) {
31+ this .id = id ;
32+ }
33+
34+ public String getName () {
35+ return name ;
36+ }
37+
38+ public void setName (String name ) {
39+ this .name = name ;
40+ }
41+
42+ public Integer getStatus () {
43+ return status ;
44+ }
45+
46+ public void setStatus (Integer status ) {
47+ this .status = status ;
48+ }
49+ }
Original file line number Diff line number Diff line change 1+ package org .baeldung .mockito .repository ;
2+
3+ import org .springframework .data .jpa .repository .JpaRepository ;
4+ import org .springframework .stereotype .Repository ;
5+
6+ @ Repository ("userRepository" )
7+ public interface UserRepository extends JpaRepository <User , Integer > {
8+
9+ }
Original file line number Diff line number Diff line change 1- package org .baeldung ;
1+ package org .baeldung . mockito ;
22
3- import org .baeldung .repository .UserRepository ;
3+ import org .baeldung .mockito . repository .UserRepository ;
44import org .junit .Assert ;
55import org .junit .Test ;
66import org .junit .runner .RunWith ;
@@ -28,6 +28,6 @@ public void testMockitoMockMethod() {
2828 Mockito .when (localMockRepository .count ()).thenReturn (111L );
2929 long userCount = localMockRepository .count ();
3030 Assert .assertEquals (111L , userCount );
31- Mockito .verify (localMockRepository ).count ();
31+ Mockito .verify (localMockRepository ).count ();
3232 }
3333}
Original file line number Diff line number Diff line change 1- package org .baeldung ;
1+ package org .baeldung . mockito ;
22
3- import org .baeldung .repository .UserRepository ;
3+ import org .baeldung .mockito . repository .UserRepository ;
44import org .junit .Assert ;
55import org .junit .Test ;
66import org .junit .runner .RunWith ;
1010import org .springframework .context .ApplicationContext ;
1111import org .springframework .test .context .junit4 .SpringRunner ;
1212
13-
1413@ RunWith (SpringRunner .class )
1514public class MockBeanAnnotationIntegrationTest {
1615
You can’t perform that action at this time.
0 commit comments