1 /* Licensed to the Apache Software Foundation (ASF) under one or more 2 * contributor license agreements. See the NOTICE file distributed with 3 * this work for additional information regarding copyright ownership. 4 * The ASF licenses this file to you under the Apache License, Version 2.0 5 * (the "License"); you may not use this file except in compliance with 6 * the License. You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package org.apache.myfaces.context; 17 18 import junit.framework.TestCase; 19 20 /** 21 * Regular Expression tests used within the faces context submodules 22 * 23 * @author Werner Punz(latest modification by $Author: struberg $) 24 * @version $Revision: 1188694 $ $Date: 2011-10-25 10:07:44 -0500 (Tue, 25 Oct 2011) $ 25 */ 26 public class ContextRegexpTest extends TestCase { 27 28 static final String RE_SPLITTER = "[\\s\\t\\r\\n]*\\,[\\s\\t\\r\\n]*"; 29 30 31 32 33 34 /** 35 * condition valid string 36 */ 37 public void testCondition1() { 38 String[] splitted = " hello ,world \n ,bla ".split(RE_SPLITTER); 39 splitted[0] = splitted[0].trim(); 40 int len = splitted.length-1; 41 if(len > 0) {//all others trimmed by the re 42 splitted[len] = splitted[len].trim(); 43 } 44 assertTrue("length assertion", splitted.length == 3); 45 assertTrue(splitted[0].trim().equals("hello")); 46 assertTrue(splitted[1].trim().equals("world")); 47 assertTrue(splitted[2].trim().equals("bla")); 48 } 49 50 /** 51 * test the condition 2 52 * empty string 53 */ 54 public void testCondition2() { 55 String[] splitted = " ".split(RE_SPLITTER); 56 assertTrue(splitted.length == 1); 57 assertTrue(splitted[0] != null); 58 } 59 60 /** 61 * test the condition 3 62 * empty string no blanks 63 */ 64 public void testCondition3() { 65 String[] splitted = "".split(RE_SPLITTER); 66 assertTrue(splitted.length == 1); 67 assertTrue(splitted[0] != null); 68 } 69 }