yangxk1 opened a new issue, #770:
URL: https://github.com/apache/incubator-graphar/issues/770

   ### Describe the enhancement requested
   
   Starting from JUnit 4.13 and in JUnit 5, the 
[Assert.assertThrows](https://junit.org/junit4/javadoc/latest/org/junit/Assert.html#assertThrows(java.lang.Class,%20org.junit.function.ThrowingRunnable))
 method is provided to test for expected exceptions in a more elegant and 
readable way. Compared to the traditional “try-catch + fail/assert” approach, 
`assertThrows` is the officially recommended best practice, as it improves code 
conciseness and maintainability.
   
   In the current test code of the java-info module, many test methods still 
use the legacy exception testing pattern. We recommend gradually replacing them 
with assertThrows to unify the code style and adhere to modern JUnit standards.
   
   Old method demo:
   
https://github.com/apache/incubator-graphar/blob/1bb04683f48ef9b0342d8378adc1deadc7318224/maven-projects/info/src/test/java/org/apache/graphar/info/VersionInfoTest.java#L113
   ```
       @Test
       public void testVersionInfoCheckTypeWithNullType() {
           VersionInfo versionInfo = new VersionInfo(1, null);
   
           // The current implementation doesn't handle null gracefully, so 
this will throw NPE
           try {
               versionInfo.checkType(null);
               Assert.fail("Expected NullPointerException");
           } catch (NullPointerException expected) {
               // This is the current behavior - null parameter causes NPE
           }
       }
   ```
   use assertThrows demo:
   ```
   IllegalArgumentException illegalArgumentException =
                   Assert.assertThrows(
                           IllegalArgumentException.class, () -> 
graphInfo.getVertexInfo("not_exist"));
           Assert.assertEquals(
                   "Vertex type not_exist not exist in graph ldbc_sample",
                   illegalArgumentException.getMessage());
   ```
   
   ### Component(s)
   
   Java


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@graphar.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@graphar.apache.org
For additional commands, e-mail: commits-h...@graphar.apache.org

Reply via email to