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-jxpath.git
commit 4349218887b5d504ff152040b1d8ddd4cd3e8c42 Author: Gary D. Gregory <[email protected]> AuthorDate: Tue Jul 29 16:16:40 2025 -0400 Use final --- .../apache/commons/jxpath/util/ValueUtilsTest.java | 74 +++++++++++----------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/src/test/java/org/apache/commons/jxpath/util/ValueUtilsTest.java b/src/test/java/org/apache/commons/jxpath/util/ValueUtilsTest.java index b97c9ef..f8afad8 100644 --- a/src/test/java/org/apache/commons/jxpath/util/ValueUtilsTest.java +++ b/src/test/java/org/apache/commons/jxpath/util/ValueUtilsTest.java @@ -37,6 +37,43 @@ import org.junit.jupiter.api.Test; class ValueUtilsTest { + public static class DummyHandler implements DynamicPropertyHandler { + + @Override + public Object getProperty(final Object object, final String propertyName) { + return null; + } + + @Override + public String[] getPropertyNames(final Object object) { + return new String[0]; + } + + @Override + public void setProperty(final Object object, final String propertyName, final Object value) { + + } + } + + @Test + void testGetDynamicPropertyHandlerConcurrently() throws InterruptedException, ExecutionException { + // This test ensures that ValueUtils::getDynamicPropertyHandler can be accessed concurrently + // It does not assert any specific behavior, but rather ensures that no exceptions are thrown on concurrent access + final int nThreads = 200; // Number of threads to simulate concurrent access + final List<Future<?>> futures = new ArrayList<>(); + final ExecutorService threadPool = Executors.newFixedThreadPool(nThreads); + for (int i = 0; i < nThreads; i++) { + futures.add(threadPool.submit(() -> ValueUtils.getDynamicPropertyHandler(DummyHandler.class))); + } + + threadPool.shutdown(); + threadPool.awaitTermination(1, TimeUnit.SECONDS); + + for (final Future<?> future : futures) { + future.get(); // This will throw if any thread threw + } + } + @Test void testGetValueFromArray() { final Object data = new Object(); @@ -95,41 +132,4 @@ class ValueUtilsTest { void testGetValueFromSetTooSmall() { assertNull(ValueUtils.getValue(Collections.EMPTY_SET, 2)); } - - @Test - void testGetDynamicPropertyHandlerConcurrently() throws InterruptedException, ExecutionException { - // This test ensures that ValueUtils::getDynamicPropertyHandler can be accessed concurrently - // It does not assert any specific behavior, but rather ensures that no exceptions are thrown on concurrent access - int nThreads = 200; // Number of threads to simulate concurrent access - List<Future<?>> futures = new ArrayList<>(); - ExecutorService threadPool = Executors.newFixedThreadPool(nThreads); - for (int i = 0; i < nThreads; i++) { - futures.add(threadPool.submit(() -> ValueUtils.getDynamicPropertyHandler(DummyHandler.class))); - } - - threadPool.shutdown(); - threadPool.awaitTermination(1, TimeUnit.SECONDS); - - for (Future<?> future : futures) { - future.get(); // This will throw if any thread threw - } - } - - public static class DummyHandler implements DynamicPropertyHandler { - - @Override - public Object getProperty(Object object, String propertyName) { - return null; - } - - @Override - public String[] getPropertyNames(Object object) { - return new String[0]; - } - - @Override - public void setProperty(Object object, String propertyName, Object value) { - - } - } }
