1
2
3
4
5
6
7
8
9
10 package org.mule.module.ibeans.annotations;
11
12 import java.beans.ExceptionListener;
13 import java.net.UnknownHostException;
14 import java.util.concurrent.atomic.AtomicBoolean;
15
16 import org.ibeans.annotation.IntegrationBean;
17 import org.junit.Test;
18
19 import static org.junit.Assert.assertNull;
20 import static org.junit.Assert.assertTrue;
21
22
23
24
25
26 public class ExceptionListenerTestCase extends AbstractIBeansTestCase
27 {
28 @IntegrationBean
29 private TestExceptionIBean test;
30
31 @Test
32 public void testExceptionIsCaughtByListener() throws Exception
33 {
34 final AtomicBoolean exceptionThrown = new AtomicBoolean(false);
35 test.setExceptionListener(new ExceptionListener()
36 {
37 @Override
38 public void exceptionThrown(Exception e)
39 {
40 exceptionThrown.set(true);
41 }
42 });
43 String data = test.doSomething("blah");
44
45 assertTrue(exceptionThrown.get());
46 assertNull(data);
47 }
48
49 @Test
50 public void testExceptionOfDifferentTypeIsCaughtByListener() throws Exception
51 {
52 final AtomicBoolean exceptionThrown = new AtomicBoolean(false);
53 test.setExceptionListener(new ExceptionListener()
54 {
55 @Override
56 public void exceptionThrown(Exception e)
57 {
58 exceptionThrown.set(true);
59 assertTrue(e instanceof UnknownHostException);
60 }
61 });
62 String data = test.doSomethingElse();
63
64 assertTrue(exceptionThrown.get());
65 assertNull(data);
66 }
67 }
68