Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3.x Replace try/catch in tests on assertThrows #7344

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, 2021 Oracle and/or its affiliates.
* Copyright (c) 2020, 2023 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -262,11 +262,7 @@ public void testMap() {

@Test
public void testMapNullMapper() {
try {
Single.just("foo").map(null);
fail("NullPointerException should be thrown");
} catch (NullPointerException ex) {
}
assertThrows(NullPointerException.class, () -> Single.just("foo").map(null), "NullPointerException should be thrown");
}

@Test
Expand Down Expand Up @@ -375,11 +371,7 @@ public void testNeverFlatMap() {

@Test
public void testFlatMapNullMapper() {
try {
Single.just("bar").flatMap(null);
fail("NullPointerException should have been thrown");
} catch (NullPointerException ex) {
}
assertThrows(NullPointerException.class, () -> Single.just("bar").flatMap(null), "NullPointerException should have been thrown");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, 2022 Oracle and/or its affiliates.
* Copyright (c) 2021, 2023 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -21,13 +21,13 @@
import org.eclipse.microprofile.config.ConfigProvider;
import org.eclipse.microprofile.config.spi.ConfigProviderResolver;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;


class MpMetaConfigTest {
Expand Down Expand Up @@ -107,10 +107,7 @@ void testMetaPropertiesPathProfile() {
void testMetaPropertiesNotOptional() {
System.setProperty(MpMetaConfig.META_CONFIG_SYSTEM_PROPERTY,
"custom-mp-meta-config-not-optional.properties");
try {
config = ConfigProvider.getConfig();
Assertions.fail("Expecting meta-config to fail due to not optional non-existent config source");
} catch (ConfigException e) {}
assertThrows(ConfigException.class, ConfigProvider::getConfig, "Expecting meta-config to fail due to not optional non-existent config source");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Oracle and/or its affiliates.
* Copyright (c) 2022, 2023 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -22,13 +22,13 @@
import org.eclipse.microprofile.config.ConfigProvider;
import org.eclipse.microprofile.config.spi.ConfigProviderResolver;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;

class HoconJsonMpMetaConfigTest {
private static ConfigProviderResolver configResolver;
Expand Down Expand Up @@ -150,9 +150,6 @@ void testMetaOrdinal() {
@Test
void testMetaHoconNonExistentNotOptional() {
System.setProperty(META_CONFIG_SYSTEM_PROPERTY, "custom-mp-meta-config-hocon-path-not-optional.yaml");
try {
config = ConfigProvider.getConfig();
Assertions.fail("Expecting meta-config to fail due to not optional non-existent config source");
} catch (ConfigException e) {}
assertThrows(ConfigException.class, ConfigProvider::getConfig, "Expecting meta-config to fail due to not optional non-existent config source");
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Oracle and/or its affiliates.
* Copyright (c) 2022, 2023 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -21,13 +21,13 @@
import org.eclipse.microprofile.config.ConfigProvider;
import org.eclipse.microprofile.config.spi.ConfigProviderResolver;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;

class YamlMpMetaConfigTest {
private static ConfigProviderResolver configResolver;
Expand Down Expand Up @@ -120,9 +120,6 @@ void testMetaOrdinal() {
@Test
void testMetaNonExistentNotOptional() {
System.setProperty(META_CONFIG_SYSTEM_PROPERTY, "custom-mp-meta-config-path-not-optional.yaml");
try {
config = ConfigProvider.getConfig();
Assertions.fail("Expecting meta-config to fail due to not optional non-existent config source");
} catch (ConfigException e) {}
assertThrows(ConfigException.class, ConfigProvider::getConfig, "Expecting meta-config to fail due to not optional non-existent config source");
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2021 Oracle and/or its affiliates.
* Copyright (c) 2018, 2023 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -31,7 +31,6 @@
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.fail;

/**
* Unit test for {@link SignedJwt}.
Expand Down Expand Up @@ -94,12 +93,8 @@ public void testParsingInvalidEncodingOnTokenParts() {
{"payload", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9+lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c"},
{"signature", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV/adQssw5c"}
};
for (int i=0; i < tokens.length; i++) {
try {
SignedJwt.parseToken(tokens[i][1]);
fail("Parsing should have failed as the token " + tokens[i][0] + " is incorrectly encoded");
} catch (JwtException t) {
}
for (String[] token : tokens) {
assertThrows(JwtException.class, () -> SignedJwt.parseToken(token[1]), "Parsing should have failed as the token " + token[0] + " is incorrectly encoded");
}
}

Expand Down
Loading