This is an automated email from the ASF dual-hosted git repository.

gnodet pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven.git


The following commit(s) were added to refs/heads/master by this push:
     new e914c3a0de Assert toolchains builder throws on bad input (#13949)
e914c3a0de is described below

commit e914c3a0de9ec1994f1c83d6895d0af705707370
Author: Sharang Gupta <[email protected]>
AuthorDate: Thu Nov 12 16:19:11 2026 +0000

    Assert toolchains builder throws on bad input (#13949)
    
    testStrictToolchainsParseException and testIOException only checked the
    message inside a catch block, so they passed even when build() returned
    normally. Use assertThrows so a missing ToolchainsBuildingException
    fails the tests.
---
 .../building/DefaultToolchainsBuilderTest.java     | 29 ++++++++++------------
 1 file changed, 13 insertions(+), 16 deletions(-)

diff --git 
a/compat/maven-toolchain-builder/src/test/java/org/apache/maven/toolchain/building/DefaultToolchainsBuilderTest.java
 
b/compat/maven-toolchain-builder/src/test/java/org/apache/maven/toolchain/building/DefaultToolchainsBuilderTest.java
index ba5e543a99..1fbb9a6bf0 100644
--- 
a/compat/maven-toolchain-builder/src/test/java/org/apache/maven/toolchain/building/DefaultToolchainsBuilderTest.java
+++ 
b/compat/maven-toolchain-builder/src/test/java/org/apache/maven/toolchain/building/DefaultToolchainsBuilderTest.java
@@ -45,6 +45,7 @@
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.doThrow;
@@ -198,14 +199,12 @@ void testStrictToolchainsParseException() throws 
Exception {
         ToolchainsParseException parseException = new 
ToolchainsParseException("MESSAGE", 4, 2);
         
doThrow(parseException).when(toolchainsReader).read(any(InputStream.class), 
ArgumentMatchers.anyMap());
 
-        try {
-            toolchainBuilder.build(request);
-        } catch (ToolchainsBuildingException e) {
-            assertEquals(
-                    "1 problem was encountered while building the effective 
toolchains" + LS
-                            + "[FATAL] Non-parseable toolchains (memory): 
MESSAGE @ line 4, column 2" + LS,
-                    e.getMessage());
-        }
+        ToolchainsBuildingException e =
+                assertThrows(ToolchainsBuildingException.class, () -> 
toolchainBuilder.build(request));
+        assertEquals(
+                "1 problem was encountered while building the effective 
toolchains" + LS
+                        + "[FATAL] Non-parseable toolchains (memory): MESSAGE 
@ line 4, column 2" + LS,
+                e.getMessage());
     }
 
     @Test
@@ -218,14 +217,12 @@ void testIOException() throws Exception {
         ToolchainsBuildingRequest request = new 
DefaultToolchainsBuildingRequest();
         request.setGlobalToolchainsSource(src);
 
-        try {
-            toolchainBuilder.build(request);
-        } catch (ToolchainsBuildingException e) {
-            assertEquals(
-                    "1 problem was encountered while building the effective 
toolchains" + LS
-                            + "[FATAL] Non-readable toolchains LOCATION: 
MESSAGE" + LS,
-                    e.getMessage());
-        }
+        ToolchainsBuildingException e =
+                assertThrows(ToolchainsBuildingException.class, () -> 
toolchainBuilder.build(request));
+        assertEquals(
+                "1 problem was encountered while building the effective 
toolchains" + LS
+                        + "[FATAL] Non-readable toolchains LOCATION: MESSAGE" 
+ LS,
+                e.getMessage());
     }
 
     @Test

Reply via email to