Java Code Examples for org.junit.jupiter.api.Assertions#assertThrows()

The following examples show how to use org.junit.jupiter.api.Assertions#assertThrows() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestProfileResearches.java    From Slimefun4 with GNU General Public License v3.0 7 votes vote down vote up
@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));
}
 
Example 2
Source File: MangooUtilsTest.java    From mangooio with Apache License 2.0 5 votes vote down vote up
@Test()
public void testInvalidMaxRandomString() {
    Assertions.assertThrows(IllegalArgumentException.class, () -> {
        MangooUtils.randomString(257);
    }, "Failed to test invalid max number of random string");
}
 
Example 3
Source File: QuaternionTest.java    From commons-numbers with Apache License 2.0 5 votes vote down vote up
@Test
void testInverse_nanNorm() {
    Quaternion q = Quaternion.of(Double.NaN, 0, 0, 0);
    Assertions.assertThrows(IllegalStateException.class,
            q::inverse
    );
}
 
Example 4
Source File: TestRecipeService.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
@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());
}
 
Example 5
Source File: CameraLogicDefaultMockTest.java    From canon-sdk-java with MIT License 5 votes vote down vote up
@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));
}
 
Example 6
Source File: ConsumerStateTest.java    From storm-dynamic-spout with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * 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)
    );
}
 
Example 7
Source File: CodeFormatterTest.java    From smithy with Apache License 2.0 5 votes vote down vote up
@Test
public void performsRelativeBoundsChecking() {
    Assertions.assertThrows(IllegalArgumentException.class, () -> {
        CodeFormatter formatter = new CodeFormatter();
        formatter.putFormatter('L', CodeFormatterTest::valueOf);
        formatter.format("hello $L", "", createWriter());
    });
}
 
Example 8
Source File: ReadOnlyParametersCheckerTest.java    From multiapps-controller with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 9
Source File: FieldTypeRationalTest.java    From commons-imaging with Apache License 2.0 5 votes vote down vote up
@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);
    });
}
 
Example 10
Source File: ValidationEventTest.java    From smithy with Apache License 2.0 5 votes vote down vote up
@Test
public void requiresMessage() {
    Assertions.assertThrows(IllegalStateException.class, () -> {
        ValidationEvent.builder()
                .severity(Severity.ERROR)
                .eventId("foo")
                .build();
    });
}
 
Example 11
Source File: PointTest.java    From influxdb-java with MIT License 5 votes vote down vote up
/**
 * Tests for issue #110
 */
@Test
public void testAddingTagsWithNullNameThrowsAnError() {
    Assertions.assertThrows(NullPointerException.class, () -> {
        Point.measurement("dontcare").tag(null, "DontCare");
    });
}
 
Example 12
Source File: AdHocSchedulerTest.java    From spring-batch-rest with Apache License 2.0 4 votes vote down vote up
@Test
public void exceptionForBadJobConfigCron() {
	Assertions.assertThrows(RuntimeException.class, () -> {
		scheduler.schedule(JobConfig.builder().name(null).asynchronous(false).build(), TRIGGER_EVERY_SECOND);
	});
}
 
Example 13
Source File: AbstractPatternMatcherTest.java    From spectator with Apache License 2.0 4 votes vote down vote up
@Test
public void unknownQuantifier() {
  Assertions.assertThrows(IllegalArgumentException.class,
      () -> PatternMatcher.compile(".+*"));
}
 
Example 14
Source File: ComplexTest.java    From commons-numbers with Apache License 2.0 4 votes vote down vote up
@Test
void testParseEmpty() {
    Assertions.assertThrows(NumberFormatException.class, () -> Complex.parse(""));
    Assertions.assertThrows(NumberFormatException.class, () -> Complex.parse(" "));
}
 
Example 15
Source File: SignatureTest.java    From symbol-sdk-java with Apache License 2.0 4 votes vote down vote up
@Test
public void byteArrayCtorFailsIfByteArrayIsTooSmall() {
    // Act:
    Assertions.assertThrows(IllegalArgumentException.class, () -> new Signature(new byte[63]));
}
 
Example 16
Source File: InfluxDBFactoryTest.java    From influxdb-java with MIT License 4 votes vote down vote up
@Test
public void testShouldThrowIllegalArgumentWithInvalidUrl() {
	Assertions.assertThrows(IllegalArgumentException.class,() -> {
		 InfluxDBFactory.connect("invalidUrl");
	});
}
 
Example 17
Source File: ChiSquaredDistributionTest.java    From commons-statistics with Apache License 2.0 4 votes vote down vote up
@Test
void testConstructorPrecondition1() {
    Assertions.assertThrows(DistributionException.class, () -> new ChiSquaredDistribution(0));
}
 
Example 18
Source File: ProxyConfigServiceTest.java    From cloudbreak with Apache License 2.0 4 votes vote down vote up
@Test
public void testDeleteByNameForAccountIdEmpty() {
    when(proxyConfigRepository.findByNameInAccount(NAME, ACCOUNT_ID)).thenReturn(Optional.empty());
    Assertions.assertThrows(NotFoundException.class, () -> underTestProxyConfigService.deleteByNameInAccount(NAME, ACCOUNT_ID));
}
 
Example 19
Source File: SignatureTest.java    From symbol-sdk-java with Apache License 2.0 4 votes vote down vote up
@Test
public void binaryCtorFailsIfByteArrayOfRIsTooLarge() {
    // Act:
    Assertions.assertThrows(IllegalArgumentException.class,
        () -> new Signature(new byte[33], new byte[32]));
}
 
Example 20
Source File: AbstractCanonCommandTest.java    From canon-sdk-java with MIT License 3 votes vote down vote up
@Test
void getExecutionDurationSinceNow() {
    Assertions.assertThrows(IllegalStateException.class, () -> doNothingCommand.getExecutionDurationSinceNow());

    doNothingCommand.run();

    final Duration duration = doNothingCommand.getExecutionDurationSinceNow();

    Assertions.assertNotNull(duration);
}