urbanairship-core/src/test/java/com/urbanairship/push/NamedUserJobHandlerTest.java
@Test
    public void testAssociateNamedUserSucceed() {
        when(pushManager.getChannelId()).thenReturn("channelID");
        when(namedUser.getId()).thenReturn("namedUserID");

        for (int statusCode = 200; statusCode < 300; statusCode++) {
            // Set a new change token to force an update
            changeToken = UUID.randomUUID().toString();

            // Set up a 2xx response
            Response response = Mockito.mock(Response.class);
            when(namedUserClient.associate("namedUserID", "channelID")).thenReturn(response);
            when(response.getStatus()).thenReturn(statusCode);

            // Perform the update
            JobInfo jobInfo = JobInfo.newBuilder().setAction(NamedUserJobHandler.ACTION_UPDATE_NAMED_USER).build();
            Assert.assertEquals(JobInfo.JOB_FINISHED, jobHandler.performJob(jobInfo));

            // Verify the update was performed
            verify(namedUserClient).associate("namedUserID", "channelID");

            // Verify the last change token was updated
            assertEquals(changeToken, dataStore.getString(NamedUserJobHandler.LAST_UPDATED_TOKEN_KEY, null));

            // Reset the mocks so we can verify again
            reset(namedUserClient);
        }
    }
/**
     * Test associate named user succeeds if the status is 2xx.
     */
Test associate named user succeeds if the status is 2xx.
Test associate named user succeeds if the status is 2xx .
@Test
    public void testAssociateNamedUserSucceed() {
        when(pushManager.getChannelId()).thenReturn("channelID");
        when(namedUser.getId()).thenReturn("namedUserID");
        for (int statusCode = 200; statusCode < 300; statusCode++) {
            changeToken = UUID.randomUUID().toString();
            Response response = Mockito.mock(Response.class);
            when(namedUserClient.associate("namedUserID", "channelID")).thenReturn(response);
            when(response.getStatus()).thenReturn(statusCode);
            JobInfo jobInfo = JobInfo.newBuilder().setAction(NamedUserJobHandler.ACTION_UPDATE_NAMED_USER).build();
            Assert.assertEquals(JobInfo.JOB_FINISHED, jobHandler.performJob(jobInfo));
            verify(namedUserClient).associate("namedUserID", "channelID");
            assertEquals(changeToken, dataStore.getString(NamedUserJobHandler.LAST_UPDATED_TOKEN_KEY, null));
            reset(namedUserClient);
        }
    }
@ Test public void testAssociateNamedUserSucceed ( ) { when ( pushManager . getChannelId ( ) ) . thenReturn ( "channelID" ) ; when ( namedUser . getId ( ) ) . thenReturn ( "namedUserID" ) ; for ( int statusCode = 200 ; statusCode < 300 ; statusCode ++ ) { changeToken = UUID . randomUUID ( ) . toString ( ) ; Response response = Mockito . mock ( Response . class ) ; when ( namedUserClient . associate ( "namedUserID" , "channelID" ) ) . thenReturn ( response ) ; when ( response . getStatus ( ) ) . thenReturn ( statusCode ) ; JobInfo jobInfo = JobInfo . newBuilder ( ) . setAction ( NamedUserJobHandler . ACTION_UPDATE_NAMED_USER ) . build ( ) ; Assert . assertEquals ( JobInfo . JOB_FINISHED , jobHandler . performJob ( jobInfo ) ) ; verify ( namedUserClient ) . associate ( "namedUserID" , "channelID" ) ; assertEquals ( changeToken , dataStore . getString ( NamedUserJobHandler . LAST_UPDATED_TOKEN_KEY , null ) ) ; reset ( namedUserClient ) ; } }
Test associate named user succeeds if the status is 2xx.
Test associate named user succeeds if the status is 2xx .
// Set a new change token to force an update // Set up a 2xx response // Perform the update // Verify the update was performed // Verify the last change token was updated // Reset the mocks so we can verify again