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.config.spring.parsers.specific;
8   
9   import org.mule.config.spring.parsers.specific.RegExFilterDefinitionParser.FlagsMapping;
10  import org.mule.tck.junit4.AbstractMuleTestCase;
11  
12  import java.util.regex.Pattern;
13  
14  import org.junit.Before;
15  import org.junit.Test;
16  
17  import static org.junit.Assert.assertEquals;
18  import static org.junit.Assert.fail;
19  
20  public class FlagsMappingTestCase extends AbstractMuleTestCase
21  {
22  
23      private FlagsMapping flagsMapping;
24  
25      @Before
26      public void setUp() throws Exception
27      {
28          flagsMapping = new FlagsMapping();
29      }
30  
31      @Test
32      public void testSetSingleFlagString()
33      {
34          int result = rewrite("DOTALL");
35          assertEquals(Pattern.DOTALL, result);
36      }
37  
38      @Test
39      public void testMultipleFlagsString()
40      {
41          int result = rewrite("DOTALL,MULTILINE");
42          assertEquals(Pattern.DOTALL | Pattern.MULTILINE, result);
43      }
44  
45      @Test(expected = IllegalArgumentException.class)
46      public void testInvalidFlagsString()
47      {
48          flagsMapping.rewrite("WRONG_FLAG");
49      }
50  
51      private int rewrite(String input)
52      {
53          Integer result = (Integer) flagsMapping.rewrite(input);
54          return result.intValue();
55      }
56  }