Skip to content

Commit 4349218

Browse files
committed
Use final
1 parent c53f325 commit 4349218

File tree

1 file changed

+37
-37
lines changed

1 file changed

+37
-37
lines changed

src/test/java/org/apache/commons/jxpath/util/ValueUtilsTest.java

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,43 @@
3737

3838
class ValueUtilsTest {
3939

40+
public static class DummyHandler implements DynamicPropertyHandler {
41+
42+
@Override
43+
public Object getProperty(final Object object, final String propertyName) {
44+
return null;
45+
}
46+
47+
@Override
48+
public String[] getPropertyNames(final Object object) {
49+
return new String[0];
50+
}
51+
52+
@Override
53+
public void setProperty(final Object object, final String propertyName, final Object value) {
54+
55+
}
56+
}
57+
58+
@Test
59+
void testGetDynamicPropertyHandlerConcurrently() throws InterruptedException, ExecutionException {
60+
// This test ensures that ValueUtils::getDynamicPropertyHandler can be accessed concurrently
61+
// It does not assert any specific behavior, but rather ensures that no exceptions are thrown on concurrent access
62+
final int nThreads = 200; // Number of threads to simulate concurrent access
63+
final List<Future<?>> futures = new ArrayList<>();
64+
final ExecutorService threadPool = Executors.newFixedThreadPool(nThreads);
65+
for (int i = 0; i < nThreads; i++) {
66+
futures.add(threadPool.submit(() -> ValueUtils.getDynamicPropertyHandler(DummyHandler.class)));
67+
}
68+
69+
threadPool.shutdown();
70+
threadPool.awaitTermination(1, TimeUnit.SECONDS);
71+
72+
for (final Future<?> future : futures) {
73+
future.get(); // This will throw if any thread threw
74+
}
75+
}
76+
4077
@Test
4178
void testGetValueFromArray() {
4279
final Object data = new Object();
@@ -95,41 +132,4 @@ void testGetValueFromSetNegativeIndex() {
95132
void testGetValueFromSetTooSmall() {
96133
assertNull(ValueUtils.getValue(Collections.EMPTY_SET, 2));
97134
}
98-
99-
@Test
100-
void testGetDynamicPropertyHandlerConcurrently() throws InterruptedException, ExecutionException {
101-
// This test ensures that ValueUtils::getDynamicPropertyHandler can be accessed concurrently
102-
// It does not assert any specific behavior, but rather ensures that no exceptions are thrown on concurrent access
103-
int nThreads = 200; // Number of threads to simulate concurrent access
104-
List<Future<?>> futures = new ArrayList<>();
105-
ExecutorService threadPool = Executors.newFixedThreadPool(nThreads);
106-
for (int i = 0; i < nThreads; i++) {
107-
futures.add(threadPool.submit(() -> ValueUtils.getDynamicPropertyHandler(DummyHandler.class)));
108-
}
109-
110-
threadPool.shutdown();
111-
threadPool.awaitTermination(1, TimeUnit.SECONDS);
112-
113-
for (Future<?> future : futures) {
114-
future.get(); // This will throw if any thread threw
115-
}
116-
}
117-
118-
public static class DummyHandler implements DynamicPropertyHandler {
119-
120-
@Override
121-
public Object getProperty(Object object, String propertyName) {
122-
return null;
123-
}
124-
125-
@Override
126-
public String[] getPropertyNames(Object object) {
127-
return new String[0];
128-
}
129-
130-
@Override
131-
public void setProperty(Object object, String propertyName, Object value) {
132-
133-
}
134-
}
135135
}

0 commit comments

Comments
 (0)