@Test public void testAddRemove() { final ImageJ context = ImageJ.createContext(DisplayService.class); final DisplayService displayService = context.getService(DisplayService.class); final String name = "AddRemove"; // TODO: Reenable once DefaultDisplay is discoverable again. // final Object[] values = { 12.34, 890, 0, 93.73f }; final Object[] values = {"quick", "brown", "fox", "jumps"}; @SuppressWarnings("unchecked") final Display<Object> display = (Display<Object>) displayService.createDisplay(name, values[0]); assertNotNull(display); for (int i = 1; i < values.length; i++) { display.add(values[i]); } display.update(); // are all objects present in the display? assertFalse(display.isEmpty()); assertEquals(display.size(), values.length); for (int i = 0; i < values.length; i++) { final Object result = display.get(i); assertEquals(values[i], result); } // does removing an object work as expected? display.remove(0); final Object result = display.get(0); assertEquals(values[1], result); // does removing all objects work as expected? for (int i = 1; i < values.length; i++) { display.remove(0); } assertTrue(display.isEmpty()); }
@Test public void testCreate() { final ImageJ context = ImageJ.createContext(DisplayService.class); final DisplayService displayService = context.getService(DisplayService.class); final String name = "Create"; // TODO: Reenable once DefaultDisplay is discoverable again. // final Double value = 12.34; final String value = "Some text to display."; final Display<?> display = displayService.createDisplay(name, value); // was the display created successfully? assertNotNull(display); // does the display have the proper context? assertEquals(context, display.getContext()); // does the display have the proper name? assertEquals(name, display.getName()); // does the display contain the required object? final Object result = display.get(0); assertNotNull(result); assertEquals(value, result); }