001: /* ====================================================================
002: The Jicarilla Software License
003:
004: Copyright (c) 2003 Leo Simons.
005: All rights reserved.
006:
007: Permission is hereby granted, free of charge, to any person obtaining
008: a copy of this software and associated documentation files (the
009: "Software"), to deal in the Software without restriction, including
010: without limitation the rights to use, copy, modify, merge, publish,
011: distribute, sublicense, and/or sell copies of the Software, and to
012: permit persons to whom the Software is furnished to do so, subject to
013: the following conditions:
014:
015: The above copyright notice and this permission notice shall be
016: included in all copies or substantial portions of the Software.
017:
018: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
019: EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
020: MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
021: IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
022: CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
023: TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
024: SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
025: ==================================================================== */
026: package org.jicarilla.lang.test;
027:
028: import org.jicarilla.lang.RegexpSelector;
029: import org.jicarilla.lang.TrueSelector;
030: import junit.framework.TestCase;
031:
032: import java.util.regex.Pattern;
033:
034: /**
035: * @author <a href="lsimons at jicarilla dot org">Leo Simons</a>
036: * @version $Id: RegexpSelectorTestCase.java,v 1.1 2003/12/10 20:37:24 lsimons
037: * Exp $
038: */
039: public class RegexpSelectorTestCase extends TestCase {
040: protected RegexpSelector m_selector;
041: protected RegexpSelector m_blahSelector;
042: protected RegexpSelector m_testSelector;
043:
044: public void setUp() {
045: m_selector = new RegexpSelector(Pattern.compile(".*"));
046: m_blahSelector = new RegexpSelector(Pattern.compile("blah.*"));
047: }
048:
049: public void testSelect() {
050: assertTrue(m_selector.select("blah"));
051: assertTrue(m_selector.select(new StringObj("blah")));
052: assertTrue(m_selector.select(null));
053:
054: assertTrue(m_blahSelector.select("blah"));
055: assertFalse(m_blahSelector.select("jodelahiti"));
056: assertFalse(m_blahSelector.select(null));
057: assertTrue(m_selector.select(new StringObj("blah")));
058: }
059:
060: public void testGetCriterion() {
061: Pattern p = Pattern.compile(".*");
062: m_selector = new RegexpSelector(p);
063: assertEquals(p, m_selector.getCriterion());
064: }
065:
066: public static class StringObj {
067: private String m_string;
068:
069: public StringObj(String string) {
070: m_string = string;
071: }
072:
073: public String toString() {
074: return m_string;
075: }
076: }
077:
078: RegexpSelector selector = new RegexpSelector(Pattern.compile("bla"));
079: RegexpSelector selector2 = new RegexpSelector(Pattern
080: .compile("bla"));
081: RegexpSelector selector3 = new RegexpSelector(Pattern.compile(".*"));
082: RegexpSelector selector4 = new RegexpSelector(Pattern
083: .compile("blah"));
084:
085: TrueSelector ts = new TrueSelector();
086:
087: public void testEquals() {
088: assertTrue(selector.equals(selector));
089: assertTrue(selector.equals(selector2));
090: assertFalse(selector.equals(selector3));
091: assertFalse(selector.equals(selector4));
092: assertFalse(selector.equals(null));
093: assertFalse(selector.equals(this ));
094: assertFalse(selector.equals(ts));
095:
096: assertFalse(selector3.equals(selector));
097: assertFalse(selector3.equals(selector4));
098: assertFalse(selector3.equals(null));
099: assertFalse(selector.equals(this ));
100: }
101:
102: public void testHashCode() {
103: assertEquals(selector.hashCode(), selector.hashCode());
104: assertEquals(selector.hashCode(), selector2.hashCode());
105: assertFalse(selector.hashCode() == selector3.hashCode());
106: assertFalse(selector.hashCode() == selector4.hashCode());
107:
108: assertEquals(selector3.hashCode(), selector3.hashCode());
109: assertFalse(selector3.hashCode() == selector.hashCode());
110: }
111: }
|