17
17
18
18
import static org .assertj .core .api .Assertions .assertThat ;
19
19
import static org .assertj .core .api .Assertions .assertThatThrownBy ;
20
+ import static org .mockito .ArgumentMatchers .any ;
20
21
import static org .mockito .ArgumentMatchers .anyLong ;
21
22
import static org .mockito .Mockito .doAnswer ;
22
23
import static org .mockito .Mockito .mock ;
24
+ import static org .mockito .Mockito .when ;
23
25
26
+ import java .io .IOException ;
27
+ import java .io .UncheckedIOException ;
24
28
import java .nio .ByteBuffer ;
25
29
import java .util .ArrayList ;
26
30
import java .util .List ;
41
45
import org .mockito .stubbing .Answer ;
42
46
import org .reactivestreams .Subscriber ;
43
47
import org .reactivestreams .Subscription ;
48
+ import software .amazon .awssdk .utils .FunctionalUtils ;
44
49
import software .amazon .awssdk .utils .ThreadFactoryBuilder ;
45
50
46
51
public class InputStreamSubscriberTest {
@@ -54,7 +59,7 @@ public void setup() {
54
59
}
55
60
56
61
@ Test
57
- public void onComplete_returnsEndOfStream_onRead () {
62
+ public void onComplete_returnsEndOfStream_onRead () throws IOException {
58
63
publisher .subscribe (subscriber );
59
64
publisher .complete ();
60
65
assertThat (subscriber .read ()).isEqualTo (-1 );
@@ -74,7 +79,7 @@ public void onError_throws_onRead() {
74
79
}
75
80
76
81
@ Test
77
- public void onComplete_afterOnNext_returnsEndOfStream () {
82
+ public void onComplete_afterOnNext_returnsEndOfStream () throws IOException {
78
83
publisher .subscribe (subscriber );
79
84
publisher .send (byteBufferOfLength (1 ));
80
85
publisher .complete ();
@@ -83,7 +88,7 @@ public void onComplete_afterOnNext_returnsEndOfStream() {
83
88
}
84
89
85
90
@ Test
86
- public void onComplete_afterEmptyOnNext_returnsEndOfStream () {
91
+ public void onComplete_afterEmptyOnNext_returnsEndOfStream () throws IOException {
87
92
publisher .subscribe (subscriber );
88
93
publisher .send (byteBufferOfLength (0 ));
89
94
publisher .send (byteBufferOfLength (0 ));
@@ -93,14 +98,14 @@ public void onComplete_afterEmptyOnNext_returnsEndOfStream() {
93
98
}
94
99
95
100
@ Test
96
- public void read_afterOnNext_returnsData () {
101
+ public void read_afterOnNext_returnsData () throws IOException {
97
102
publisher .subscribe (subscriber );
98
103
publisher .send (byteBufferWithByte (10 ));
99
104
assertThat (subscriber .read ()).isEqualTo (10 );
100
105
}
101
106
102
107
@ Test
103
- public void readBytes_afterOnNext_returnsData () {
108
+ public void readBytes_afterOnNext_returnsData () throws IOException {
104
109
publisher .subscribe (subscriber );
105
110
publisher .send (byteBufferWithByte (10 ));
106
111
publisher .send (byteBufferWithByte (20 ));
@@ -112,7 +117,7 @@ public void readBytes_afterOnNext_returnsData() {
112
117
}
113
118
114
119
@ Test
115
- public void readBytesWithOffset_afterOnNext_returnsData () {
120
+ public void readBytesWithOffset_afterOnNext_returnsData () throws IOException {
116
121
publisher .subscribe (subscriber );
117
122
publisher .send (byteBufferWithByte (10 ));
118
123
publisher .send (byteBufferWithByte (20 ));
@@ -133,7 +138,7 @@ public void read_afterClose_fails() {
133
138
}
134
139
135
140
@ Test
136
- public void readByteArray_0Len_returns0 () {
141
+ public void readByteArray_0Len_returns0 () throws IOException {
137
142
publisher .subscribe (subscriber );
138
143
139
144
assertThat (subscriber .read (new byte [1 ], 0 , 0 )).isEqualTo (0 );
@@ -211,6 +216,18 @@ public void stochastic_methodCallsSeemThreadSafe(Consumer<InputStreamSubscriber>
211
216
}
212
217
}
213
218
219
+ @ Test
220
+ public void read_uncheckedIOException_isThrownAsIOException () {
221
+ ByteBufferStoringSubscriber byteBufferStoringSubscriber = mock (ByteBufferStoringSubscriber .class );
222
+ when (byteBufferStoringSubscriber .blockingTransferTo (any ()))
223
+ .thenThrow (new UncheckedIOException (new IOException ("Not wrapped as UncheckedIOException" )));
224
+ InputStreamSubscriber errorSubscriber = new InputStreamSubscriber (byteBufferStoringSubscriber );
225
+
226
+ assertThatThrownBy (() -> errorSubscriber .read (new byte [1 ]))
227
+ .isInstanceOf (IOException .class ).hasMessage ("Not wrapped as UncheckedIOException" );
228
+
229
+ }
230
+
214
231
public static Consumer <InputStreamSubscriber > subscriberOnNext () {
215
232
return s -> s .onNext (ByteBuffer .allocate (1 ));
216
233
}
@@ -224,11 +241,11 @@ public static Consumer<InputStreamSubscriber> subscriberOnError() {
224
241
}
225
242
226
243
public static Consumer <InputStreamSubscriber > subscriberRead1 () {
227
- return s -> s .read ();
244
+ return s -> FunctionalUtils . invokeSafely (() -> s .read () );
228
245
}
229
246
230
247
public static Consumer <InputStreamSubscriber > subscriberReadArray () {
231
- return s -> s .read (new byte [4 ]);
248
+ return s -> FunctionalUtils . invokeSafely (() -> s .read (new byte [4 ]) );
232
249
}
233
250
234
251
public static Consumer <InputStreamSubscriber > subscriberClose () {
0 commit comments