@Test public void addContainerPropertyNull() { try { ContainerUtils.addContainerProperty(null, null, null, null); fail("It should throw a NullPointerException"); } catch (NullPointerException e) { assertTrue("Should throw an NullPointerException", e instanceof NullPointerException); } try { ContainerUtils.addContainerProperty(null, "propertyName", String.class, null); fail("It should throw a NullPointerException"); } catch (NullPointerException e) { assertTrue("Should throw an NullPointerException", e instanceof NullPointerException); } try { ContainerUtils.addContainerProperty(new IndexedContainer(), null, null, null); fail("It should throw a NullPointerException"); } catch (NullPointerException e) { assertTrue("Should throw an NullPointerException", e instanceof NullPointerException); } try { ContainerUtils.addContainerProperty(new IndexedContainer(), "nullProperty", null, null); fail("It should throw a NullPointerException"); } catch (NullPointerException e) { assertTrue("Should throw an NullPointerException", e instanceof NullPointerException); } }
@Test public void getFromPrimitiveCollectionNull() { try { ContainerUtils.getFromPrimitiveCollection(null); fail("Should throw an NullPointerException"); } catch (NullPointerException e) { assertTrue("Should throw an NullPointerException", e instanceof NullPointerException); } }
@Test public void getFromPrimitiveCollectionDouble() { Container container = ContainerUtils.getFromPrimitiveCollection(Arrays.asList(new Double[] {1d, 2d, 3d})); assertNotNull(container); assertEquals(3, container.size()); for (Object object : container.getItemIds()) { assertTrue(object instanceof Double); } }
@Test public void getFromPrimitiveCollectionInteger() { Container container = ContainerUtils.getFromPrimitiveCollection(Arrays.asList(new Integer[] {1, 2, 3})); assertNotNull(container); assertEquals(3, container.size()); for (Object object : container.getItemIds()) { assertTrue(object instanceof Integer); } }
@Test public void getFromPrimitiveCollectionString() { Container container = ContainerUtils.getFromPrimitiveCollection(Arrays.asList(new String[] {"a", "b", "c"})); assertNotNull(container); assertEquals(3, container.size()); for (Object object : container.getItemIds()) { assertTrue(object instanceof String); } }
@Test public void addContainerPropertyMetadata() { Container container = new IndexedContainer(); PropertyMetadata metadata = new PropertyMetadata("propertyName", String.class, null, "propertyName"); ContainerUtils.addContainerProperty(container, metadata); assertTrue( "container should contains a property 'propertyName'", container.getContainerPropertyIds().contains(metadata.getPropertyName())); assertEquals(String.class, container.getType("propertyName")); }
@Test public void initContainerNonSupported() throws InstantiationException { try { ContainerUtils.initContainer(NonSupportedContainer.class); fail("Should throw an InstantiationException"); } catch (IllegalAccessException e) { fail("Should not throw an IllegalAccessException"); } catch (InstantiationException e) { assertTrue("Should throw an InstantiationException", e instanceof InstantiationException); } }
@Test public void initContainerNull() throws InstantiationException { try { ContainerUtils.initContainer(null); fail("Should throw an IllegalArgumentException"); } catch (IllegalAccessException e) { fail("Should not throw an IllegalArgumentException"); } catch (InstantiationException e) { fail("Should not throw an IllegalArgumentException"); } catch (IllegalArgumentException e) { assertTrue("Should throw an IllegalArgumentException", e instanceof IllegalArgumentException); assertEquals("containerClass cannot be null.", e.getMessage()); } }
@Test public void initContainerIndexed() throws InstantiationException { try { Container container = ContainerUtils.initContainer(IndexedContainer.class); assertNotNull("container should not be null", container); assertTrue("container should be a Filterable", container instanceof Filterable); assertEquals( "container should be an IndexedContainer", IndexedContainer.class, container.getClass()); } catch (IllegalAccessException e) { fail("Should not throw an IllegalAccessException"); } catch (InstantiationException e) { fail("Should not throw an InstantiationException"); } }
@Test public void initContainerHierarchicalContainer() throws InstantiationException { try { Container container = ContainerUtils.initContainer(HierarchicalContainer.class); assertNotNull("container should not be null", container); assertTrue("container should be a Hierarchical", container instanceof Hierarchical); assertEquals( "container should be an HierarchicalContainer", HierarchicalContainer.class, container.getClass()); } catch (IllegalAccessException e) { fail("Should not throw an IllegalAccessException"); } catch (InstantiationException e) { fail("Should not throw an InstantiationException"); } }
@Test public void getFromPrimitiveCollectionEmpty() { Container container = ContainerUtils.getFromPrimitiveCollection(Arrays.asList(new String[] {})); assertNotNull(container); assertEquals(0, container.size()); }