GUI -- Table Model et al -- added missing unit tests.
Change-Id: Icc77457cab5b79724fcb5b354c2d74f2b2690d89
diff --git a/core/api/src/test/java/org/onosproject/ui/table/cell/AbstractCellComparatorTest.java b/core/api/src/test/java/org/onosproject/ui/table/cell/AbstractCellComparatorTest.java
new file mode 100644
index 0000000..0b9af23
--- /dev/null
+++ b/core/api/src/test/java/org/onosproject/ui/table/cell/AbstractCellComparatorTest.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed 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.onosproject.ui.table.cell;
+
+import org.junit.Test;
+import org.onosproject.ui.table.CellComparator;
+
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Unit tests for {@link AbstractCellComparator}.
+ */
+public class AbstractCellComparatorTest {
+
+ private static class Concrete extends AbstractCellComparator {
+ @Override
+ protected int nonNullCompare(Object o1, Object o2) {
+ return 42;
+ }
+ }
+
+ private CellComparator cmp = new Concrete();
+
+ @Test
+ public void twoNullArgs() {
+ assertTrue("two nulls", cmp.compare(null, null) == 0);
+ }
+
+ @Test
+ public void nullArgOne() {
+ assertTrue("null one", cmp.compare(null, 1) < 0);
+ }
+
+ @Test
+ public void nullArgTwo() {
+ assertTrue("null two", cmp.compare(1, null) > 0);
+ }
+
+ // mock output, but check that our method was invoked...
+ @Test
+ public void noNulls() {
+ assertTrue("no Nulls", cmp.compare(1, 2) == 42);
+ }
+}
diff --git a/core/api/src/test/java/org/onosproject/ui/table/cell/AbstractCellFormatterTest.java b/core/api/src/test/java/org/onosproject/ui/table/cell/AbstractCellFormatterTest.java
new file mode 100644
index 0000000..7a3c34bc
--- /dev/null
+++ b/core/api/src/test/java/org/onosproject/ui/table/cell/AbstractCellFormatterTest.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed 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.onosproject.ui.table.cell;
+
+import org.junit.Test;
+import org.onosproject.ui.table.CellFormatter;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Unit tests for {@link AbstractCellFormatter}.
+ */
+public class AbstractCellFormatterTest {
+
+ private static final String MOCK_OUTPUT = "Mock!!";
+
+ private static class Concrete extends AbstractCellFormatter {
+ @Override
+ protected String nonNullFormat(Object value) {
+ return MOCK_OUTPUT;
+ }
+ }
+
+ private CellFormatter frm = new Concrete();
+
+ @Test
+ public void nullInput() {
+ assertEquals("wrong result", "", frm.format(null));
+ }
+
+ // mock output, but check that our method was invoked...
+ @Test
+ public void nonNullInput() {
+ assertEquals("what?", MOCK_OUTPUT, frm.format(1));
+ }
+
+}
diff --git a/core/api/src/test/java/org/onosproject/ui/table/cell/AppIdFormatterTest.java b/core/api/src/test/java/org/onosproject/ui/table/cell/AppIdFormatterTest.java
new file mode 100644
index 0000000..e74fb47
--- /dev/null
+++ b/core/api/src/test/java/org/onosproject/ui/table/cell/AppIdFormatterTest.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed 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.onosproject.ui.table.cell;
+
+import org.junit.Test;
+import org.onosproject.core.ApplicationId;
+import org.onosproject.ui.table.CellFormatter;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Unit tests for {@link AppIdFormatter}.
+ */
+public class AppIdFormatterTest {
+
+ private static final ApplicationId APP_ID = new ApplicationId() {
+ @Override
+ public short id() {
+ return 25;
+ }
+
+ @Override
+ public String name() {
+ return "some app";
+ }
+ };
+
+ private CellFormatter fmt = AppIdFormatter.INSTANCE;
+
+ @Test
+ public void basic() {
+ assertEquals("wrong format", "25 : some app", fmt.format(APP_ID));
+ }
+
+}
diff --git a/core/api/src/test/java/org/onosproject/ui/table/cell/ConnectPointFormatterTest.java b/core/api/src/test/java/org/onosproject/ui/table/cell/ConnectPointFormatterTest.java
new file mode 100644
index 0000000..65fd784
--- /dev/null
+++ b/core/api/src/test/java/org/onosproject/ui/table/cell/ConnectPointFormatterTest.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed 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.onosproject.ui.table.cell;
+
+import org.junit.Test;
+import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.PortNumber;
+import org.onosproject.ui.table.CellFormatter;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Unit tests for {@link ConnectPointFormatter}.
+ */
+public class ConnectPointFormatterTest {
+
+ private static final DeviceId DEVID = DeviceId.deviceId("foobar");
+ private static final PortNumber PORT = PortNumber.portNumber(42);
+
+ private static final ConnectPoint CP = new ConnectPoint(DEVID, PORT);
+
+ private CellFormatter fmt = ConnectPointFormatter.INSTANCE;
+
+ @Test
+ public void basic() {
+ assertEquals("wrong format", "foobar/42", fmt.format(CP));
+ }
+
+}
diff --git a/core/api/src/test/java/org/onosproject/ui/table/cell/HostLocationFormatterTest.java b/core/api/src/test/java/org/onosproject/ui/table/cell/HostLocationFormatterTest.java
new file mode 100644
index 0000000..bfbe454
--- /dev/null
+++ b/core/api/src/test/java/org/onosproject/ui/table/cell/HostLocationFormatterTest.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed 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.onosproject.ui.table.cell;
+
+import org.junit.Test;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.HostLocation;
+import org.onosproject.net.PortNumber;
+import org.onosproject.ui.table.CellFormatter;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Unit tests for {@link HostLocationFormatter}.
+ */
+public class HostLocationFormatterTest {
+
+ private static final DeviceId DEVID = DeviceId.deviceId("foobar");
+ private static final PortNumber PORT = PortNumber.portNumber(42);
+ private static final long TIME = 12345;
+
+ private static final HostLocation LOC = new HostLocation(DEVID, PORT, TIME);
+
+ private CellFormatter fmt = HostLocationFormatter.INSTANCE;
+
+ @Test
+ public void basic() {
+ assertEquals("wrong format", "foobar/42", fmt.format(LOC));
+ }
+
+}
diff --git a/core/api/src/test/java/org/onosproject/ui/table/cell/LongComparatorTest.java b/core/api/src/test/java/org/onosproject/ui/table/cell/LongComparatorTest.java
new file mode 100644
index 0000000..f016540
--- /dev/null
+++ b/core/api/src/test/java/org/onosproject/ui/table/cell/LongComparatorTest.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed 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.onosproject.ui.table.cell;
+
+import org.junit.Test;
+import org.onosproject.ui.table.CellComparator;
+
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Unit tests for {@link LongComparator}.
+ */
+public class LongComparatorTest {
+
+ private CellComparator cmp = LongComparator.INSTANCE;
+
+ @Test
+ public void twoNulls() {
+ assertTrue("two nulls", cmp.compare(null, null) == 0);
+ }
+
+ @Test
+ public void nullVsNegValue() {
+ assertTrue("null vs neg value", cmp.compare(null, -5L) < 0);
+ }
+
+ @Test
+ public void nullVsPosValue() {
+ assertTrue("null vs pos value", cmp.compare(null, 5L) < 0);
+ }
+
+ @Test
+ public void negValueVsNull() {
+ assertTrue("neg value vs null", cmp.compare(-5L, null) > 0);
+ }
+
+ @Test
+ public void posValueVsNull() {
+ assertTrue("pos value vs null", cmp.compare(5L, null) > 0);
+ }
+
+
+ @Test
+ public void smallVsBig() {
+ assertTrue("small vs big", cmp.compare(25L, 75L) < 0);
+ }
+
+ @Test
+ public void bigVsSmall() {
+ assertTrue("big vs small", cmp.compare(75L, 25L) > 0);
+ }
+
+ @Test
+ public void sameValue() {
+ assertTrue("same value", cmp.compare(50L, 50L) == 0);
+ }
+}
diff --git a/core/api/src/test/java/org/onosproject/ui/table/cell/TimeFormatterTest.java b/core/api/src/test/java/org/onosproject/ui/table/cell/TimeFormatterTest.java
new file mode 100644
index 0000000..924902a
--- /dev/null
+++ b/core/api/src/test/java/org/onosproject/ui/table/cell/TimeFormatterTest.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed 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.onosproject.ui.table.cell;
+
+import org.joda.time.DateTime;
+import org.junit.Test;
+import org.onosproject.ui.table.CellFormatter;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Unit tests for {@link TimeFormatter}.
+ */
+public class TimeFormatterTest {
+
+ private static final DateTime TIME = DateTime.parse("2010-06-30T01:20");
+ private static final String EXP_OUTPUT = "1:20:00 AM PDT";
+
+ private CellFormatter fmt = TimeFormatter.INSTANCE;
+
+ @Test
+ public void basic() {
+ assertEquals("wrong format", EXP_OUTPUT, fmt.format(TIME));
+ }
+}