This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-lang.git
commit d45f23e9579196e552afda6eb6baccf8d782c640 Author: Gary D. Gregory <garydgreg...@gmail.com> AuthorDate: Wed Aug 20 18:24:10 2025 -0400 Refactor some exception tests --- .../lang3/concurrent/ConcurrentExceptionTest.java | 60 ++++++++++++++++++++++ .../concurrent/ConcurrentRuntimeExceptionTest.java | 52 +++++++++++++++++++ .../lang3/concurrent/ConcurrentUtilsTest.java | 56 +------------------- 3 files changed, 113 insertions(+), 55 deletions(-) diff --git a/src/test/java/org/apache/commons/lang3/concurrent/ConcurrentExceptionTest.java b/src/test/java/org/apache/commons/lang3/concurrent/ConcurrentExceptionTest.java new file mode 100644 index 000000000..41eca1b6d --- /dev/null +++ b/src/test/java/org/apache/commons/lang3/concurrent/ConcurrentExceptionTest.java @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.commons.lang3.concurrent; + +import static org.apache.commons.lang3.LangAssertions.assertIllegalArgumentException; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; + +import org.junit.jupiter.api.Test; + +/** + * Tests {@link ConcurrentException}. + */ +class ConcurrentExceptionTest { + + /** + * Tests creating a ConcurrentException with an error as cause. + */ + @Test + void testCauseError() { + assertIllegalArgumentException(() -> new ConcurrentException("An error", new Error())); + } + + /** + * Tests creating a ConcurrentException with null as cause. + */ + @Test + void testCauseNull() { + assertIllegalArgumentException(() -> new ConcurrentException((Throwable) null)); + } + + @Test + void testCauseString() { + assertEquals("test", new ConcurrentException("test").getMessage()); + assertNull(new ConcurrentException((String) null).getMessage()); + } + + /** + * Tests creating a ConcurrentException with a runtime exception as cause. + */ + @Test + void testCauseUnchecked() { + assertIllegalArgumentException(() -> new ConcurrentException(new RuntimeException())); + } +} diff --git a/src/test/java/org/apache/commons/lang3/concurrent/ConcurrentRuntimeExceptionTest.java b/src/test/java/org/apache/commons/lang3/concurrent/ConcurrentRuntimeExceptionTest.java new file mode 100644 index 000000000..3c529dff9 --- /dev/null +++ b/src/test/java/org/apache/commons/lang3/concurrent/ConcurrentRuntimeExceptionTest.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.commons.lang3.concurrent; + +import static org.apache.commons.lang3.LangAssertions.assertIllegalArgumentException; + +import org.junit.jupiter.api.Test; + +/** + * Tests {@link ConcurrentRuntimeException}. + */ +class ConcurrentRuntimeExceptionTest { + + /** + * Tries to create a ConcurrentRuntimeException with an error as cause. + */ + @Test + void testCauseError() { + assertIllegalArgumentException(() -> new ConcurrentRuntimeException("An error", new Error())); + } + + /** + * Tries to create a ConcurrentRuntimeException with null as cause. + */ + @Test + void testCauseNull() { + assertIllegalArgumentException(() -> new ConcurrentRuntimeException(null)); + } + + /** + * Tries to create a ConcurrentRuntimeException with a runtime as cause. + */ + @Test + void testCauseUnchecked() { + assertIllegalArgumentException(() -> new ConcurrentRuntimeException(new RuntimeException())); + } +} diff --git a/src/test/java/org/apache/commons/lang3/concurrent/ConcurrentUtilsTest.java b/src/test/java/org/apache/commons/lang3/concurrent/ConcurrentUtilsTest.java index 8e12f3061..dc925aada 100644 --- a/src/test/java/org/apache/commons/lang3/concurrent/ConcurrentUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/concurrent/ConcurrentUtilsTest.java @@ -14,9 +14,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.apache.commons.lang3.concurrent; -import static org.apache.commons.lang3.LangAssertions.assertIllegalArgumentException; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -39,60 +39,6 @@ * Test class for {@link ConcurrentUtils}. */ class ConcurrentUtilsTest extends AbstractLangTest { - /** - * Tests creating a ConcurrentException with an error as cause. - */ - @Test - void testConcurrentExceptionCauseError() { - assertIllegalArgumentException(() -> new ConcurrentException("An error", new Error())); - } - - /** - * Tests creating a ConcurrentException with null as cause. - */ - @Test - void testConcurrentExceptionCauseNull() { - assertIllegalArgumentException(() -> new ConcurrentException((Throwable) null)); - } - - @Test - void testConcurrentExceptionCauseString() { - assertEquals("test", new ConcurrentException("test").getMessage()); - assertNull(new ConcurrentException((String) null).getMessage()); - } - - /** - * Tests creating a ConcurrentException with a runtime exception as cause. - */ - @Test - void testConcurrentExceptionCauseUnchecked() { - assertIllegalArgumentException(() -> new ConcurrentException(new RuntimeException())); - } - - /** - * Tries to create a ConcurrentRuntimeException with an error as cause. - */ - @Test - void testConcurrentRuntimeExceptionCauseError() { - assertIllegalArgumentException(() -> new ConcurrentRuntimeException("An error", new Error())); - } - - /** - * Tries to create a ConcurrentRuntimeException with null as cause. - */ - @Test - void testConcurrentRuntimeExceptionCauseNull() { - assertIllegalArgumentException(() -> new ConcurrentRuntimeException(null)); - } - - /** - * Tries to create a ConcurrentRuntimeException with a runtime as cause. - */ - @Test - void testConcurrentRuntimeExceptionCauseUnchecked() { - assertIllegalArgumentException(() -> new ConcurrentRuntimeException(new RuntimeException())); - } - /** * Tests constant future. *