Package org.mockito.internal.stubbing.answers

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


    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


     * @param toBeThrown
     *            to be thrown when the stubbed method is called
     * @return stubber - to select a method for stubbing
     */
    public static PowerMockitoStubber doThrow(Throwable toBeThrown) {
        return POWERMOCKITO_CORE.doAnswer(new ThrowsException(toBeThrown));
    }
View Full Code Here

    public static <T> OngoingStubbing<T> when(T methodCall) {
        return new OngoingStubbingExt<T>(Mockito.when(methodCall));
    }

    public static Stubber doThrow(Throwable toBeThrown) {
        return doAnswer(new ThrowsException(toBeThrown));
    }
View Full Code Here

        @Override
        public OngoingStubbing<T> thenThrow(Throwable... throwables) {
            if (throwables.length > 1)
                throw new UnsupportedOperationException();
            return thenAnswer(new ThrowsException(throwables[0]));
        }
View Full Code Here

        @Override
        public OngoingStubbing<T> thenThrow(Class<? extends Throwable>... throwableClasses) {
            try {
                if (throwableClasses.length > 0)
                    throw new UnsupportedOperationException();
                return thenAnswer(new ThrowsException(throwableClasses[0].newInstance()));
            } catch (InstantiationException ex) {
                throw new RuntimeException(ex);
            } catch (IllegalAccessException ex) {
                throw new RuntimeException(ex);
            }
View Full Code Here

            this.delegate = delegate;
        }

        @Override
        public Stubber doThrow(Throwable toBeThrown) {
            return doAnswer(new ThrowsException(toBeThrown));
        }
View Full Code Here

        }

        @Override
        public Stubber doThrow(Class<? extends Throwable> toBeThrown) {
            try {
                return doAnswer(new ThrowsException(toBeThrown.newInstance()));
            } catch (InstantiationException ex) {
                throw new RuntimeException(ex);
            } catch (IllegalAccessException ex) {
                throw new RuntimeException(ex);
            }
View Full Code Here

    @Test
    public void verifyInputStreamIsClosedOnException() throws IOException {
        InputStream is = null;
        try {
            Resource resource = mock(Resource.class);
            is = mock(InputStream.class, new ThrowsException(new IOException()));
            when(resource.exists()).thenReturn(true);
            when(resource.getInputStream()).thenReturn(is);
            PropertiesStore ps = new PropertiesStore();
            ps.addResource(resource);
            Assert.fail();;
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

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.