View Javadoc

1   /*
2    * $Id: FlagsMappingTestCase.java 22409 2011-07-14 05:14:27Z dirk.olmes $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.config.spring.parsers.specific;
12  
13  import org.mule.config.spring.parsers.specific.RegExFilterDefinitionParser.FlagsMapping;
14  import org.mule.tck.junit4.AbstractMuleTestCase;
15  
16  import java.util.regex.Pattern;
17  
18  import org.junit.Before;
19  import org.junit.Test;
20  
21  import static org.junit.Assert.assertEquals;
22  
23  public class FlagsMappingTestCase extends AbstractMuleTestCase
24  {
25      private FlagsMapping flagsMapping;
26  
27      @Before
28      public void setUp() throws Exception
29      {
30          flagsMapping = new FlagsMapping();
31      }
32  
33      @Test
34      public void testSetSingleFlagString()
35      {
36          int result = rewrite("DOTALL");
37          assertEquals(Pattern.DOTALL, result);
38      }
39  
40      @Test
41      public void testMultipleFlagsString()
42      {
43          int result = rewrite("DOTALL,MULTILINE");
44          assertEquals(Pattern.DOTALL | Pattern.MULTILINE, result);
45      }
46  
47      @Test(expected = IllegalArgumentException.class)
48      public void testInvalidFlagsString()
49      {
50          flagsMapping.rewrite("WRONG_FLAG");
51      }
52  
53      private int rewrite(String input)
54      {
55          Integer result = (Integer) flagsMapping.rewrite(input);
56          return result.intValue();
57      }
58  }