Package org.mockito.internal.stubbing.answers

Examples of org.mockito.internal.stubbing.answers.ThrowsException


    final String exceptionMsg = "Nope, not replicated yet...";
    final int maxRetries = 1; // Allow one retry (total of two calls)
    conf.setInt(DFSConfigKeys.DFS_CLIENT_BLOCK_WRITE_LOCATEFOLLOWINGBLOCK_RETRIES_KEY, maxRetries);
   
    NamenodeProtocols mockNN = mock(NamenodeProtocols.class);
    Answer<Object> answer = new ThrowsException(new IOException()) {
      int retryCount = 0;
     
      @Override
      public Object answer(InvocationOnMock invocation)
                       throws Throwable {
View Full Code Here


    DummyHAService svc1 = spy(new DummyHAService(null, svc1Addr));
    // Getting a proxy to a dead server will throw IOException on call,
    // not on creation of the proxy.
    HAServiceProtocol errorThrowingProxy = Mockito.mock(HAServiceProtocol.class,
        Mockito.withSettings()
          .defaultAnswer(new ThrowsException(
              new IOException("Could not connect to host")))
          .extraInterfaces(Closeable.class));
    Mockito.doNothing().when((Closeable)errorThrowingProxy).close();

    Mockito.doReturn(errorThrowingProxy).when(svc1).getProxy(
View Full Code Here

    final String exceptionMsg = "Nope, not replicated yet...";
    final int maxRetries = 1; // Allow one retry (total of two calls)
    conf.setInt(DFSConfigKeys.DFS_CLIENT_BLOCK_WRITE_LOCATEFOLLOWINGBLOCK_RETRIES_KEY, maxRetries);
   
    NamenodeProtocols mockNN = mock(NamenodeProtocols.class);
    Answer<Object> answer = new ThrowsException(new IOException()) {
      int retryCount = 0;
     
      @Override
      public Object answer(InvocationOnMock invocation)
                       throws Throwable {
View Full Code Here

    Configuration conf = new HdfsConfiguration();
   conf.setInt(DFSConfigKeys.DFS_CLIENT_BLOCK_WRITE_LOCATEFOLLOWINGBLOCK_RETRIES_KEY,
                maxRetries);
   
    NameNode mockNN = mock(NameNode.class);
    Answer<Object> answer = new ThrowsException(new IOException()) {
      int retryCount = 0;
     
      @Override
      public Object answer(InvocationOnMock invocation)
                       throws Throwable {
View Full Code Here

    final String exceptionMsg = "Nope, not replicated yet...";
    final int maxRetries = 1; // Allow one retry (total of two calls)
    conf.setInt(DFSConfigKeys.DFS_CLIENT_BLOCK_WRITE_LOCATEFOLLOWINGBLOCK_RETRIES_KEY, maxRetries);
   
    NamenodeProtocols mockNN = mock(NamenodeProtocols.class);
    Answer<Object> answer = new ThrowsException(new IOException()) {
      int retryCount = 0;
     
      @Override
      public Object answer(InvocationOnMock invocation)
                       throws Throwable {
View Full Code Here

        this.mock = mock;
        this.invocationContainerImpl = invocationContainerImpl;
    }

    public VoidMethodStubbable<T> toThrow(Throwable throwable) {
        invocationContainerImpl.addAnswerForVoidMethod(new ThrowsException(throwable));
        return this;
    }
View Full Code Here

        }
        return stubbing;
    }

    private OngoingStubbing<T> thenThrow(Throwable throwable) {
        return thenAnswer(new ThrowsException(throwable));
    }
View Full Code Here

    @Mock(extraInterfaces={List.class},serializable=true) IMethods imethodsWithExtraInterfacesMock;
   
    @Test
    public void should_allow_throws_exception_to_be_serializable() throws Exception {
        // given
        when(barMock.doSomething()).thenAnswer(new ThrowsException(new RuntimeException()));

        //when-serialize then-deserialize
        serializeAndBack(barMock);
    }
View Full Code Here

    public DeprecatedOngoingStubbing<T> toReturn(T value) {
        return toAnswer(new Returns(value));
    }

    public DeprecatedOngoingStubbing<T> toThrow(Throwable throwable) {
        return toAnswer(new ThrowsException(throwable));
    }
View Full Code Here

    private static final long serialVersionUID = 6160482220413048624L;

    @Test
    public void should_allow_throws_exception_to_be_serializable() throws Exception {
        // given
        Bar mock = mock(Bar.class, new ThrowsException(new RuntimeException()));
        // when-serialize then-deserialize
        serializeAndBack(mock);
    }
View Full Code Here

TOP

Related Classes of org.mockito.internal.stubbing.answers.ThrowsException

Copyright © 2018 www.massapicom. 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.