Examples of Stubber


Examples of org.mockito.internal.stubbing.Stubber

   
    public MockHandler(String mockName, MockingProgress mockingProgress, MatchersBinder matchersBinder) {
        this.mockName = mockName;
        this.mockingProgress = mockingProgress;
        this.matchersBinder = matchersBinder;
        stubber = new Stubber(mockingProgress);
       
        verifyingRecorder = createRecorder();
    }
View Full Code Here

Examples of org.mockito.stubbing.Stubber

        }
    }

    protected void mockListen(List<DomainEvent> anEvents, int aLoops) {
        int i = 0;
        Stubber theStubber = null;
        do {
            if(theStubber == null) {
                theStubber = doAnswer(new AsyncCallbackAnswer<List<DomainEvent>>(anEvents));
            } else {
                theStubber.doAnswer(new AsyncCallbackAnswer<List<DomainEvent>>(anEvents));
            }
        } while(++i < aLoops);
        theStubber.doNothing().when(myEventServiceAsyncMock).listen(any(AsyncCallback.class));
    }
View Full Code Here

Examples of org.mockito.stubbing.Stubber

        theStubber.doNothing().when(myEventServiceAsyncMock).listen(any(AsyncCallback.class));
    }

    protected void mockListen(List<DomainEvent> anEvents, int aLoops, Throwable aTestException) {
        int i = 0;
        Stubber theStubber = null;
        do {
            if(theStubber == null) {
                theStubber = doAnswer(new AsyncCallbackThrowableAnswer(aTestException));
            } else {
                theStubber.doAnswer(new AsyncCallbackThrowableAnswer(aTestException));
            }
        } while(++i < aLoops);
        theStubber.doNothing().when(myEventServiceAsyncMock).listen(any(AsyncCallback.class));

        //When no events are available, there will not follow a successful call.
        if(aLoops > 0 && anEvents != null && !anEvents.isEmpty()) {
            doAnswer(new AsyncCallbackAnswer(anEvents)).doNothing().when(myEventServiceAsyncMock).listen(any(AsyncCallback.class));
        }
View Full Code Here

Examples of org.mockito.stubbing.Stubber

    throws IOException {

    TransportConf conf = new TransportConf(new SystemPropertyConfigProvider());
    BlockFetchStarter fetchStarter = mock(BlockFetchStarter.class);

    Stubber stub = null;

    // Contains all blockIds that are referenced across all interactions.
    final LinkedHashSet<String> blockIds = Sets.newLinkedHashSet();

    for (final Map<String, Object> interaction : interactions) {
      blockIds.addAll(interaction.keySet());

      Answer<Void> answer = new Answer<Void>() {
        @Override
        public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
          try {
            // Verify that the RetryingBlockFetcher requested the expected blocks.
            String[] requestedBlockIds = (String[]) invocationOnMock.getArguments()[0];
            String[] desiredBlockIds = interaction.keySet().toArray(new String[interaction.size()]);
            assertArrayEquals(desiredBlockIds, requestedBlockIds);

            // Now actually invoke the success/failure callbacks on each block.
            BlockFetchingListener retryListener =
              (BlockFetchingListener) invocationOnMock.getArguments()[1];
            for (Map.Entry<String, Object> block : interaction.entrySet()) {
              String blockId = block.getKey();
              Object blockValue = block.getValue();

              if (blockValue instanceof ManagedBuffer) {
                retryListener.onBlockFetchSuccess(blockId, (ManagedBuffer) blockValue);
              } else if (blockValue instanceof Exception) {
                retryListener.onBlockFetchFailure(blockId, (Exception) blockValue);
              } else {
                fail("Can only handle ManagedBuffers and Exceptions, got " + blockValue);
              }
            }
            return null;
          } catch (Throwable e) {
            e.printStackTrace();
            throw e;
          }
        }
      };

      // This is either the first stub, or should be chained behind the prior ones.
      if (stub == null) {
        stub = doAnswer(answer);
      } else {
        stub.doAnswer(answer);
      }
    }

    assert stub != null;
    stub.when(fetchStarter).createAndStart((String[]) any(), (BlockFetchingListener) anyObject());
    String[] blockIdArray = blockIds.toArray(new String[blockIds.size()]);
    new RetryingBlockFetcher(conf, fetchStarter, blockIdArray, listener).start();
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.