2  * Copyright 2005 the original author or authors.
 
   4  * Licensed under the Apache License, Version 2.0 (the "License");
 
   5  * you may not use this file except in compliance with the License.
 
   6  * You may obtain a copy of the License at
 
   8  *      http://www.apache.org/licenses/LICENSE-2.0
 
  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.
 
  17 package org.wamblee.conditions;
 
  19 import junit.framework.TestCase;
 
  22  * Tests {@link org.wamblee.conditions.PropertyRegexCondition}. 
 
  24 public class PropertyRegexConditionTest extends TestCase {
 
  26     private boolean match(String aProperty, String aRegex, boolean aToLower, TestBean aBean) { 
 
  27         PropertyRegexCondition<TestBean> condition = new PropertyRegexCondition<TestBean>(aProperty, aRegex, aToLower );
 
  28         return condition.matches(aBean);
 
  31     private void checkMatch(String aProperty, String aRegex, boolean aToLower, TestBean aBean, boolean aResult) { 
 
  32         assertEquals( aResult, match(aProperty, aRegex, aToLower, aBean)); 
 
  36      * Verifies correct matching behavior for several cases. 
 
  39     public void testMatchProperty() {
 
  40         TestBean bean = new TestBean("Hallo"); 
 
  41         checkMatch("value", "Hallo", false, bean, true); 
 
  42         checkMatch("value", "all", false, bean, false);
 
  43         checkMatch("value", ".a.*o", false, bean, true);
 
  44         checkMatch("value", "hallo", false, bean, false); // no match when not converting to lower case.
 
  45         checkMatch("value", "hallo", true, bean, true); // match!
 
  49      * Uses property regex condition for non-existing property. 
 
  50      * Verifies that a runtime exception is thrown. 
 
  53     public void testWrongProperty() { 
 
  54         TestBean bean = new TestBean("Hallo");
 
  56            match("bla", ".*", false, bean);       
 
  57         } catch (RuntimeException e) { 
 
  64      * Applies condition to a private property. Verifies that a runtime 
 
  65      * exception is thrown. 
 
  68     public void testPrivateProperty() { 
 
  69         TestBean bean = new TestBean("Hallo");
 
  71            match("privateValue", ".*", false, bean);       
 
  72         } catch (RuntimeException e) {