[jboss-svn-commits] JBL Code SVN: r24419 - in labs/jbossrules/trunk/drools-container/drools-mc/src: test/java/org/drools/test/mc/io/test and 2 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Thu Dec 18 07:20:54 EST 2008
Author: alesj
Date: 2008-12-18 07:20:54 -0500 (Thu, 18 Dec 2008)
New Revision: 24419
Added:
labs/jbossrules/trunk/drools-container/drools-mc/src/test/resources/mc/io/equalstc/
labs/jbossrules/trunk/drools-container/drools-mc/src/test/resources/mc/io/equalstc/one.txt
Modified:
labs/jbossrules/trunk/drools-container/drools-mc/src/main/java/org/drools/mc/io/VFSResource.java
labs/jbossrules/trunk/drools-container/drools-mc/src/test/java/org/drools/test/mc/io/test/ResourcesTest.java
Log:
[JBRULES-1897]; impl equals, hash.
Modified: labs/jbossrules/trunk/drools-container/drools-mc/src/main/java/org/drools/mc/io/VFSResource.java
===================================================================
--- labs/jbossrules/trunk/drools-container/drools-mc/src/main/java/org/drools/mc/io/VFSResource.java 2008-12-18 12:20:38 UTC (rev 24418)
+++ labs/jbossrules/trunk/drools-container/drools-mc/src/main/java/org/drools/mc/io/VFSResource.java 2008-12-18 12:20:54 UTC (rev 24419)
@@ -167,4 +167,45 @@
{
return new InputStreamReader(getInputStream());
}
+
+ @Override
+ public int hashCode()
+ {
+ return toURL().hashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (obj instanceof VFSResource == false)
+ return false;
+
+ VFSResource other = VFSResource.class.cast(obj);
+ return toURL().equals(other.toURL());
+ }
+
+ @Override
+ public String toString()
+ {
+ return "[VFSResource = " + toURL() + "]";
+ }
+
+ /**
+ * To url.
+ *
+ * @return the url
+ * @throws RuntimeException for any error
+ */
+ protected URL toURL()
+ {
+ try
+ {
+ return getURL();
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
}
+
\ No newline at end of file
Modified: labs/jbossrules/trunk/drools-container/drools-mc/src/test/java/org/drools/test/mc/io/test/ResourcesTest.java
===================================================================
--- labs/jbossrules/trunk/drools-container/drools-mc/src/test/java/org/drools/test/mc/io/test/ResourcesTest.java 2008-12-18 12:20:38 UTC (rev 24418)
+++ labs/jbossrules/trunk/drools-container/drools-mc/src/test/java/org/drools/test/mc/io/test/ResourcesTest.java 2008-12-18 12:20:54 UTC (rev 24419)
@@ -23,6 +23,8 @@
import java.net.URL;
import java.util.Collection;
+import java.util.Set;
+import java.util.HashSet;
import org.drools.io.InternalResource;
import org.drools.io.Resource;
@@ -47,7 +49,7 @@
return provider;
}
- protected Resource testResource(String name)
+ protected Resource findResource(String name)
{
URL url = getResource(name);
ResourceProvider provider = getResourceProvider();
@@ -56,16 +58,40 @@
return root;
}
+ public void testEquals() throws Exception
+ {
+ Resource r1 = findResource("/mc/io/equalstc");
+ Resource r2 = findResource("/mc/io/equalstc");
+ assertTrue(r1 != r2);
+ assertEquals(r1, r2);
+ // hash test
+ Set<Resource> r = new HashSet<Resource>();
+ r.add(r1);
+ r.add(r2);
+ assertEquals(1, r.size());
+
+ assertTrue(r1 instanceof InternalResource);
+ assertTrue(r2 instanceof InternalResource);
+ Collection<Resource> c1 = InternalResource.class.cast(r1).listResources();
+ Collection<Resource> c2 = InternalResource.class.cast(r2).listResources();
+ assertEquals(c1, c2);
+ // hash test
+ Set<Resource> c = new HashSet<Resource>();
+ c.addAll(c1);
+ c.addAll(c2);
+ assertEquals(1, c.size());
+ }
+
public void testResource() throws Exception
{
- Resource resource = testResource("/mc/io/root");
+ Resource resource = findResource("/mc/io/root");
assertNotNull(resource.getInputStream());
assertNotNull(resource.getReader());
}
public void testInternalResource() throws Exception
{
- Resource root = testResource("/mc/io/root");
+ Resource root = findResource("/mc/io/root");
assertTrue(root instanceof InternalResource);
InternalResource resource = InternalResource.class.cast(root);
Added: labs/jbossrules/trunk/drools-container/drools-mc/src/test/resources/mc/io/equalstc/one.txt
===================================================================
--- labs/jbossrules/trunk/drools-container/drools-mc/src/test/resources/mc/io/equalstc/one.txt (rev 0)
+++ labs/jbossrules/trunk/drools-container/drools-mc/src/test/resources/mc/io/equalstc/one.txt 2008-12-18 12:20:54 UTC (rev 24419)
@@ -0,0 +1 @@
+Single file.
More information about the jboss-svn-commits
mailing list