Add unit tests for FlowBatchId class.
- Changed toString() method to return the value in HEX string.
- Added unit tests for FlowBatchId class.
Change-Id: Ic6aa031dade552581081b359a31e40b680c8fbad
diff --git a/src/main/java/net/onrc/onos/api/flowmanager/FlowBatchId.java b/src/main/java/net/onrc/onos/api/flowmanager/FlowBatchId.java
index 6b71b2f..219f779 100644
--- a/src/main/java/net/onrc/onos/api/flowmanager/FlowBatchId.java
+++ b/src/main/java/net/onrc/onos/api/flowmanager/FlowBatchId.java
@@ -2,10 +2,15 @@
import java.util.Objects;
+import javax.annotation.concurrent.Immutable;
+
/**
* Represents ID for {@link FlowBatchOperation}.
+ * <p>
+ * This class is immutable.
*/
-public class FlowBatchId {
+@Immutable
+public final class FlowBatchId {
private final long id;
/**
@@ -17,7 +22,7 @@
@Override
public String toString() {
- return Long.toString(id);
+ return "0x" + Long.toHexString(id);
}
@Override
diff --git a/src/test/java/net/onrc/onos/api/flowmanager/FlowBatchIdTest.java b/src/test/java/net/onrc/onos/api/flowmanager/FlowBatchIdTest.java
new file mode 100644
index 0000000..cfde79e
--- /dev/null
+++ b/src/test/java/net/onrc/onos/api/flowmanager/FlowBatchIdTest.java
@@ -0,0 +1,68 @@
+package net.onrc.onos.api.flowmanager;
+
+import static net.onrc.onos.core.util.ImmutableClassChecker.assertThatClassIsImmutable;
+import static org.junit.Assert.assertEquals;
+import net.onrc.onos.core.util.TestUtils;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import com.google.common.testing.EqualsTester;
+
+/**
+ * Unit tests for {@link FlowBatchId} class.
+ */
+public class FlowBatchIdTest {
+ private FlowBatchId flowBatchId1;
+ private FlowBatchId flowBatchId2;
+ private FlowBatchId flowBatchId3;
+ private FlowBatchId flowBatchId4;
+ private FlowBatchId flowBatchId5;
+
+ @Before
+ public void setUp() {
+ flowBatchId1 = new FlowBatchId(0L);
+ flowBatchId2 = new FlowBatchId(1L);
+ flowBatchId3 = new FlowBatchId(2L);
+ flowBatchId4 = new FlowBatchId(1L);
+ flowBatchId5 = new FlowBatchId(0xABCDEFL);
+ }
+
+ /**
+ * Tests {@link FlowBatchId#FlowBatchId(long)} constructor.
+ */
+ @Test
+ public void testConstructor() {
+ assertEquals(0xABCDEFL, TestUtils.getField(flowBatchId5, "id"));
+ }
+
+ /**
+ * Tests the equality of {@link FlowBatchId} objects.
+ */
+ @Test
+ public void testEqualsAndHashCode() {
+ new EqualsTester()
+ .addEqualityGroup(flowBatchId1)
+ .addEqualityGroup(flowBatchId2, flowBatchId4)
+ .addEqualityGroup(flowBatchId3)
+ .addEqualityGroup(flowBatchId5)
+ .testEquals();
+ }
+
+ /**
+ * Tests {@link FlowBatchId#toString()} method.
+ */
+ @Test
+ public void testToString() {
+ assertEquals("0x0", flowBatchId1.toString());
+ assertEquals("0xabcdef", flowBatchId5.toString());
+ }
+
+ /**
+ * Tests if {@link FlowBatchId} is immutable.
+ */
+ @Test
+ public void testImmutable() {
+ assertThatClassIsImmutable(FlowBatchId.class);
+ }
+}