SharedTable { public static void add(final String label, final String header, final long value) { add(label, header, new Double(value)); } private  SharedTable(); static void add(final String label, final String header,
		final long value); static void add(final String label, final String header,
		final double value); static void add(final String label, final String header,
		final Double value); static Table<DefaultColumn<Double>, Double> getTable(); static boolean hasData(); static void reset(); static final Double EMPTY_CELL; }
@Test public void testAdd() { final String labelA = "Image A"; final String labelB = "Image B"; final String header1 = "Measurement 1"; final String header2 = "Measurement 2"; SharedTable.add(labelB, header2, 2.0); SharedTable.add(labelA, header1, 1.0); SharedTable.add(labelA, header1, 1.0); SharedTable.add(labelA, header2, 2.0); SharedTable.add(labelA, header2, 3.0); final Table<DefaultColumn<Double>, Double> table = SharedTable.getTable(); assertEquals("Wrong number of columns", 2, table.getColumnCount()); assertEquals("Wrong number of rows", 3, table.getRowCount()); final DefaultColumn<Double> column1 = table.get(header1); assertEquals("Cell should be empty", EMPTY_CELL, column1.get(0)); assertEquals("Wrong number of empty cells", 1, column1.stream().filter( Objects::isNull).count()); final DefaultColumn<Double> column2 = table.get(header2); assertEquals("Cell contains wrong value", 3.0, column2.get(1), 1e-12); assertEquals("Wrong number of empty cells", 0, column2.stream().filter( Objects::isNull).count()); assertEquals("Label on the wrong row", 0, table.getRowIndex(labelB)); }
@Test public void testAddThrowsIAEIfEmptyLabel() { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Label cannot be empty"); SharedTable.add("", "Header", 1.0); }
@Test public void testAddThrowsIAEIfEmptyHeader() { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Header cannot be empty"); SharedTable.add("Label", "", 1.0); }
@Test(expected = NullPointerException.class) public void testAddThrowsNPEIfNullLabel() { SharedTable.add(null, "Header", 1.0); }
@Test(expected = NullPointerException.class) public void testAddThrowsNPEIfNullHeader() { SharedTable.add("Label", null, 1.0); }
@Test(expected = NullPointerException.class) public void testAddThrowsNPEIfNullValue() { SharedTable.add("Label", "Header", null); }