How to use SimpleArgumentResolverTest class of org.mockito.internal.configuration.injection package

Best Mockito code snippet using org.mockito.internal.configuration.injection.SimpleArgumentResolverTest

Run Mockito automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

copy
1/*
2 * Copyright (c) 2007 Mockito contributors
3 * This program is made available under the terms of the MIT License.
4 */
5
6package org.mockito.test.configuration.injection;
7
8import org.junit.Test;
9import org.mockito.internal.configuration.injection.ConstructorInjection;
10
11import java.io.ByteArrayOutputStream;
12import java.io.OutputStream;
13import java.util.*;
14
15import static org.junit.Assert.*;
16
17public class SimpleArgumentResolverTest {
18
19    @Test
20    public void should_return_object_matching_given_types() throws Exception {
21        ConstructorInjection.SimpleArgumentResolver resolver =
22                new ConstructorInjection.SimpleArgumentResolver(newSetOf(new HashSet<Long>(), new ByteArrayOutputStream(), new HashMap<String, String>()));
23
24        Object[] resolvedInstance = resolver.resolveTypeInstances(Set.class, Map.class, OutputStream.class);
25
26        assertEquals(3, resolvedInstance.length);
27        assertTrue(resolvedInstance[0] instanceof Set);
28        assertTrue(resolvedInstance[1] instanceof Map);
29        assertTrue(resolvedInstance[2] instanceof OutputStream);
30    }
31
32    @Test
33    public void should_return_null_when_match_is_not_possible_on_given_types() throws Exception {
34        ConstructorInjection.SimpleArgumentResolver resolver =
35                new ConstructorInjection.SimpleArgumentResolver(newSetOf(new HashSet<Float>(), new ByteArrayOutputStream()));
36
37        Object[] resolvedInstance = resolver.resolveTypeInstances(Set.class, Map.class, OutputStream.class);
38
39        assertEquals(3, resolvedInstance.length);
40        assertTrue(resolvedInstance[0] instanceof Set);
41        assertNull(resolvedInstance[1]);
42        assertTrue(resolvedInstance[2] instanceof OutputStream);
43    }
44
45    @Test
46    public void should_return_null_when_types_are_primitives() throws Exception {
47        ConstructorInjection.SimpleArgumentResolver resolver =
48                new ConstructorInjection.SimpleArgumentResolver(newSetOf(new HashMap<Integer, String>(), new TreeSet<Integer>()));
49
50        Object[] resolvedInstance = resolver.resolveTypeInstances(Set.class, Map.class, Boolean.class);
51
52        assertEquals(3, resolvedInstance.length);
53        assertTrue(resolvedInstance[0] instanceof Set);
54        assertTrue(resolvedInstance[1] instanceof Map);
55        assertNull(resolvedInstance[2]);
56    }
57
58    private Set<Object> newSetOf(Object... objects) {
59        return new HashSet<Object>(Arrays.asList(objects));
60    }
61
62
63}
64
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

...Most popular Stackoverflow questions on SimpleArgumentResolverTest

    No relevant questions found for this class 😞

Run Selenium Automation Tests on LambdaTest Cloud Grid

Trigger Selenium automation tests on a cloud-based Grid of 3000+ real browsers and operating systems.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)