Search in sources :

Example 71 with Answer

use of org.mockito.stubbing.Answer in project hazelcast by hazelcast.

the class HazelcastInstanceFactoryTest method test_NewInstance_terminateInstance_afterNodeStart.

@Test(expected = IllegalStateException.class)
public void test_NewInstance_terminateInstance_afterNodeStart() throws Exception {
    NodeContext context = new TestNodeContext() {

        @Override
        public NodeExtension createNodeExtension(final Node node) {
            NodeExtension nodeExtension = super.createNodeExtension(node);
            doAnswer(new Answer() {

                @Override
                public Object answer(InvocationOnMock invocation) throws Throwable {
                    node.hazelcastInstance.shutdown();
                    return null;
                }
            }).when(nodeExtension).afterStart();
            return nodeExtension;
        }
    };
    Config config = new Config();
    config.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false);
    hazelcastInstance = HazelcastInstanceFactory.newHazelcastInstance(config, randomString(), context);
}
Also used : Answer(org.mockito.stubbing.Answer) Mockito.doAnswer(org.mockito.Mockito.doAnswer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Config(com.hazelcast.config.Config) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 72 with Answer

use of org.mockito.stubbing.Answer in project fresco by facebook.

the class DrawableTestUtils method stubSetAlpha.

/**
   * Stubs setAlpha method.
   * @param drawable to stub method of
   */
public static void stubSetAlpha(final Drawable drawable) {
    final AtomicInteger atomicInteger = new AtomicInteger(255);
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            Integer alpha = (Integer) invocation.getArguments()[0];
            drawable.invalidateSelf();
            atomicInteger.set(alpha);
            return null;
        }
    }).when(drawable).setAlpha(anyInt());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Answer(org.mockito.stubbing.Answer) Mockito.doAnswer(org.mockito.Mockito.doAnswer) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) InvocationOnMock(org.mockito.invocation.InvocationOnMock)

Example 73 with Answer

use of org.mockito.stubbing.Answer in project fresco by facebook.

the class DrawableTestUtils method stubGetAndSetBounds.

/**
   * Stubs setBounds and getBounds methods.
   * @param drawable drawable to stub methods of
   */
public static void stubGetAndSetBounds(Drawable drawable) {
    final Rect rect = new Rect();
    when(drawable.getBounds()).thenReturn(rect);
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            rect.set((Integer) invocation.getArguments()[0], (Integer) invocation.getArguments()[1], (Integer) invocation.getArguments()[2], (Integer) invocation.getArguments()[3]);
            return null;
        }
    }).when(drawable).setBounds(anyInt(), anyInt(), anyInt(), anyInt());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Answer(org.mockito.stubbing.Answer) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Rect(android.graphics.Rect) InvocationOnMock(org.mockito.invocation.InvocationOnMock)

Example 74 with Answer

use of org.mockito.stubbing.Answer in project fresco by facebook.

the class DraweeMocks method stubGetAndSetHierarchy.

/**
   * Stubs setHierarchy and getHierarchy methods.
   * @param controller controller to stub methods of
   */
public static void stubGetAndSetHierarchy(DraweeController controller) {
    final DraweeHierarchy[] dhHolder = new DraweeHierarchy[1];
    doAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            return dhHolder[0];
        }
    }).when(controller).getHierarchy();
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            return dhHolder[0] = (DraweeHierarchy) invocation.getArguments()[0];
        }
    }).when(controller).setHierarchy(any(DraweeHierarchy.class));
}
Also used : Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) GenericDraweeHierarchy(com.facebook.drawee.generic.GenericDraweeHierarchy) DraweeHierarchy(com.facebook.drawee.interfaces.DraweeHierarchy)

Example 75 with Answer

use of org.mockito.stubbing.Answer in project fresco by facebook.

the class DraweeMocks method stubGetAndSetContentDescription.

/**
   * Stubs setContentDescription and getContentDescription methods.
   * @param controller controller to stub methods of
   */
public static void stubGetAndSetContentDescription(DraweeController controller) {
    final String[] contentDescriptionHolder = new String[1];
    doAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            return contentDescriptionHolder[0];
        }
    }).when(controller).getContentDescription();
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            return contentDescriptionHolder[0] = (String) invocation.getArguments()[0];
        }
    }).when(controller).setContentDescription(any(String.class));
}
Also used : Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock)

Aggregations

Answer (org.mockito.stubbing.Answer)262 InvocationOnMock (org.mockito.invocation.InvocationOnMock)247 Test (org.junit.Test)148 Mockito.doAnswer (org.mockito.Mockito.doAnswer)99 Before (org.junit.Before)36 Matchers.anyString (org.mockito.Matchers.anyString)32 HashMap (java.util.HashMap)31 ArrayList (java.util.ArrayList)30 IOException (java.io.IOException)20 HashSet (java.util.HashSet)16 File (java.io.File)15 AtomicReference (java.util.concurrent.atomic.AtomicReference)15 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)15 Map (java.util.Map)13 List (java.util.List)12 Test (org.testng.annotations.Test)12 CountDownLatch (java.util.concurrent.CountDownLatch)11 Configuration (org.apache.hadoop.conf.Configuration)11 RequestFinishedListener (com.android.volley.RequestQueue.RequestFinishedListener)9 MockRequest (com.android.volley.mock.MockRequest)9