View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.routing.filters;
8   
9   import org.mule.DefaultMuleMessage;
10  import org.mule.api.MuleContext;
11  import org.mule.api.MuleMessage;
12  import org.mule.message.DefaultExceptionPayload;
13  import org.mule.tck.junit4.AbstractMuleTestCase;
14  
15  import java.io.IOException;
16  
17  import org.junit.Test;
18  
19  import static org.junit.Assert.assertNull;
20  import static org.junit.Assert.assertTrue;
21  import static org.mockito.Mockito.mock;
22  
23  public class ExceptionTypeFilterTestCase extends AbstractMuleTestCase
24  {
25  
26      private MuleContext muleContext = mock(MuleContext.class);
27  
28      @Test
29      public void testExceptionTypeFilter()
30      {
31          ExceptionTypeFilter filter = new ExceptionTypeFilter();
32          assertNull(filter.getExpectedType());
33          MuleMessage m = new DefaultMuleMessage("test", muleContext);
34          assertTrue(!filter.accept(m));
35          m.setExceptionPayload(new DefaultExceptionPayload(new IllegalArgumentException("test")));
36          assertTrue(filter.accept(m));
37  
38          filter = new ExceptionTypeFilter(IOException.class);
39          assertTrue(!filter.accept(m));
40          m.setExceptionPayload(new DefaultExceptionPayload(new IOException("test")));
41          assertTrue(filter.accept(m));
42      }
43  
44  }