Unit test refactoring
- removed tests no longer useful now that all Intent objects are unique
- fixed intent object equality tests
- enabled several immutable base class tests
- renamed several Test....java classes to ...Test.Java to
match project best practices
Change-Id: Ic829d6d39556d2f63323f5e82f3807dba86c62ec
diff --git a/core/api/src/test/java/org/onlab/onos/net/intent/HostToHostIntentTest.java b/core/api/src/test/java/org/onlab/onos/net/intent/HostToHostIntentTest.java
index a6ce3dd..d1405b9 100644
--- a/core/api/src/test/java/org/onlab/onos/net/intent/HostToHostIntentTest.java
+++ b/core/api/src/test/java/org/onlab/onos/net/intent/HostToHostIntentTest.java
@@ -15,13 +15,17 @@
*/
package org.onlab.onos.net.intent;
-import org.junit.Ignore;
import org.junit.Test;
+import org.onlab.onos.TestApplicationId;
+import org.onlab.onos.core.ApplicationId;
import org.onlab.onos.net.HostId;
import org.onlab.onos.net.flow.TrafficSelector;
import com.google.common.testing.EqualsTester;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.is;
import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
import static org.onlab.onos.net.NetTestTools.APP_ID;
import static org.onlab.onos.net.NetTestTools.hid;
@@ -36,6 +40,28 @@
private final HostId id2 = hid("12:34:56:78:92:ab/1");
private final HostId id3 = hid("12:34:56:78:93:ab/1");
+ private static final ApplicationId APPID = new TestApplicationId("foo");
+
+ private HostToHostIntent makeHostToHost(HostId one, HostId two) {
+ return new HostToHostIntent(APPID, one, two, selector, treatment);
+ }
+
+ /**
+ * Tests the equals() method where two HostToHostIntents have references
+ * to the same hosts. These should compare equal.
+ */
+ @Test
+ public void testSameEquals() {
+
+ HostId one = hid("00:00:00:00:00:01/-1");
+ HostId two = hid("00:00:00:00:00:02/-1");
+ HostToHostIntent i1 = makeHostToHost(one, two);
+ HostToHostIntent i2 = makeHostToHost(one, two);
+
+ assertThat(i1.one(), is(equalTo(i2.one())));
+ assertThat(i1.two(), is(equalTo(i2.two())));
+ }
+
/**
* Checks that the HostToHostIntent class is immutable.
*/
@@ -47,18 +73,14 @@
/**
* Tests equals(), hashCode() and toString() methods.
*/
- @Test @Ignore("Equality is based on ids, which will be different")
+ @Test
public void testEquals() {
final HostToHostIntent intent1 = new HostToHostIntent(APP_ID,
id1,
id2,
selector,
treatment);
- final HostToHostIntent sameAsIntent1 = new HostToHostIntent(APP_ID,
- id1,
- id2,
- selector,
- treatment);
+
final HostToHostIntent intent2 = new HostToHostIntent(APP_ID,
id2,
id3,
@@ -66,7 +88,7 @@
treatment);
new EqualsTester()
- .addEqualityGroup(intent1, sameAsIntent1)
+ .addEqualityGroup(intent1)
.addEqualityGroup(intent2)
.testEquals();
}
diff --git a/core/api/src/test/java/org/onlab/onos/net/intent/IntentTest.java b/core/api/src/test/java/org/onlab/onos/net/intent/IntentTest.java
index ab805bf..2f675b7 100644
--- a/core/api/src/test/java/org/onlab/onos/net/intent/IntentTest.java
+++ b/core/api/src/test/java/org/onlab/onos/net/intent/IntentTest.java
@@ -15,15 +15,10 @@
*/
package org.onlab.onos.net.intent;
-import org.junit.Ignore;
-import org.junit.Test;
-
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
-import static org.junit.Assert.*;
-
/**
* Base facilities to test various intent tests.
*/
@@ -39,24 +34,6 @@
return new HashSet<>(Arrays.asList(items));
}
- @Test @Ignore("Equality is based on ids, which will be different")
- public void equalsAndHashCode() {
- Intent one = createOne();
- Intent like = createOne();
- Intent another = createAnother();
-
- assertTrue("should be equal", one.equals(like));
- assertEquals("incorrect hashCode", one.hashCode(), like.hashCode());
- assertFalse("should not be equal", one.equals(another));
- }
-
- //@Test FIXME
- public void testToString() {
- Intent one = createOne();
- Intent like = createOne();
- assertEquals("incorrect toString", one.toString(), like.toString());
- }
-
/**
* Creates a new intent, but always a like intent, i.e. all instances will
* be equal, but should not be the same.
diff --git a/core/api/src/test/java/org/onlab/onos/net/intent/LinkCollectionIntentTest.java b/core/api/src/test/java/org/onlab/onos/net/intent/LinkCollectionIntentTest.java
index 4b47734..f785196 100644
--- a/core/api/src/test/java/org/onlab/onos/net/intent/LinkCollectionIntentTest.java
+++ b/core/api/src/test/java/org/onlab/onos/net/intent/LinkCollectionIntentTest.java
@@ -20,7 +20,6 @@
import java.util.List;
import java.util.Set;
-import org.junit.Ignore;
import org.junit.Test;
import org.onlab.onos.net.ConnectPoint;
import org.onlab.onos.net.Link;
@@ -61,7 +60,7 @@
/**
* Tests equals(), hashCode() and toString() methods.
*/
- @Test @Ignore("Equality is based on ids, which will be different")
+ @Test
public void testEquals() {
final HashSet<Link> links1 = new HashSet<>();
@@ -72,12 +71,6 @@
treatment,
links1,
egress);
- final LinkCollectionIntent sameAsCollectionIntent1 =
- new LinkCollectionIntent(APP_ID,
- selector,
- treatment,
- links1,
- egress);
final HashSet<Link> links2 = new HashSet<>();
links2.add(link("src", 1, "dst", 3));
@@ -89,7 +82,7 @@
egress);
new EqualsTester()
- .addEqualityGroup(collectionIntent1, sameAsCollectionIntent1)
+ .addEqualityGroup(collectionIntent1)
.addEqualityGroup(collectionIntent2)
.testEquals();
}
diff --git a/core/api/src/test/java/org/onlab/onos/net/intent/MultiPointToSinglePointIntentTest.java b/core/api/src/test/java/org/onlab/onos/net/intent/MultiPointToSinglePointIntentTest.java
index 4ab3699..fd751ec 100644
--- a/core/api/src/test/java/org/onlab/onos/net/intent/MultiPointToSinglePointIntentTest.java
+++ b/core/api/src/test/java/org/onlab/onos/net/intent/MultiPointToSinglePointIntentTest.java
@@ -18,12 +18,21 @@
import org.junit.Test;
import static org.junit.Assert.assertEquals;
+import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
/**
* Suite of tests of the multi-to-single point intent descriptor.
*/
public class MultiPointToSinglePointIntentTest extends ConnectivityIntentTest {
+ /**
+ * Checks that the MultiPointToSinglePointIntent class is immutable.
+ */
+ @Test
+ public void checkImmutability() {
+ assertThatClassIsImmutable(MultiPointToSinglePointIntent.class);
+ }
+
@Test
public void basics() {
MultiPointToSinglePointIntent intent = createOne();
diff --git a/core/api/src/test/java/org/onlab/onos/net/intent/PointToPointIntentTest.java b/core/api/src/test/java/org/onlab/onos/net/intent/PointToPointIntentTest.java
index 67c728e..3fbd2b3 100644
--- a/core/api/src/test/java/org/onlab/onos/net/intent/PointToPointIntentTest.java
+++ b/core/api/src/test/java/org/onlab/onos/net/intent/PointToPointIntentTest.java
@@ -18,12 +18,21 @@
import org.junit.Test;
import static org.junit.Assert.assertEquals;
+import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutableBaseClass;
/**
* Suite of tests of the point-to-point intent descriptor.
*/
public class PointToPointIntentTest extends ConnectivityIntentTest {
+ /**
+ * Checks that the MultiPointToSinglePointIntent class is immutable.
+ */
+ @Test
+ public void checkImmutability() {
+ assertThatClassIsImmutableBaseClass(PointToPointIntent.class);
+ }
+
@Test
public void basics() {
PointToPointIntent intent = createOne();