refactored junk main test into junit test


git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@919370 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/sigil/common/obr.test/.classpath b/sigil/common/obr.test/.classpath
new file mode 100644
index 0000000..c9ffd60
--- /dev/null
+++ b/sigil/common/obr.test/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" path="src"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+	<classpathentry kind="con" path="org.apache.felix.sigil.classpathContainer"/>
+	<classpathentry kind="output" path="build/classes"/>
+</classpath>
diff --git a/sigil/common/obr.test/.project b/sigil/common/obr.test/.project
new file mode 100644
index 0000000..f952bce
--- /dev/null
+++ b/sigil/common/obr.test/.project
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>org.apache.felix.sigil.common.obr.test</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.apache.felix.sigil.eclipse.core.sigilBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.apache.felix.sigil.sigilnature</nature>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+	</natures>
+</projectDescription>
diff --git a/sigil/common/obr.test/sigil.properties b/sigil/common/obr.test/sigil.properties
new file mode 100644
index 0000000..2945c8f
--- /dev/null
+++ b/sigil/common/obr.test/sigil.properties
@@ -0,0 +1,18 @@
+
+# sigil project file, saved by plugin.
+
+-bundles: \
+	org.apache.felix.sigil.common.obr.test, \
+
+-sourcedirs: \
+	src, \
+
+-fragment: \
+	org.apache.felix.sigil.common.obr;version=0.9.0, \
+
+-imports: \
+	junit.framework, \
+	org.osgi.framework, \
+	org.apache.felix.sigil.common.osgi;version=0.9.0, \
+
+# end
diff --git a/sigil/common/obr.test/src/org/apache/felix/sigil/obr/impl/VersionRangeHelperTest.java b/sigil/common/obr.test/src/org/apache/felix/sigil/obr/impl/VersionRangeHelperTest.java
new file mode 100644
index 0000000..8835c4b
--- /dev/null
+++ b/sigil/common/obr.test/src/org/apache/felix/sigil/obr/impl/VersionRangeHelperTest.java
@@ -0,0 +1,147 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.felix.sigil.obr.impl;
+
+import org.apache.felix.sigil.common.osgi.LDAPExpr;
+import org.apache.felix.sigil.common.osgi.LDAPParser;
+import org.apache.felix.sigil.common.osgi.VersionRange;
+import org.osgi.framework.Version;
+
+import junit.framework.TestCase;
+
+public class VersionRangeHelperTest extends TestCase
+{
+    public void testRange1() {
+        LDAPExpr expr;
+        VersionRange range;
+        
+        expr = LDAPParser.parseExpression("(&(version>=1.0.0)(version<=2.0.0))" );
+        range = VersionRangeHelper.decodeVersions( expr );
+        assertEquals( VersionRange.parseVersionRange("[1.0.0,2.0.0]"), range );
+    }
+    
+    public void testRange2() {
+        LDAPExpr expr;
+        VersionRange range;
+            
+        expr = LDAPParser.parseExpression("(&(version>1.0.0)(version<2.0.0))");
+        range = VersionRangeHelper.decodeVersions( expr );
+        assertEquals( VersionRange.parseVersionRange("(1.0.0,2.0.0)"), range );        
+    }
+    
+    public void testRange3() {
+        LDAPExpr expr;
+        VersionRange range;
+
+        expr = LDAPParser.parseExpression("(&(!(version<1.0.0))(!(version>2.0.0)))");
+        range = VersionRangeHelper.decodeVersions( expr );
+        assertEquals( VersionRange.parseVersionRange("[1.0.0,2.0.0]"), range );
+    }
+    
+    public void testRange4() {
+        LDAPExpr expr;
+        VersionRange range;
+
+        expr = LDAPParser.parseExpression("(&(!(version<=1.0.0))(!(version>=2.0.0)))");
+        range = VersionRangeHelper.decodeVersions( expr );
+        assertEquals( VersionRange.parseVersionRange("(1.0.0,2.0.0)"), range );
+    }
+    
+    public void testRange5() {
+        LDAPExpr expr;
+        VersionRange range;
+        
+        expr = LDAPParser.parseExpression("(version=1.0.0)");
+        range = VersionRangeHelper.decodeVersions( expr );
+        assertEquals( VersionRange.parseVersionRange("[1.0.0,1.0.0]"), range );
+    }
+    
+    public void testRange6() {
+        LDAPExpr expr;
+        VersionRange range;
+        
+        expr = LDAPParser.parseExpression("(version>=1.0.0)");
+        range = VersionRangeHelper.decodeVersions( expr );
+        assertEquals( new VersionRange(false, new Version(1,0,0), VersionRange.INFINITE_VERSION, true ), range );
+    }
+    
+    public void testRange7() {
+        LDAPExpr expr;
+        VersionRange range;
+        
+        expr = LDAPParser.parseExpression("(version<=2.0.0)");
+        range = VersionRangeHelper.decodeVersions( expr );
+        assertEquals( VersionRange.parseVersionRange("[0,2.0.0]"), range );
+    }
+    
+    public void testRange8() {
+        LDAPExpr expr;
+        VersionRange range;
+        
+        expr = LDAPParser.parseExpression("(version>1.0.0)");
+        range = VersionRangeHelper.decodeVersions( expr );
+        assertEquals( new VersionRange(true, new Version(1,0,0), VersionRange.INFINITE_VERSION, true ), range );
+    }
+    
+    public void testRange9() {
+        LDAPExpr expr;
+        VersionRange range;
+        
+        expr = LDAPParser.parseExpression("(version<2.0.0)");
+        range = VersionRangeHelper.decodeVersions( expr );
+        assertEquals( VersionRange.parseVersionRange("[0,2.0.0)"), range );
+    }
+    
+    public void testRange10() {
+        LDAPExpr expr;
+        VersionRange range;
+        
+        expr = LDAPParser.parseExpression("(!(version>2.0.0))");
+        range = VersionRangeHelper.decodeVersions( expr );
+        assertEquals( VersionRange.parseVersionRange("[0,2.0.0]"), range );
+    }
+    
+    public void testRange11() {
+        LDAPExpr expr;
+        VersionRange range;
+        
+        expr = LDAPParser.parseExpression("(!(version<1.0.0))");
+        range = VersionRangeHelper.decodeVersions( expr );
+        assertEquals( VersionRange.parseVersionRange("1.0.0"), range );
+    }
+    
+    public void testRange12() {
+        LDAPExpr expr;
+        VersionRange range;
+        
+        expr = LDAPParser.parseExpression("(!(version>=2.0.0))");
+        range = VersionRangeHelper.decodeVersions( expr );
+        assertEquals( VersionRange.parseVersionRange("[0,2.0.0)"), range );
+    }
+    
+    public void testRange13() {
+        LDAPExpr expr;
+        VersionRange range;
+        
+        expr = LDAPParser.parseExpression("(!(version<=1.0.0))");
+        range = VersionRangeHelper.decodeVersions( expr );
+        assertEquals( new VersionRange(true, new Version(1,0,0), VersionRange.INFINITE_VERSION, true ), range );
+    }
+}
diff --git a/sigil/common/obr/src/org/apache/felix/sigil/obr/impl/VersionRangeHelper.java b/sigil/common/obr/src/org/apache/felix/sigil/obr/impl/VersionRangeHelper.java
index f25babb..9cdb6e0 100644
--- a/sigil/common/obr/src/org/apache/felix/sigil/obr/impl/VersionRangeHelper.java
+++ b/sigil/common/obr/src/org/apache/felix/sigil/obr/impl/VersionRangeHelper.java
@@ -24,8 +24,6 @@
 import java.util.List;
 
 import org.apache.felix.sigil.common.osgi.LDAPExpr;
-import org.apache.felix.sigil.common.osgi.LDAPParseException;
-import org.apache.felix.sigil.common.osgi.LDAPParser;
 import org.apache.felix.sigil.common.osgi.Not;
 import org.apache.felix.sigil.common.osgi.Ops;
 import org.apache.felix.sigil.common.osgi.SimpleTerm;
@@ -34,21 +32,10 @@
 import org.osgi.framework.Version;
 
 
-class VersionRangeHelper
+public class VersionRangeHelper
 {
 
-    // e.g. (&(version>=1.0.0)(version<=2.0.0)) (&(version>1.0.0)(version<2.0.0)) (&(!(version<1.0.0))(!(version>2.0.0))) (&(!(version<=1.0.0))(!(version>=2.0.0))) (version=1.0.0) (version>=1.0.0) (version<=2.0.0) (version>1.0.0) (version<2.0.0)  (!(version>2.0.0)) (!(version<1.0.0)) (!(version>=2.0.0)) (!(version<=1.0.0))
-    public static void main( String[] args ) throws LDAPParseException
-    {
-        for ( String arg : args )
-        {
-            LDAPExpr expr = LDAPParser.parseExpression( arg.trim() );
-            System.out.println( expr + " -> " + decodeVersions( expr ) );
-        }
-    }
-
-
-    static VersionRange decodeVersions( LDAPExpr expr ) throws NumberFormatException
+    public static VersionRange decodeVersions( LDAPExpr expr ) throws NumberFormatException
     {
         ArrayList<LDAPExpr> terms = new ArrayList<LDAPExpr>( 1 );