当前位置: 首页>>代码示例>>Java>>正文


Java ThrowingCallable类代码示例

本文整理汇总了Java中org.assertj.core.api.ThrowableAssert.ThrowingCallable的典型用法代码示例。如果您正苦于以下问题:Java ThrowingCallable类的具体用法?Java ThrowingCallable怎么用?Java ThrowingCallable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ThrowingCallable类属于org.assertj.core.api.ThrowableAssert包,在下文中一共展示了ThrowingCallable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: should_mock_final_method

import org.assertj.core.api.ThrowableAssert.ThrowingCallable; //导入依赖的package包/类
@Test
public void should_mock_final_method() {
    final FinalClass finalClass = Mockito.mock(FinalClass.class);
    
    doNothing().when(finalClass).say(anyString());
    
    Throwable throwable = catchThrowable(new ThrowingCallable() {
        @Override
        public void call() throws Throwable {
            finalClass.say(RandomStringUtils.random(10));
        }
    });
    
    assertThat(throwable)
        .as("Final method is mocked and exception is not thrown")
        .isNull();
    
}
 
开发者ID:powermock,项目名称:powermock-examples-maven,代码行数:19,代码来源:OnlyMockitoTest.java

示例2: validation_should_work_everytime_when_no_exception_is_thrown

import org.assertj.core.api.ThrowableAssert.ThrowingCallable; //导入依赖的package包/类
@Test
public void validation_should_work_everytime_when_no_exception_is_thrown() {
    InterfaceAvecDesMethodes mock = mock(InterfaceAvecDesMethodes.class);
    when(mock.recuperationDesDonnees(anyString())).thenReturn(resultListMock());

    final ServiceInterface service = getInterface(mock);

    Throwable thrownByMethod = catchThrowable(new ThrowingCallable() {
        @Override
        public void call() throws Throwable {
            service.validationDonneesForId("0");
        }
    });

    assertThat(thrownByMethod).isNull();
}
 
开发者ID:Eulbobo,项目名称:java-samples,代码行数:17,代码来源:AbstractServiceInterfaceTest.java

示例3: validation_should_work_everytime_when_sqlexception_is_thrown

import org.assertj.core.api.ThrowableAssert.ThrowingCallable; //导入依赖的package包/类
@Test
public void validation_should_work_everytime_when_sqlexception_is_thrown() throws SQLException {
    InterfaceAvecDesMethodes mock = mock(InterfaceAvecDesMethodes.class);
    when(mock.recuperationDesDonnees(anyString())).thenReturn(resultListMock());

    doThrow(SQLException.class)
            .when(mock)
            .verificationDesDonnees(anyList());

    final ServiceInterface service = getInterface(mock);

    Throwable thrownByMethod = catchThrowable(new ThrowingCallable() {
        @Override
        public void call() throws Throwable {
            service.validationDonneesForId("0");
        }
    });

    assertThat(thrownByMethod).isNull();
}
 
开发者ID:Eulbobo,项目名称:java-samples,代码行数:21,代码来源:AbstractServiceInterfaceTest.java

示例4: should_raise_and_exception_when_querying_for_unknow_object

import org.assertj.core.api.ThrowableAssert.ThrowingCallable; //导入依赖的package包/类
@Test
public void should_raise_and_exception_when_querying_for_unknow_object() {

    Throwable thrown = Assertions.catchThrowable(new ThrowingCallable() {

        @Override
        public void call() throws Throwable {
            queryForObject.getIdForUser(4);
            failBecauseExceptionWasNotThrown(EmptyResultDataAccessException.class);
        }
    });

    Assertions.assertThat(thrown)
            .isNotNull()
            .isInstanceOf(EmptyResultDataAccessException.class);
}
 
开发者ID:Eulbobo,项目名称:java-samples,代码行数:17,代码来源:QueryForObjectTest.java

示例5: saveOrUpdate_should_raise_and_SQLException

import org.assertj.core.api.ThrowableAssert.ThrowingCallable; //导入依赖的package包/类
@Test
public void saveOrUpdate_should_raise_and_SQLException() {
    final UserService service = new UserServiceImpl(mock(UserDao.class));

    Throwable throwable = Assertions.catchThrowable(new ThrowingCallable() {
        @Override
        public void call() throws Throwable {
            service.saveOrUpdate(user(1l, "one"));
        }
    });

    Assertions.assertThat(throwable)
            .isNotNull()
            .isInstanceOf(SQLException.class);

}
 
开发者ID:Eulbobo,项目名称:java-samples,代码行数:17,代码来源:UserServiceImplTest.java

示例6: delete_should_raise_and_UnsupportedOperationException

import org.assertj.core.api.ThrowableAssert.ThrowingCallable; //导入依赖的package包/类
@Test
public void delete_should_raise_and_UnsupportedOperationException() {
    final UserService service = new UserServiceImpl(mock(UserDao.class));

    Throwable throwable = Assertions.catchThrowable(new ThrowingCallable() {
        @Override
        public void call() throws Throwable {
            service.delete(user(1l, "one"));
        }
    });

    Assertions.assertThat(throwable)
            .isNotNull()
            .isInstanceOf(UnsupportedOperationException.class);

}
 
开发者ID:Eulbobo,项目名称:java-samples,代码行数:17,代码来源:UserServiceImplTest.java

示例7: thisWillFailMiserabily_should_raise_and_UnsupportedOperationException

import org.assertj.core.api.ThrowableAssert.ThrowingCallable; //导入依赖的package包/类
@Test
public void thisWillFailMiserabily_should_raise_and_UnsupportedOperationException() {
    final UserService service = new UserServiceImpl(mock(UserDao.class));

    Throwable throwable = Assertions.catchThrowable(new ThrowingCallable() {
        @Override
        public void call() throws Throwable {
            service.thisWillFailMiserabily();
        }
    });

    Assertions.assertThat(throwable)
            .isNotNull()
            .isInstanceOf(UnsupportedOperationException.class);

}
 
开发者ID:Eulbobo,项目名称:java-samples,代码行数:17,代码来源:UserServiceImplTest.java

示例8: should_catch_any_exception_but_DomainException_and_wrap_it_into_DomainException

import org.assertj.core.api.ThrowableAssert.ThrowingCallable; //导入依赖的package包/类
@Test
public void should_catch_any_exception_but_DomainException_and_wrap_it_into_DomainException() {
    final Exception thrown = new Exception();

    assertThatThrownBy(new ThrowingCallable() {
        @Override
        public void call() throws Throwable {
            final ExceptionAutoWrap aspect = new ExceptionAutoWrap();
            aspect.catchLogAndRethrow(thrown);
            failBecauseExceptionWasNotThrown(Exception.class);
        }
    })
            .isNotNull()
            .isInstanceOf(DomainException.class)
            .hasCause(thrown);
}
 
开发者ID:Eulbobo,项目名称:java-samples,代码行数:17,代码来源:ExceptionAutoWrapTest.java

示例9: should_catch_any_RuntimeException_and_wrap_it_into_DomainException

import org.assertj.core.api.ThrowableAssert.ThrowingCallable; //导入依赖的package包/类
@Test
public void should_catch_any_RuntimeException_and_wrap_it_into_DomainException() {
    final Exception thrown = new RuntimeException();

    assertThatThrownBy(new ThrowingCallable() {
        @Override
        public void call() throws Throwable {
            final ExceptionAutoWrap aspect = new ExceptionAutoWrap();
            aspect.catchLogAndRethrow(thrown);
            failBecauseExceptionWasNotThrown(Exception.class);
        }
    })
            .isNotNull()
            .isInstanceOf(DomainException.class)
            .hasCause(thrown);
}
 
开发者ID:Eulbobo,项目名称:java-samples,代码行数:17,代码来源:ExceptionAutoWrapTest.java

示例10: should_not_wrap_DomainException

import org.assertj.core.api.ThrowableAssert.ThrowingCallable; //导入依赖的package包/类
@Test
public void should_not_wrap_DomainException() {
    final Exception thrown = new DomainException("Test message");

    assertThatThrownBy(new ThrowingCallable() {
        @Override
        public void call() throws Throwable {
            final ExceptionAutoWrap aspect = new ExceptionAutoWrap();
            aspect.catchLogAndRethrow(thrown);
            failBecauseExceptionWasNotThrown(DomainException.class);
        }
    })
            .isNotNull()
            .isInstanceOf(DomainException.class)
            .hasNoCause()
            .isEqualTo(thrown);
}
 
开发者ID:Eulbobo,项目名称:java-samples,代码行数:18,代码来源:ExceptionAutoWrapTest.java

示例11: should_wrap_any_RuntimeException_into_Checked_Exception

import org.assertj.core.api.ThrowableAssert.ThrowingCallable; //导入依赖的package包/类
@Test
public void should_wrap_any_RuntimeException_into_Checked_Exception() {
    final RuntimeException thrown = new DomainException("Test message");

    assertThatThrownBy(new ThrowingCallable() {
        @Override
        public void call() throws Throwable {
            final ExceptionAutoWrap aspect = new ExceptionAutoWrap();
            aspect.wrapIntoNotRuntimeException(thrown);
            failBecauseExceptionWasNotThrown(Exception.class);
        }
    })
            .isNotNull()
            .isInstanceOf(Exception.class)
            .hasCause(thrown);
}
 
开发者ID:Eulbobo,项目名称:java-samples,代码行数:17,代码来源:ExceptionAutoWrapTest.java

示例12: should_raise_DiceException_when_rolling_dice_with_a_beautiful_test

import org.assertj.core.api.ThrowableAssert.ThrowingCallable; //导入依赖的package包/类
@Test
public void should_raise_DiceException_when_rolling_dice_with_a_beautiful_test() {
    final MethodsThrowingExceptions method = new MethodsThrowingExceptions(21);

    // la meilleure façon de tester si on est en Java7 avec assertJ 2.X
    Throwable thrownByMethod = Assertions.catchThrowable(new ThrowingCallable() {
        @Override
        public void call() throws Throwable {
            method.rollDice();
            failBecauseExceptionWasNotThrown(DiceException.class);
        }
    });

    assertThat(thrownByMethod)
            .isInstanceOf(RandomException.class)
            .isExactlyInstanceOf(DiceException.class)
            .hasMessageContaining("21 failures yet");
}
 
开发者ID:Eulbobo,项目名称:java-samples,代码行数:19,代码来源:MethodsThrowingExceptionsTest.java

示例13: assertThatThrownByWithExpectedException

import org.assertj.core.api.ThrowableAssert.ThrowingCallable; //导入依赖的package包/类
/**
 * Adds {@code "(expected exception)"} to the log message and lower its logging level to
 * {@link Level#DEBUG} if the exception occurred from the {@code shouldRaiseThrowable} matches
 * {@code throwable} and contains {@code message}.
 */
public static AbstractThrowableAssert<?, ? extends Throwable> assertThatThrownByWithExpectedException(
        Class<?> throwable, String message, ThrowingCallable shouldRaiseThrowable) throws Exception {
    requireNonNull(throwable, "throwable");
    requireNonNull(message, "message");
    requireNonNull(shouldRaiseThrowable, "shouldRaiseThrowable");
    exceptionAndMessage.put(throwable.getName(), message);
    try {
        return assertThatThrownBy(shouldRaiseThrowable);
    } finally {
        exceptionAndMessage.remove(throwable.getName());
    }
}
 
开发者ID:line,项目名称:centraldogma,代码行数:18,代码来源:ExpectedExceptionAppender.java

示例14: shouldThrowForNonDataenumClassName

import org.assertj.core.api.ThrowableAssert.ThrowingCallable; //导入依赖的package包/类
@Test
public void shouldThrowForNonDataenumClassName() throws Exception {
  assertThatThrownBy(
          new ThrowingCallable() {
            @Override
            public void call() throws Throwable {
              OutputSpecFactory.toOutputClass(ClassName.get("com.spotify", "My"));
            }
          })
      .isInstanceOf(ParserException.class)
      .hasMessageContaining("Bad name");
}
 
开发者ID:spotify,项目名称:dataenum,代码行数:13,代码来源:OutputSpecFactoryTest.java

示例15: shouldThrowForNonClassName

import org.assertj.core.api.ThrowableAssert.ThrowingCallable; //导入依赖的package包/类
@Test
public void shouldThrowForNonClassName() throws Exception {
  assertThatThrownBy(
          new ThrowingCallable() {
            @Override
            public void call() throws Throwable {
              OutputSpecFactory.toOutputClass(TypeName.BOOLEAN);
            }
          })
      .isInstanceOf(ClassCastException.class);
}
 
开发者ID:spotify,项目名称:dataenum,代码行数:12,代码来源:OutputSpecFactoryTest.java


注:本文中的org.assertj.core.api.ThrowableAssert.ThrowingCallable类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。