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
20
21
22
23 public class ExceptionListenerTestCase extends AbstractIBeansTestCase
24 {
25 @SuppressWarnings("unused")
26 @IntegrationBean
27 private TestExceptionIBean test;
28
29
30 @Test
31 public void testExceptionIsCaughtByListener() throws Exception
32 {
33 final AtomicBoolean exceptionThrown = new AtomicBoolean(false);
34 test.setExceptionListener(new ExceptionListener()
35 {
36 public void exceptionThrown(Exception e)
37 {
38 exceptionThrown.set(true);
39 }
40 });
41 String data = test.doSomething("blah");
42
43 assertTrue(exceptionThrown.get());
44 assertNull(data);
45 }
46
47 @Test
48 public void testExceptionOfDifferentTypeIsCaughtByListener() throws Exception
49 {
50 final AtomicBoolean exceptionThrown = new AtomicBoolean(false);
51 test.setExceptionListener(new ExceptionListener()
52 {
53 public void exceptionThrown(Exception e)
54 {
55 exceptionThrown.set(true);
56 assertTrue(e instanceof UnknownHostException);
57 }
58 });
59 String data = test.doSomethingElse();
60
61 assertTrue(exceptionThrown.get());
62 assertNull(data);
63 }
64 }
65