17
17
package functions ;
18
18
19
19
import static com .google .common .truth .Truth .assertThat ;
20
+ import static org .mockito .Mockito .mock ;
21
+ import static org .mockito .Mockito .when ;
20
22
21
23
import com .google .cloud .functions .HttpRequest ;
22
24
import com .google .cloud .functions .HttpResponse ;
38
40
import org .junit .runner .RunWith ;
39
41
import org .junit .runners .JUnit4 ;
40
42
import org .mockito .Mock ;
41
- import org .mockito .Mockito ;
42
- import org .powermock .api .mockito .PowerMockito ;
43
+ import org .mockito .MockitoAnnotations ;
43
44
44
45
@ RunWith (JUnit4 .class )
45
46
public class HelloSpannerTest {
@@ -69,31 +70,25 @@ public static void restoreLogging() {
69
70
70
71
@ Before
71
72
public void beforeTest () throws IOException {
72
- Mockito .mockitoSession ().initMocks (this );
73
-
74
- request = PowerMockito .mock (HttpRequest .class );
75
- response = PowerMockito .mock (HttpResponse .class );
76
- client = PowerMockito .mock (DatabaseClient .class );
73
+ MockitoAnnotations .initMocks (this );
77
74
78
75
responseOut = new StringWriter ();
79
76
writerOut = new BufferedWriter (responseOut );
80
- PowerMockito . when (response .getWriter ()).thenReturn (writerOut );
77
+ when (response .getWriter ()).thenReturn (writerOut );
81
78
82
79
logHandler .clear ();
83
80
}
84
81
85
82
private void setupSuccessfulMockQuery () {
86
- ReadContext readContext = PowerMockito .mock (ReadContext .class );
87
- ResultSet resultSet = PowerMockito .mock (ResultSet .class );
88
- PowerMockito .when (resultSet .next ()).thenReturn (true , true , false );
89
- PowerMockito .when (resultSet .getLong ("SingerId" )).thenReturn (1L , 2L , 0L );
90
- PowerMockito .when (resultSet .getLong ("AlbumId" )).thenReturn (1L , 1L , 0L );
91
- PowerMockito .when (resultSet .getString ("AlbumTitle" )).thenReturn ("Album 1" , "Album 2" , null );
92
- PowerMockito .when (
93
- readContext .executeQuery (
94
- Statement .of ("SELECT SingerId, AlbumId, AlbumTitle FROM Albums" )))
83
+ ReadContext readContext = mock (ReadContext .class );
84
+ ResultSet resultSet = mock (ResultSet .class );
85
+ when (resultSet .next ()).thenReturn (true , true , false );
86
+ when (resultSet .getLong ("SingerId" )).thenReturn (1L , 2L , 0L );
87
+ when (resultSet .getLong ("AlbumId" )).thenReturn (1L , 1L , 0L );
88
+ when (resultSet .getString ("AlbumTitle" )).thenReturn ("Album 1" , "Album 2" , null );
89
+ when (readContext .executeQuery (Statement .of ("SELECT SingerId, AlbumId, AlbumTitle FROM Albums" )))
95
90
.thenReturn (resultSet );
96
- PowerMockito . when (client .singleUse ()).thenReturn (readContext );
91
+ when (client .singleUse ()).thenReturn (readContext );
97
92
}
98
93
99
94
@ Test
@@ -110,14 +105,12 @@ DatabaseClient getClient() {
110
105
}
111
106
112
107
private void setupFailedMockQuery () {
113
- ReadContext readContext = PowerMockito .mock (ReadContext .class );
114
- PowerMockito .when (
115
- readContext .executeQuery (
116
- Statement .of ("SELECT SingerId, AlbumId, AlbumTitle FROM Albums" )))
108
+ ReadContext readContext = mock (ReadContext .class );
109
+ when (readContext .executeQuery (Statement .of ("SELECT SingerId, AlbumId, AlbumTitle FROM Albums" )))
117
110
.thenThrow (
118
111
SpannerExceptionFactory .newSpannerException (
119
112
ErrorCode .NOT_FOUND , "Table `Albums` not found" ));
120
- PowerMockito . when (client .singleUse ()).thenReturn (readContext );
113
+ when (client .singleUse ()).thenReturn (readContext );
121
114
}
122
115
123
116
@ Test
0 commit comments