@Override public int size() { return properties.size(); }
@Test public void shouldConstructPropertiesWithOtherProperties() { // Given final Map<String, Object> otherProperties = new HashMap<>(); otherProperties.put("propertyName", "property value"); // When final Properties properties = new Properties(otherProperties); // Then assertEquals(1, properties.size()); assertEquals("property value", properties.get("propertyName")); }
@Test public void shouldNotAddPropertyIfPropertyNameIsNull() { // When final Properties properties = new Properties(); properties.put(null, "propertyValue1"); // Then assertEquals(0, properties.size()); }
@Test public void shouldConstructPropertiesWithProperty() { // Given // When final Properties properties = new Properties("propertyName", "property value"); // Then assertEquals(1, properties.size()); assertEquals("property value", properties.get("propertyName")); }
@Test public void shouldRemovePropertyIfAddedWithNullValue() { // Given final Properties properties = new Properties(); properties.put("property1", "propertyValue1"); properties.put("property2", "propertyValue2"); // When properties.put("property1", null); // Then assertEquals(1, properties.size()); assertEquals(null, properties.get("property1")); }
@Test public void shouldCopyProperties() { // Given final Element element1 = newElement("group"); final Properties newProperties = new Properties("property1", "propertyValue1"); // When element1.copyProperties(newProperties); // Then assertEquals(1, element1.getProperties().size()); assertEquals("propertyValue1", element1.getProperty("property1")); }
@Test public void shouldRemoveProperties() { // Given final String property1 = "property 1"; final String property2 = "property 2"; final String property3 = "property 3"; final String property4 = "property 4"; final String propertyValue1 = "property value 1"; final String propertyValue2 = "property value 2"; final String propertyValue3 = "property value 3"; final String propertyValue4 = "property value 4"; final Collection<String> propertiesToRemove = Arrays.asList(property2, property4); final Properties properties = new Properties(); properties.put(property1, propertyValue1); properties.put(property2, propertyValue2); properties.put(property3, propertyValue3); properties.put(property4, propertyValue4); // When properties.remove(propertiesToRemove); // Then assertEquals(2, properties.size()); assertEquals(propertyValue1, properties.get(property1)); assertEquals(propertyValue3, properties.get(property3)); }
@Test public void shouldKeepOnlyGivenProperties() { // Given final String property1 = "property 1"; final String property2 = "property 2"; final String property3 = "property 3"; final String property4 = "property 4"; final String propertyValue1 = "property value 1"; final String propertyValue2 = "property value 2"; final String propertyValue3 = "property value 3"; final String propertyValue4 = "property value 4"; final Collection<String> propertiesToKeep = Arrays.asList(property1, property3); final Properties properties = new Properties(); properties.put(property1, propertyValue1); properties.put(property2, propertyValue2); properties.put(property3, propertyValue3); properties.put(property4, propertyValue4); // When properties.keepOnly(propertiesToKeep); // Then assertEquals(2, properties.size()); assertEquals(propertyValue1, properties.get(property1)); assertEquals(propertyValue3, properties.get(property3)); }
@Test public void shouldRemoveProperty() { // Given final Element element1 = newElement("group"); element1.putProperty("property1", "propertyValue1"); element1.putProperty("property2", "propertyValue2"); // When element1.removeProperty("property1"); // Then assertEquals(1, element1.getProperties().size()); assertEquals(null, element1.getProperty("property1")); assertEquals("propertyValue2", element1.getProperty("property2")); }
@Test public void shouldCloneProperties() { // Given final String property1 = "property 1"; final String property2 = "property 2"; final String propertyValue1 = "property value 1"; final String propertyValue2 = "property value 2"; final Properties properties = new Properties(); properties.put(property1, propertyValue1); properties.put(property2, propertyValue2); // When final Properties clone = properties.clone(); // Then assertEquals(2, clone.size()); assertNotSame(properties, clone); assertEquals(propertyValue1, clone.get(property1)); assertEquals(propertyValue2, clone.get(property2)); }
@Test public void shouldNotRemoveAllPropertiesWhenNoRelevantProperties() { //Given final View view = new View.Builder() .edge(TestGroups.EDGE, new ViewElementDefinition.Builder() .properties(TestPropertyNames.COUNT) .build()) .entity(TestGroups.ENTITY, new ViewElementDefinition.Builder() .properties(TestPropertyNames.PROP_2) .build()) .build(); final Edge edge = new Edge.Builder() .group(TestGroups.EDGE) .property(TestPropertyNames.PROP_1, "1") .property(TestPropertyNames.PROP_2, "2") .property(TestPropertyNames.PROP_3, "3") .build(); //When ViewUtil.removeProperties(view, edge); //Then assertEquals(0, edge.getProperties().size()); }
@Test public void shouldKeepOnlyProvidedProperties() { //Given final View view = new View.Builder() .edge(TestGroups.EDGE, new ViewElementDefinition.Builder() .properties(TestPropertyNames.PROP_1) .build()) .entity(TestGroups.ENTITY, new ViewElementDefinition.Builder() .properties(TestPropertyNames.PROP_2) .build()) .build(); final Edge edge = new Edge.Builder() .group(TestGroups.EDGE) .property(TestPropertyNames.PROP_1, "1") .property(TestPropertyNames.PROP_2, "2") .property(TestPropertyNames.PROP_3, "3") .build(); //When ViewUtil.removeProperties(view, edge); //Then assertEquals(1, edge.getProperties().size()); assertEquals("1", edge.getProperties().get(TestPropertyNames.PROP_1)); }
@Test public void shouldRemoveExcludedProperties() { //Given final View view = new View.Builder() .edge(TestGroups.EDGE, new ViewElementDefinition.Builder() .excludeProperties(TestPropertyNames.PROP_1) .build()) .entity(TestGroups.ENTITY, new ViewElementDefinition.Builder() .excludeProperties(TestPropertyNames.PROP_2) .build()) .build(); final Edge edge = new Edge.Builder() .group(TestGroups.EDGE) .property(TestPropertyNames.PROP_1, "1") .property(TestPropertyNames.PROP_2, "2") .property(TestPropertyNames.PROP_3, "3") .build(); //When ViewUtil.removeProperties(view, edge); //Then assertEquals(2, edge.getProperties().size()); assertEquals("2", edge.getProperties().get(TestPropertyNames.PROP_2)); assertEquals("3", edge.getProperties().get(TestPropertyNames.PROP_3)); }
@Test public void shouldNotRemovePropertiesWhenNoRelevantExcludeProperties() { //Given final View view = new View.Builder() .edge(TestGroups.EDGE, new ViewElementDefinition.Builder() .excludeProperties(TestPropertyNames.COUNT) .build()) .entity(TestGroups.ENTITY, new ViewElementDefinition.Builder() .properties(TestPropertyNames.PROP_2) .build()) .build(); final Edge edge = new Edge.Builder() .group(TestGroups.EDGE) .property(TestPropertyNames.PROP_1, "1") .property(TestPropertyNames.PROP_2, "2") .property(TestPropertyNames.PROP_3, "3") .build(); //When ViewUtil.removeProperties(view, edge); //Then assertEquals(3, edge.getProperties().size()); assertEquals("1", edge.getProperties().get(TestPropertyNames.PROP_1)); assertEquals("2", edge.getProperties().get(TestPropertyNames.PROP_2)); assertEquals("3", edge.getProperties().get(TestPropertyNames.PROP_3)); }
@Test public void shouldNotRemovePropertiesWhenNotSet() { //Given final View view = new View.Builder() .edge(TestGroups.EDGE, new ViewElementDefinition.Builder() .allProperties() .build()) .entity(TestGroups.ENTITY, new ViewElementDefinition.Builder() .properties(TestPropertyNames.PROP_2) .build()) .build(); final Edge edge = new Edge.Builder() .group(TestGroups.EDGE) .property(TestPropertyNames.PROP_1, "1") .property(TestPropertyNames.PROP_2, "2") .property(TestPropertyNames.PROP_3, "3") .build(); //When ViewUtil.removeProperties(view, edge); //Then assertEquals(3, edge.getProperties().size()); assertEquals("1", edge.getProperties().get(TestPropertyNames.PROP_1)); assertEquals("2", edge.getProperties().get(TestPropertyNames.PROP_2)); assertEquals("3", edge.getProperties().get(TestPropertyNames.PROP_3)); }
@Override public int size() { return properties.size(); }