diff --git a/common/reactive/src/test/java/io/helidon/common/reactive/SingleTest.java b/common/reactive/src/test/java/io/helidon/common/reactive/SingleTest.java index 4e17d7a9eb5..1cd3a05cce8 100644 --- a/common/reactive/src/test/java/io/helidon/common/reactive/SingleTest.java +++ b/common/reactive/src/test/java/io/helidon/common/reactive/SingleTest.java @@ -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. @@ -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 @@ -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 diff --git a/config/config-mp/src/test/java/io/helidon/config/mp/MpMetaConfigTest.java b/config/config-mp/src/test/java/io/helidon/config/mp/MpMetaConfigTest.java index c55697e9fcd..5e82e86e9c4 100644 --- a/config/config-mp/src/test/java/io/helidon/config/mp/MpMetaConfigTest.java +++ b/config/config-mp/src/test/java/io/helidon/config/mp/MpMetaConfigTest.java @@ -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. @@ -16,23 +16,18 @@ package io.helidon.config.mp; -import java.util.LinkedList; -import java.util.List; - import io.helidon.config.ConfigException; import org.eclipse.microprofile.config.Config; import org.eclipse.microprofile.config.ConfigProvider; import org.eclipse.microprofile.config.spi.ConfigProviderResolver; -import org.eclipse.microprofile.config.spi.ConfigSource; 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.hamcrest.Matchers.iterableWithSize; +import static org.junit.jupiter.api.Assertions.assertThrows; class MpMetaConfigTest { @@ -112,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 diff --git a/config/hocon-mp/src/test/java/io/helidon/config/hocon/mp/HoconJsonMpMetaConfigTest.java b/config/hocon-mp/src/test/java/io/helidon/config/hocon/mp/HoconJsonMpMetaConfigTest.java index b550e679551..ce45227201e 100644 --- a/config/hocon-mp/src/test/java/io/helidon/config/hocon/mp/HoconJsonMpMetaConfigTest.java +++ b/config/hocon-mp/src/test/java/io/helidon/config/hocon/mp/HoconJsonMpMetaConfigTest.java @@ -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. @@ -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; @@ -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"); } } diff --git a/config/yaml-mp/src/test/java/io/helidon/config/yaml/mp/YamlMpMetaConfigTest.java b/config/yaml-mp/src/test/java/io/helidon/config/yaml/mp/YamlMpMetaConfigTest.java index 97f887ab6da..d4de0228e55 100644 --- a/config/yaml-mp/src/test/java/io/helidon/config/yaml/mp/YamlMpMetaConfigTest.java +++ b/config/yaml-mp/src/test/java/io/helidon/config/yaml/mp/YamlMpMetaConfigTest.java @@ -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. @@ -22,7 +22,6 @@ import org.eclipse.microprofile.config.spi.ConfigProviderResolver; import org.eclipse.microprofile.config.spi.ConfigSource; 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; @@ -34,6 +33,7 @@ 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; @@ -126,9 +126,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"); } } diff --git a/security/jwt/src/test/java/io/helidon/security/jwt/SignedJwtTest.java b/security/jwt/src/test/java/io/helidon/security/jwt/SignedJwtTest.java index 3e426f4c815..bfda0d73ed3 100644 --- a/security/jwt/src/test/java/io/helidon/security/jwt/SignedJwtTest.java +++ b/security/jwt/src/test/java/io/helidon/security/jwt/SignedJwtTest.java @@ -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. @@ -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}. @@ -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"); } }