|
1 | 1 | package com.baeldung.commons.lang3; |
2 | 2 |
|
3 | 3 | import static org.junit.Assert.assertArrayEquals; |
| 4 | +import static org.junit.Assert.assertEquals; |
4 | 5 | import static org.junit.Assert.assertFalse; |
5 | 6 | import static org.junit.Assert.assertNotSame; |
6 | 7 | import static org.junit.Assert.assertSame; |
|
12 | 13 | import java.io.File; |
13 | 14 | import java.lang.reflect.Field; |
14 | 15 | import java.util.Locale; |
| 16 | +import java.util.concurrent.ExecutionException; |
15 | 17 | import java.util.concurrent.Future; |
16 | 18 |
|
17 | 19 | import org.apache.commons.lang3.ArchUtils; |
18 | 20 | import org.apache.commons.lang3.BooleanUtils; |
19 | 21 | import org.apache.commons.lang3.SystemUtils; |
20 | 22 | import org.apache.commons.lang3.arch.Processor; |
| 23 | +import org.apache.commons.lang3.concurrent.ConcurrentException; |
21 | 24 | import org.apache.commons.lang3.concurrent.ConcurrentRuntimeException; |
22 | 25 | import org.apache.commons.lang3.concurrent.ConcurrentUtils; |
23 | 26 | import org.apache.commons.lang3.event.EventUtils; |
@@ -97,22 +100,37 @@ public void test_getInstance_String_Locale() { |
97 | 100 | public void testAddEventListenerThrowsException() { |
98 | 101 | final ExceptionEventSource src = new ExceptionEventSource(); |
99 | 102 | try { |
100 | | - EventUtils.addEventListener(src, PropertyChangeListener.class, new PropertyChangeListener() { |
101 | | - @Override |
102 | | - public void propertyChange(final PropertyChangeEvent e) { |
103 | | - // Do nothing! |
104 | | - } |
105 | | - }); |
| 103 | + EventUtils.addEventListener(src, PropertyChangeListener.class, (PropertyChangeEvent e) -> { |
| 104 | + /* Change event*/}); |
106 | 105 | fail("Add method should have thrown an exception, so method should fail."); |
107 | 106 | } catch (final RuntimeException e) { |
108 | 107 |
|
109 | 108 | } |
110 | 109 | } |
111 | 110 |
|
| 111 | + @Test |
| 112 | + public void ConcurrentExceptionSample() throws ConcurrentException { |
| 113 | + final Error err = new AssertionError("Test"); |
| 114 | + try { |
| 115 | + ConcurrentUtils.handleCause(new ExecutionException(err)); |
| 116 | + fail("Error not thrown!"); |
| 117 | + } catch (final Error e) { |
| 118 | + assertEquals("Wrong error", err, e); |
| 119 | + } |
| 120 | + } |
| 121 | + |
112 | 122 | public static class ExceptionEventSource { |
113 | 123 | public void addPropertyChangeListener(final PropertyChangeListener listener) { |
114 | 124 | throw new RuntimeException(); |
115 | 125 | } |
116 | 126 | } |
117 | 127 |
|
| 128 | + @Test |
| 129 | + public void testLazyInitializer() throws Exception { |
| 130 | + SampleLazyInitializer sampleLazyInitializer = new SampleLazyInitializer(); |
| 131 | + SampleObject sampleObjectOne = sampleLazyInitializer.get(); |
| 132 | + SampleObject sampleObjectTwo = sampleLazyInitializer.get(); |
| 133 | + assertEquals(sampleObjectOne, sampleObjectTwo); |
| 134 | + } |
| 135 | + |
118 | 136 | } |
0 commit comments