2020import org .junit .runner .RunWith ;
2121import org .mockito .Mockito ;
2222import org .powermock .api .mockito .PowerMockito ;
23+ import static org .powermock .api .mockito .PowerMockito .*;
2324import org .powermock .core .classloader .annotations .PrepareForTest ;
2425import org .powermock .modules .junit4 .PowerMockRunner ;
2526
@@ -39,29 +40,32 @@ public class AppIdentityServiceTest {
3940
4041 /**
4142 * testGetAppIdentity
42- * @throws Exception
43+ * @throws Exception
4344 */
4445 @ Test
45- public void testGetAppIdentity () throws Exception {
46+ public void testGetAppIdentity () throws Exception {
4647
47- EnvironmentDetail envDetail = EnvironmentDetail .newBuilder ().deviceName ("device" ).appName ("app" ).build ();
48+ final EnvironmentDetail envDetail =
49+ EnvironmentDetail .newBuilder ().deviceName ("device" ).appName ("app" ).build ();
4850
49- AppIdentity appIdentity = AppIdentity .newBuilder ().deviceId (Integer .valueOf (123 )).appNameId ("456" ).build ();
51+ final AppIdentity appIdentity =
52+ AppIdentity .newBuilder ().deviceId (123 ).appNameId ("456" ).appName ("app" ).build ();
53+
54+ final ObjectMapper objectMapper = new ObjectMapper ();
5055
51- ObjectMapper objectMapper = new ObjectMapper ();
52-
5356 String appIdentityResponse = objectMapper .writer ().writeValueAsString (appIdentity );
54-
55- HttpClient httpClient = PowerMockito .mock (HttpClient .class );
56- PowerMockito .whenNew (HttpClient .class ).withAnyArguments ().thenReturn (httpClient );
57- PowerMockito .when (httpClient .post (Mockito .anyString (), (byte []) Mockito .any ())).thenReturn (appIdentityResponse );
58-
59- ApiConfiguration apiConfig = ApiConfiguration .newBuilder ().apiUrl ("url" ).apiKey ("key" ).envDetail (envDetail ).build ();
60-
57+
58+ final HttpClient httpClient = mock (HttpClient .class );
59+ whenNew (HttpClient .class ).withAnyArguments ().thenReturn (httpClient );
60+ when (httpClient .post (Mockito .anyString (), (byte []) Mockito .any ())).thenReturn (appIdentityResponse );
61+
62+ ApiConfiguration apiConfig =
63+ ApiConfiguration .newBuilder ().apiUrl ("url" ).apiKey ("key" ).application ("app" ).envDetail (envDetail ).build ();
64+
6165 AppIdentityService service = new AppIdentityService (apiConfig , objectMapper );
6266
6367 Optional <AppIdentity > rv = service .getAppIdentity ();
64-
68+
6569 Assert .assertNotNull (rv );
6670 Assert .assertTrue (rv .isPresent ());
6771 Assert .assertEquals (Integer .valueOf (123 ), rv .get ().getDeviceId ());
0 commit comments