1
1
package software .amazon .payloadoffloading ;
2
2
3
- import junitparams .JUnitParamsRunner ;
4
- import org .hamcrest .Matchers ;
5
- import org .junit .Before ;
6
- import org .junit .Rule ;
7
- import org .junit .Test ;
8
- import org .junit .rules .ExpectedException ;
9
- import org .junit .runner .RunWith ;
3
+ import org .junit .jupiter .api .BeforeEach ;
4
+ import org .junit .jupiter .api .Test ;
10
5
import org .mockito .ArgumentCaptor ;
11
6
import software .amazon .awssdk .core .exception .SdkClientException ;
12
7
import software .amazon .awssdk .core .exception .SdkException ;
13
8
import software .amazon .awssdk .services .s3 .model .ObjectCannedACL ;
14
9
15
- import static org .junit .Assert .*;
10
+ import static org .junit .jupiter .api .Assertions .assertEquals ;
11
+ import static org .junit .jupiter .api .Assertions .assertNotEquals ;
12
+ import static org .junit .jupiter .api .Assertions .assertThrows ;
16
13
import static org .mockito .ArgumentMatchers .any ;
17
- import static org .mockito .Mockito .*;
14
+ import static org .mockito .Mockito .doThrow ;
15
+ import static org .mockito .Mockito .eq ;
16
+ import static org .mockito .Mockito .mock ;
17
+ import static org .mockito .Mockito .times ;
18
+ import static org .mockito .Mockito .verify ;
19
+ import static org .mockito .Mockito .verifyNoInteractions ;
20
+ import static org .mockito .Mockito .when ;
18
21
19
- @ RunWith (JUnitParamsRunner .class )
20
22
public class S3BackedPayloadStoreTest {
21
23
private static final String S3_BUCKET_NAME = "test-bucket-name" ;
22
24
private static final String ANY_PAYLOAD = "AnyPayload" ;
@@ -25,10 +27,7 @@ public class S3BackedPayloadStoreTest {
25
27
private PayloadStore payloadStore ;
26
28
private S3Dao s3Dao ;
27
29
28
- @ Rule
29
- public final ExpectedException exception = ExpectedException .none ();
30
-
31
- @ Before
30
+ @ BeforeEach
32
31
public void setup () {
33
32
s3Dao = mock (S3Dao .class );
34
33
payloadStore = new S3BackedPayloadStore (s3Dao , S3_BUCKET_NAME );
@@ -84,8 +83,8 @@ public void testStoreOriginalPayloadDoesAlwaysCreateNewObjects() {
84
83
PayloadS3Pointer anyOtherExpectedPayloadPointer = new PayloadS3Pointer (S3_BUCKET_NAME , anyOtherS3Key );
85
84
assertEquals (anyOtherExpectedPayloadPointer .toJson (), anyOtherActualPayloadPointer );
86
85
87
- assertThat (anyS3Key , Matchers . not ( anyOtherS3Key ) );
88
- assertThat (anyActualPayloadPointer , Matchers . not ( anyOtherActualPayloadPointer ) );
86
+ assertNotEquals (anyS3Key , anyOtherS3Key );
87
+ assertNotEquals (anyActualPayloadPointer , anyOtherActualPayloadPointer );
89
88
}
90
89
91
90
@ Test
@@ -97,10 +96,8 @@ public void testStoreOriginalPayloadOnS3Failure() {
97
96
any (String .class ),
98
97
any (String .class ));
99
98
100
- exception .expect (SdkException .class );
101
- exception .expectMessage ("S3 Exception" );
102
99
//Any S3 Dao exception is thrown back as-is to clients
103
- payloadStore .storeOriginalPayload (ANY_PAYLOAD );
100
+ assertThrows ( SdkException . class , () -> payloadStore .storeOriginalPayload (ANY_PAYLOAD ), "S3 Exception" );
104
101
}
105
102
106
103
@ Test
@@ -120,21 +117,21 @@ public void testGetOriginalPayloadOnSuccess() {
120
117
121
118
@ Test
122
119
public void testGetOriginalPayloadIncorrectPointer () {
123
- exception .expect (SdkClientException .class );
124
- exception .expectMessage (INCORRECT_POINTER_EXCEPTION_MSG );
125
120
//Any S3 Dao exception is thrown back as-is to clients
126
- payloadStore .getOriginalPayload ("IncorrectPointer" );
121
+ assertThrows (SdkClientException .class , () -> payloadStore .getOriginalPayload ("IncorrectPointer" ),
122
+ INCORRECT_POINTER_EXCEPTION_MSG );
127
123
verifyNoInteractions (s3Dao );
128
124
}
129
125
130
126
@ Test
131
127
public void testGetOriginalPayloadOnS3Failure () {
132
- when (s3Dao .getTextFromS3 (any (String .class ), any (String .class ))).thenThrow (SdkException .create ("S3 Exception" , new Throwable ()));
133
- exception .expect (SdkException .class );
134
- exception .expectMessage ("S3 Exception" );
135
- //Any S3 Dao exception is thrown back as-is to clients
128
+ when (s3Dao .getTextFromS3 (any (String .class ), any (String .class )))
129
+ .thenThrow (SdkException .create ("S3 Exception" , new Throwable ()));
130
+
136
131
PayloadS3Pointer anyPointer = new PayloadS3Pointer (S3_BUCKET_NAME , ANY_S3_KEY );
137
- payloadStore .getOriginalPayload (anyPointer .toJson ());
132
+ //Any S3 Dao exception is thrown back as-is to clients
133
+ assertThrows (SdkException .class , () -> payloadStore .getOriginalPayload (anyPointer .toJson ()),
134
+ "S3 Exception" );
138
135
}
139
136
140
137
@ Test
@@ -152,9 +149,8 @@ public void testDeleteOriginalPayloadOnSuccess() {
152
149
153
150
@ Test
154
151
public void testDeleteOriginalPayloadIncorrectPointer () {
155
- exception .expect (SdkClientException .class );
156
- exception .expectMessage (INCORRECT_POINTER_EXCEPTION_MSG );
157
- payloadStore .deleteOriginalPayload ("IncorrectPointer" );
152
+ assertThrows (SdkClientException .class , () -> payloadStore .deleteOriginalPayload ("IncorrectPointer" ),
153
+ INCORRECT_POINTER_EXCEPTION_MSG );
158
154
verifyNoInteractions (s3Dao );
159
155
}
160
156
}
0 commit comments