下面列出了org.junit.jupiter.api.Assertions#assertThrows() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@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));
}
/**
* 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)
);
}
/**
* Tests for issue #110
*/
@Test
public void testAddingTagsWithNullNameThrowsAnError() {
Assertions.assertThrows(NullPointerException.class, () -> {
Point.measurement("dontcare").tag(null, "DontCare");
});
}
@Test
public void requiresMessage() {
Assertions.assertThrows(IllegalStateException.class, () -> {
ValidationEvent.builder()
.severity(Severity.ERROR)
.eventId("foo")
.build();
});
}
@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);
}
@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));
}
@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());
}
@Test
void testInverse_nanNorm() {
Quaternion q = Quaternion.of(Double.NaN, 0, 0, 0);
Assertions.assertThrows(IllegalStateException.class,
q::inverse
);
}
@Test
void testParseEmpty() {
Assertions.assertThrows(NumberFormatException.class, () -> Complex.parse(""));
Assertions.assertThrows(NumberFormatException.class, () -> Complex.parse(" "));
}
@Test
public void exceptionForBadJobConfigCron() {
Assertions.assertThrows(RuntimeException.class, () -> {
scheduler.schedule(JobConfig.builder().name(null).asynchronous(false).build(), TRIGGER_EVERY_SECOND);
});
}
@Test
public void unknownQuantifier() {
Assertions.assertThrows(IllegalArgumentException.class,
() -> PatternMatcher.compile(".+*"));
}
@Test()
public void testInvalidMaxRandomString() {
Assertions.assertThrows(IllegalArgumentException.class, () -> {
MangooUtils.randomString(257);
}, "Failed to test invalid max number of random string");
}
@Test
public void byteArrayCtorFailsIfByteArrayIsTooSmall() {
// Act:
Assertions.assertThrows(IllegalArgumentException.class, () -> new Signature(new byte[63]));
}
@Test
public void testShouldThrowIllegalArgumentWithInvalidUrl() {
Assertions.assertThrows(IllegalArgumentException.class,() -> {
InfluxDBFactory.connect("invalidUrl");
});
}
@Test
void testConstructorPrecondition1() {
Assertions.assertThrows(DistributionException.class, () -> new ChiSquaredDistribution(0));
}
@Test
public void testDeleteByNameForAccountIdEmpty() {
when(proxyConfigRepository.findByNameInAccount(NAME, ACCOUNT_ID)).thenReturn(Optional.empty());
Assertions.assertThrows(NotFoundException.class, () -> underTestProxyConfigService.deleteByNameInAccount(NAME, ACCOUNT_ID));
}
@Test
public void binaryCtorFailsIfByteArrayOfRIsTooLarge() {
// Act:
Assertions.assertThrows(IllegalArgumentException.class,
() -> new Signature(new byte[33], new byte[32]));
}
@Test
void getExecutionDurationSinceNow() {
Assertions.assertThrows(IllegalStateException.class, () -> doNothingCommand.getExecutionDurationSinceNow());
doNothingCommand.run();
final Duration duration = doNothingCommand.getExecutionDurationSinceNow();
Assertions.assertNotNull(duration);
}