Search in sources :

Example 31 with ArgumentCaptor

use of org.mockito.ArgumentCaptor in project OpenAM by OpenRock.

the class PolicyResourceDelegateTest method shouldHandleFailureToCreatePoliciesByDeletingCreatedPolicies.

@Test(expectedExceptions = ResourceException.class)
public void shouldHandleFailureToCreatePoliciesByDeletingCreatedPolicies() throws ResourceException {
    //Given
    //Given
    Context context = mock(Context.class);
    Set<JsonValue> policies = new HashSet<JsonValue>();
    JsonValue policyOne = json(object(field("name", "POLICY_ONE")));
    JsonValue policyTwo = json(object(field("name", "POLICY_TWO")));
    policies.add(policyOne);
    policies.add(policyTwo);
    ResourceResponse createdPolicyOne = newResourceResponse("ID_1", "REVISION_1", json(object()));
    ResourceException exception = mock(ResourceException.class);
    Promise<ResourceResponse, ResourceException> createPolicyOnePromise = Promises.newResultPromise(createdPolicyOne);
    Promise<ResourceResponse, ResourceException> createPolicyTwoPromise = Promises.newExceptionPromise(exception);
    Promise<ResourceResponse, ResourceException> deletePolicyOnePromise = Promises.newResultPromise(createdPolicyOne);
    given(policyResource.handleCreate(eq(context), Matchers.<CreateRequest>anyObject())).willReturn(createPolicyOnePromise).willReturn(createPolicyTwoPromise);
    given(policyResource.handleDelete(eq(context), Matchers.<DeleteRequest>anyObject())).willReturn(deletePolicyOnePromise);
    //When
    try {
        delegate.createPolicies(context, policies).getOrThrowUninterruptibly();
    } catch (ResourceException e) {
        //Then
        ArgumentCaptor<DeleteRequest> requestCaptor = ArgumentCaptor.forClass(DeleteRequest.class);
        verify(policyResource).handleDelete(eq(context), requestCaptor.capture());
        assertThat(requestCaptor.getValue().getResourcePathObject().leaf()).isEqualTo("ID_1");
        throw e;
    }
}
Also used : Context(org.forgerock.services.context.Context) ArgumentCaptor(org.mockito.ArgumentCaptor) Responses.newResourceResponse(org.forgerock.json.resource.Responses.newResourceResponse) ResourceResponse(org.forgerock.json.resource.ResourceResponse) CreateRequest(org.forgerock.json.resource.CreateRequest) JsonValue(org.forgerock.json.JsonValue) ResourceException(org.forgerock.json.resource.ResourceException) DeleteRequest(org.forgerock.json.resource.DeleteRequest) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 32 with ArgumentCaptor

use of org.mockito.ArgumentCaptor in project sakuli by ConSol.

the class TestCaseActionTest method testAddRelativeImagePaths.

@Test
public void testAddRelativeImagePaths() throws Exception {
    Path currenPath = Paths.get(".").toAbsolutePath().normalize();
    sample.setTcFile(currenPath.resolve("tc.js"));
    ArgumentCaptor path = ArgumentCaptor.forClass(Path.class);
    String picfolderName = "my_pic_folder";
    testling.addImagePathsAsString(picfolderName);
    verify(loaderMock).addImagePaths((Path[]) path.capture());
    assertEquals(path.getValue().toString(), currenPath.toString() + File.separator + picfolderName);
}
Also used : Path(java.nio.file.Path) ArgumentCaptor(org.mockito.ArgumentCaptor) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.testng.annotations.Test) BaseTest(org.sakuli.BaseTest)

Example 33 with ArgumentCaptor

use of org.mockito.ArgumentCaptor in project sakuli by ConSol.

the class TestCaseActionTest method testAddImagePaths.

@Test
public void testAddImagePaths() throws Exception {
    ArgumentCaptor path = ArgumentCaptor.forClass(Path.class);
    testling.addImagePathsAsString("/home");
    verify(loaderMock).addImagePaths((Path[]) path.capture());
    assertEquals(path.getValue().toString(), Paths.get("/home").normalize().toString());
}
Also used : Path(java.nio.file.Path) ArgumentCaptor(org.mockito.ArgumentCaptor) Test(org.testng.annotations.Test) BaseTest(org.sakuli.BaseTest)

Aggregations

ArgumentCaptor (org.mockito.ArgumentCaptor)33 List (java.util.List)16 Matchers.anyString (org.mockito.Matchers.anyString)15 Test (org.testng.annotations.Test)15 ArrayList (java.util.ArrayList)14 HashMap (java.util.HashMap)13 HashSet (java.util.HashSet)13 Map (java.util.Map)13 Set (java.util.Set)13 Collectors (java.util.stream.Collectors)13 Test (org.junit.Test)13 Mockito.verify (org.mockito.Mockito.verify)13 Collections (java.util.Collections)12 Arrays.asList (java.util.Arrays.asList)11 IOException (java.io.IOException)10 Arrays (java.util.Arrays)10 Collections.emptySet (java.util.Collections.emptySet)10 Collections.singleton (java.util.Collections.singleton)10 Collections.singletonMap (java.util.Collections.singletonMap)10 Function (java.util.function.Function)10