org.junit.jupiter.api.Assertions#assertThrows()源码实例Demo

下面列出了org.junit.jupiter.api.Assertions#assertThrows() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: Slimefun4   文件: TestProfileResearches.java
@Test
public void testSetResearched() throws InterruptedException {
    SlimefunPlugin.getRegistry().setResearchingEnabled(true);

    Player player = server.addPlayer();
    PlayerProfile profile = TestUtilities.awaitProfile(player);

    Assertions.assertThrows(IllegalArgumentException.class, () -> profile.setResearched(null, true));

    NamespacedKey key = new NamespacedKey(plugin, "player_profile_test");
    Research research = new Research(key, 250, "Test", 100);
    research.register();

    Assertions.assertFalse(profile.isDirty());
    profile.setResearched(research, true);
    Assertions.assertTrue(profile.isDirty());

    Assertions.assertTrue(profile.hasUnlocked(research));
}
 
源代码2 项目: storm-dynamic-spout   文件: ConsumerStateTest.java
/**
 * Verifies we cannot mutate ConsumerState.
 */
@Test
public void testCannotPut() {
    // Our happy case
    final ConsumerPartition topicPartition = new ConsumerPartition("MyTopic", 2);
    final long offset = 23L;

    final ConsumerState consumerState = ConsumerState.builder()
        .withPartition(topicPartition, offset)
        .build();

    Assertions.assertThrows(UnsupportedOperationException.class, () ->
        consumerState.put(new ConsumerPartition("MyTopic", 3), 2L)
    );
}
 
源代码3 项目: influxdb-java   文件: PointTest.java
/**
 * Tests for issue #110
 */
@Test
public void testAddingTagsWithNullNameThrowsAnError() {
    Assertions.assertThrows(NullPointerException.class, () -> {
        Point.measurement("dontcare").tag(null, "DontCare");
    });
}
 
源代码4 项目: smithy   文件: ValidationEventTest.java
@Test
public void requiresMessage() {
    Assertions.assertThrows(IllegalStateException.class, () -> {
        ValidationEvent.builder()
                .severity(Severity.ERROR)
                .eventId("foo")
                .build();
    });
}
 
源代码5 项目: commons-imaging   文件: FieldTypeRationalTest.java
@Test
public void testWriteDataWithNonNull() throws ImageWriteException {
    FieldTypeRational fieldTypeRational = new FieldTypeRational((-922), "z_AX");
    ByteOrder byteOrder = ByteOrder.nativeOrder();
    Assertions.assertThrows(ImageWriteException.class, () -> {
        fieldTypeRational.writeData("z_AX", byteOrder);
    });
}
 
@MethodSource
@ParameterizedTest
public void testReadOnlyParameters(String filename, String expectedExceptionMessage, Class<? extends SLException> expectedException) {
    DeploymentDescriptor descriptor = getDescriptorParser().parseDeploymentDescriptorYaml(getClass().getResourceAsStream(filename));
    if (expectedException != null) {
        Exception exception = Assertions.assertThrows(expectedException, () -> readOnlyParametersChecker.check(descriptor));
        Assertions.assertEquals(expectedExceptionMessage, exception.getMessage());
        return;
    }
    readOnlyParametersChecker.check(descriptor);
}
 
源代码7 项目: smithy   文件: CodeFormatterTest.java
@Test
public void performsRelativeBoundsChecking() {
    Assertions.assertThrows(IllegalArgumentException.class, () -> {
        CodeFormatter formatter = new CodeFormatter();
        formatter.putFormatter('L', CodeFormatterTest::valueOf);
        formatter.format("hello $L", "", createWriter());
    });
}
 
@Test
void closeSessionThrowsOnError() {
    when(edsdkLibrary().EdsCloseSession(fakeCamera)).thenReturn(new NativeLong(EdsdkError.EDS_ERR_DEVICE_INVALID.value()));

    when(edsdkLibrary().EdsRelease(fakeCamera)).thenReturn(new NativeLong(0L));

    final CloseSessionOption option = new CloseSessionOptionBuilder()
        .setCameraRef(fakeCamera)
        .build();

    Assertions.assertThrows(EdsdkDeviceInvalidErrorException.class, () -> spyCameraLogic.closeSession(option));

    verify(edsdkLibrary(), times(0)).EdsRelease(same(fakeCamera));
}
 
源代码9 项目: Slimefun4   文件: TestRecipeService.java
@Test
public void testSubscriptions() {
    MinecraftRecipeService service = new MinecraftRecipeService(plugin);
    AtomicReference<RecipeSnapshot> reference = new AtomicReference<>();

    Assertions.assertThrows(IllegalArgumentException.class, () -> service.subscribe(null));

    service.subscribe(reference::set);
    service.refresh();

    // The callback was executed
    Assertions.assertNotNull(reference.get());
}
 
源代码10 项目: commons-numbers   文件: QuaternionTest.java
@Test
void testInverse_nanNorm() {
    Quaternion q = Quaternion.of(Double.NaN, 0, 0, 0);
    Assertions.assertThrows(IllegalStateException.class,
            q::inverse
    );
}
 
源代码11 项目: commons-numbers   文件: ComplexTest.java
@Test
void testParseEmpty() {
    Assertions.assertThrows(NumberFormatException.class, () -> Complex.parse(""));
    Assertions.assertThrows(NumberFormatException.class, () -> Complex.parse(" "));
}
 
源代码12 项目: spring-batch-rest   文件: AdHocSchedulerTest.java
@Test
public void exceptionForBadJobConfigCron() {
	Assertions.assertThrows(RuntimeException.class, () -> {
		scheduler.schedule(JobConfig.builder().name(null).asynchronous(false).build(), TRIGGER_EVERY_SECOND);
	});
}
 
源代码13 项目: spectator   文件: AbstractPatternMatcherTest.java
@Test
public void unknownQuantifier() {
  Assertions.assertThrows(IllegalArgumentException.class,
      () -> PatternMatcher.compile(".+*"));
}
 
源代码14 项目: mangooio   文件: MangooUtilsTest.java
@Test()
public void testInvalidMaxRandomString() {
    Assertions.assertThrows(IllegalArgumentException.class, () -> {
        MangooUtils.randomString(257);
    }, "Failed to test invalid max number of random string");
}
 
源代码15 项目: symbol-sdk-java   文件: SignatureTest.java
@Test
public void byteArrayCtorFailsIfByteArrayIsTooSmall() {
    // Act:
    Assertions.assertThrows(IllegalArgumentException.class, () -> new Signature(new byte[63]));
}
 
源代码16 项目: influxdb-java   文件: InfluxDBFactoryTest.java
@Test
public void testShouldThrowIllegalArgumentWithInvalidUrl() {
	Assertions.assertThrows(IllegalArgumentException.class,() -> {
		 InfluxDBFactory.connect("invalidUrl");
	});
}
 
@Test
void testConstructorPrecondition1() {
    Assertions.assertThrows(DistributionException.class, () -> new ChiSquaredDistribution(0));
}
 
源代码18 项目: cloudbreak   文件: ProxyConfigServiceTest.java
@Test
public void testDeleteByNameForAccountIdEmpty() {
    when(proxyConfigRepository.findByNameInAccount(NAME, ACCOUNT_ID)).thenReturn(Optional.empty());
    Assertions.assertThrows(NotFoundException.class, () -> underTestProxyConfigService.deleteByNameInAccount(NAME, ACCOUNT_ID));
}
 
源代码19 项目: symbol-sdk-java   文件: SignatureTest.java
@Test
public void binaryCtorFailsIfByteArrayOfRIsTooLarge() {
    // Act:
    Assertions.assertThrows(IllegalArgumentException.class,
        () -> new Signature(new byte[33], new byte[32]));
}
 
源代码20 项目: canon-sdk-java   文件: AbstractCanonCommandTest.java
@Test
void getExecutionDurationSinceNow() {
    Assertions.assertThrows(IllegalStateException.class, () -> doNothingCommand.getExecutionDurationSinceNow());

    doNothingCommand.run();

    final Duration duration = doNothingCommand.getExecutionDurationSinceNow();

    Assertions.assertNotNull(duration);
}