1818import org .apache .http .impl .client .CloseableHttpClient ;
1919import org .apache .http .message .BasicHeader ;
2020import org .apache .http .message .BasicStatusLine ;
21- import org .junit .Assert ;
22- import org .junit .BeforeClass ;
23- import org .junit .Rule ;
24- import org .junit .Test ;
25- import org .mockito .junit .MockitoJUnit ;
26- import org .mockito .junit .MockitoRule ;
27- import org .mockito .quality .Strictness ;
21+ import org .junit .jupiter .api .BeforeAll ;
22+ import org .junit .jupiter .api .Test ;
2823
2924import java .io .IOException ;
3025
26+ import static org .junit .jupiter .api .Assertions .assertEquals ;
27+ import static org .junit .jupiter .api .Assertions .assertThrows ;
28+ import static org .junit .jupiter .api .Assertions .fail ;
3129import static org .mockito .ArgumentMatchers .any ;
3230import static org .mockito .Mockito .mock ;
3331import static org .mockito .Mockito .when ;
3432
3533public class BaseResourceTest
3634{
37- @ Rule
38- public MockitoRule rule = MockitoJUnit .rule ().strictness (Strictness .STRICT_STUBS );
39-
4035 private static BaseResource baseResource ;
4136 private static SonosApiClient client ;
4237 private static SonosApiConfiguration configuration ;
4338 private static CloseableHttpClient mockedClient ;
4439
45- @ BeforeClass
40+ @ BeforeAll
4641 public static void setUp () throws Exception
4742 {
4843 client = mock (SonosApiClient .class );
@@ -56,18 +51,18 @@ public static void setUp() throws Exception
5651 }
5752
5853 @ Test
59- public void getTypeFromHeader () throws SonosApiClientException
54+ void getTypeFromHeader () throws SonosApiClientException
6055 {
6156 final CloseableHttpResponse response = mock (CloseableHttpResponse .class );
6257 when (response .getFirstHeader (BaseResource .SONOS_TYPE_HEADER ))
6358 .thenReturn (new BasicHeader (BaseResource .SONOS_TYPE_HEADER , "homeTheaterOptions" ));
6459 final SonosType type = baseResource .getTypeFromHeader (response );
6560
66- Assert . assertEquals (SonosType .homeTheaterOptions , type );
61+ assertEquals (SonosType .homeTheaterOptions , type );
6762 }
6863
6964 @ Test
70- public void getInvalidTypeFromHeader () throws SonosApiClientException
65+ void getInvalidTypeFromHeader () throws SonosApiClientException
7166 {
7267 final CloseableHttpResponse response = mock (CloseableHttpResponse .class );
7368 when (response .getFirstHeader (BaseResource .SONOS_TYPE_HEADER ))
@@ -76,16 +71,16 @@ public void getInvalidTypeFromHeader() throws SonosApiClientException
7671 try
7772 {
7873 baseResource .getTypeFromHeader (response );
79- Assert . fail ("Did not fail as expected" );
74+ fail ("Did not fail as expected" );
8075 }
8176 catch (SonosApiClientException sace )
8277 {
83- Assert . assertEquals (IllegalArgumentException .class , sace .getCause ().getClass ());
78+ assertEquals (IllegalArgumentException .class , sace .getCause ().getClass ());
8479 }
8580 }
8681
8782 @ Test
88- public void testThatMainApiCallWorks () throws IOException , SonosApiClientException , SonosApiError
83+ void testThatMainApiCallWorks () throws IOException , SonosApiClientException , SonosApiError
8984 {
9085 // Test data
9186 final SonosHomeTheaterOptions options = new SonosHomeTheaterOptions ();
@@ -104,11 +99,11 @@ public void testThatMainApiCallWorks() throws IOException, SonosApiClientExcepti
10499 final SonosHomeTheaterOptions responseOptions = baseResource .getFromApi (SonosHomeTheaterOptions .class ,
105100 "token123" , "some/test" );
106101
107- Assert . assertEquals (options , responseOptions );
102+ assertEquals (options , responseOptions );
108103 }
109104
110105 @ Test
111- public void testSonosNotDeclaringTypeStillWorks () throws IOException , SonosApiClientException , SonosApiError
106+ void testSonosNotDeclaringTypeStillWorks () throws IOException , SonosApiClientException , SonosApiError
112107 {
113108 // Test data
114109 final SonosHomeTheaterOptions options = new SonosHomeTheaterOptions ();
@@ -129,11 +124,11 @@ public void testSonosNotDeclaringTypeStillWorks() throws IOException, SonosApiCl
129124 final SonosHomeTheaterOptions responseOptions = baseResource .getFromApi (SonosHomeTheaterOptions .class ,
130125 "token123" , "some/test" );
131126
132- Assert . assertEquals (options , responseOptions );
127+ assertEquals (options , responseOptions );
133128 }
134129
135130 @ Test
136- public void testAuthErrorThrown () throws IOException , SonosApiClientException , SonosApiError
131+ void testAuthErrorThrown () throws IOException , SonosApiClientException , SonosApiError
137132 {
138133 final CloseableHttpResponse mockedResponse = mock (CloseableHttpResponse .class );
139134 final StatusLine sl = new BasicStatusLine (new ProtocolVersion ("HTTP" , 1 , 1 ), 401 , null );
@@ -142,16 +137,16 @@ public void testAuthErrorThrown() throws IOException, SonosApiClientException, S
142137 try
143138 {
144139 baseResource .getFromApi (SonosHomeTheaterOptions .class , "token123" , "some/test" );
145- Assert . fail ("Did not handle error response correctly" );
140+ fail ("Did not handle error response correctly" );
146141 }
147142 catch (final SonosApiClientException e )
148143 {
149- Assert . assertEquals ("Invalid token" , e .getMessage ());
144+ assertEquals ("Invalid token" , e .getMessage ());
150145 }
151146 }
152147
153148 @ Test
154- public void testApiErrorHandledCorrectly () throws IOException , SonosApiClientException , SonosApiError
149+ void testApiErrorHandledCorrectly () throws IOException , SonosApiClientException , SonosApiError
155150 {
156151 // Test data
157152 final SonosApiError error = new SonosApiError ();
@@ -171,16 +166,16 @@ public void testApiErrorHandledCorrectly() throws IOException, SonosApiClientExc
171166 try
172167 {
173168 baseResource .getFromApi (SonosHomeTheaterOptions .class , "token123" , "some/test" );
174- Assert . fail ("Did not handle error response correctly" );
169+ fail ("Did not handle error response correctly" );
175170 }
176171 catch (final SonosApiError e )
177172 {
178- Assert . assertEquals (SonosErrorCode .ERROR_NOT_CAPABLE , e .getErrorCode ());
173+ assertEquals (SonosErrorCode .ERROR_NOT_CAPABLE , e .getErrorCode ());
179174 }
180175 }
181176
182177 @ Test
183- public void testApiMismatchHandledCorrectly () throws IOException , SonosApiClientException , SonosApiError
178+ void testApiMismatchHandledCorrectly () throws IOException , SonosApiClientException , SonosApiError
184179 {
185180 // Test data
186181 final SonosHomeTheaterOptions options = new SonosHomeTheaterOptions ();
@@ -201,55 +196,55 @@ public void testApiMismatchHandledCorrectly() throws IOException, SonosApiClient
201196 try
202197 {
203198 baseResource .getFromApi (SonosHomeTheaterOptions .class , "token123" , "some/test" );
204- Assert . fail ("Did not handle error response correctly" );
199+ fail ("Did not handle error response correctly" );
205200 }
206201 catch (final SonosApiClientException e )
207202 {
208- Assert . assertEquals ("Sonos declared SonosAudioClip as the response type, but the integration requested SonosHomeTheaterOptions" , e .getMessage ());
203+ assertEquals ("Sonos declared SonosAudioClip as the response type, but the integration requested SonosHomeTheaterOptions" , e .getMessage ());
209204 }
210205 }
211206
212207 @ Test
213- public void getStandardRequest () throws SonosApiClientException
208+ void getStandardRequest () throws SonosApiClientException
214209 {
215210 final HttpGet req = baseResource .getStandardRequest (HttpGet .class , "token123" , "/some/path" );
216- Assert . assertEquals (HttpGet .METHOD_NAME ,
211+ assertEquals (HttpGet .METHOD_NAME ,
217212 req .getMethod ());
218213
219- Assert . assertEquals ("Bearer token123" ,
214+ assertEquals ("Bearer token123" ,
220215 req .getFirstHeader ("Authorization" ).getValue ());
221216
222- Assert . assertEquals (
217+ assertEquals (
223218 "/control/api/some/path" ,
224219 req .getURI ().getPath ());
225220 }
226221
227222 @ Test
228- public void testValidateNotNullNoFieldName () throws SonosApiClientException
223+ void testValidateNotNullNoFieldName () throws SonosApiClientException
229224 {
230225 baseResource .validateNotNull ("nonEmptyString" );
231226 }
232227
233- @ Test ( expected = SonosApiClientException . class )
234- public void testValidateNotNullBothNulls () throws SonosApiClientException
228+ @ Test
229+ void testValidateNotNullBothNulls ()
235230 {
236- baseResource .validateNotNull (null , null );
231+ assertThrows ( SonosApiClientException . class , () -> baseResource .validateNotNull (null , null ) );
237232 }
238233
239- @ Test ( expected = SonosApiClientException . class )
240- public void testValidateNotNullObjectNull () throws SonosApiClientException
234+ @ Test
235+ void testValidateNotNullObjectNull ()
241236 {
242- baseResource .validateNotNull (null , "sonos-api-java" );
237+ assertThrows ( SonosApiClientException . class , () -> baseResource .validateNotNull (null , "sonos-api-java" ) );
243238 }
244239
245- @ Test ( expected = SonosApiClientException . class )
246- public void testValidateNotNullEmptyObject () throws SonosApiClientException
240+ @ Test
241+ void testValidateNotNullEmptyObject ()
247242 {
248- baseResource .validateNotNull ("" , "sonos-api-java" );
243+ assertThrows ( SonosApiClientException . class , () -> baseResource .validateNotNull ("" , "sonos-api-java" ) );
249244 }
250245
251246 @ Test
252- public void testValidateNotNullNonEmptyObject () throws SonosApiClientException
247+ void testValidateNotNullNonEmptyObject () throws SonosApiClientException
253248 {
254249 baseResource .validateNotNull ("nonEmptyString" , "sonos-api-java" );
255250 }
0 commit comments