SW360ComponentAdapterUtils { static SW360Component validateComponent(SW360Component component) { if (StringUtils.isEmpty(component.getName())) { throw new IllegalArgumentException("Invalid component: missing property 'name'."); } if (component.getCategories() == null || component.getCategories().isEmpty()) { throw new IllegalArgumentException("Invalid component: missing property 'categories'."); } return component; } private  SW360ComponentAdapterUtils(); static void setComponentType(SW360Component component, boolean isProprietary);  }
@Test public void testValidateComponentValid() { SW360Component component = new SW360Component(); component.setName("test"); component.setCategories(Collections.singleton("Antenna")); assertThat(SW360ComponentAdapterUtils.validateComponent(component)).isSameAs(component); }
@Test public void testValidateComponentNullName() { SW360Component component = new SW360Component(); component.setCategories(Collections.singleton("Antenna")); try { SW360ComponentAdapterUtils.validateComponent(component); fail("Invalid component not detected"); } catch (IllegalArgumentException e) { assertThat(e.getMessage()).contains("missing property 'name'"); } }
@Test public void testValidateComponentEmptyName() { SW360Component component = new SW360Component(); component.setName(""); component.setCategories(Collections.singleton("Antenna")); try { SW360ComponentAdapterUtils.validateComponent(component); fail("Invalid component not detected"); } catch (IllegalArgumentException e) { assertThat(e.getMessage()).contains("missing property 'name'"); } }
@Test public void testValidateComponentNullCategories() { SW360Component component = new SW360Component(); component.setName("component"); try { SW360ComponentAdapterUtils.validateComponent(component); fail("Invalid component not detected"); } catch (IllegalArgumentException e) { assertThat(e.getMessage()).contains("missing property 'categories'"); } }
@Test public void testValidateComponentEmptyCategories() { SW360Component component = new SW360Component(); component.setCategories(Collections.emptySet()); component.setName("component"); try { SW360ComponentAdapterUtils.validateComponent(component); fail("Invalid component not detected"); } catch (IllegalArgumentException e) { assertThat(e.getMessage()).contains("missing property 'categories'"); } }