@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")); }
public void remove(final Collection<String> propertiesToRemove) { if (null != propertiesToRemove) { for (final String property : propertiesToRemove) { remove(property); } } }
@SuppressWarnings("CloneDoesntCallSuperClone") @SuppressFBWarnings(value = "CN_IDIOM_NO_SUPER_CALL", justification = "Doesn't use any properties in super class") @Override public LazyProperties clone() { return new LazyProperties(properties.clone(), valueLoader); }
@Test public void shouldNotAddPropertyIfPropertyNameIsNull() { // When final Properties properties = new Properties(); properties.put(null, "propertyValue1"); // Then assertEquals(0, properties.size()); }
@Test public void shouldAddPropertyToMapWhenAddingProperty() { // Given final ElementValueLoader elementLoader = mock(ElementValueLoader.class); final Properties properties = new Properties(); final String propertyName = "property name"; final String propertyValue = "property value"; final LazyProperties lazyProperties = new LazyProperties(properties, elementLoader); given(elementLoader.getProperty(propertyName, lazyProperties)).willReturn(propertyValue); // When lazyProperties.put(propertyName, propertyValue); // Then verify(elementLoader, never()).getProperty(propertyName, lazyProperties); assertEquals(propertyValue, properties.get(propertyName)); }
@Test public void shouldAggregatePropertiesWithMultipleOfFunctions() { // Given final BinaryOperator<Integer> max = Math::max; final BinaryOperator<Integer> min = Math::min; final ElementAggregator aggregator = new ElementAggregator.Builder() .select("max") .execute(max) .select("min") .execute(min) .build(); final Properties properties1 = new Properties(); properties1.put("max", 10); properties1.put("min", 10); final Properties properties2 = new Properties(); properties2.put("max", 100); properties2.put("min", 100); final Properties properties3 = new Properties(); properties3.put("max", 1000); properties3.put("min", 1000); // When Properties state = aggregator.apply(properties1, properties2); state = aggregator.apply(state, properties3); // Then assertEquals(1000, state.get("max")); assertEquals(10, state.get("min")); }
@Override public Object get(final String propertyName) { return properties.get(propertyName); }
@Test public void shouldSerialiseAndDeserialiseProperties() throws SerialisationException { // Given final Element element = newElement("group"); final Properties properties = new Properties(); properties.put("property1", 1L); properties.put("property2", 2); properties.put("property3", (double) 3); properties.put("property4", "4"); properties.put("property5", new Date(5L)); element.setProperties(properties); // When final byte[] serialisedElement = JSONSerialiser.serialise(element); final Element deserialisedElement = JSONSerialiser.deserialise(serialisedElement, element.getClass()); // Then assertTrue(StringUtil.toString(serialisedElement).contains("{\"java.util.Date\":5}")); assertEquals(element, deserialisedElement); }
@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")); }
public Builder property(final String name, final Object value) { properties.put(name, value); return this; }
@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)); }
Element(final String group, final Properties properties) { this.group = group; if (null == properties) { this.properties = new Properties(); } else { this.properties = properties; } }
@Test public void shouldReturnHumanReadableToString() { // 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 String toString = properties.toString(); // Then assertTrue(toString.contains("property 2=" + "<java.lang.String>property value 2")); assertTrue(toString.contains("property 1=" + "<java.lang.String>property value 1")); } }
final Properties properties = new Properties(); try { properties.putAll(elementConverter.getPropertiesFromColumnQualifier(group, topColumnQualifier)); properties.putAll(elementConverter.getPropertiesFromColumnVisibility(group, topColumnVisibility)); properties.putAll(elementConverter.getPropertiesFromValue(group, topValue)); properties.putAll(elementConverter.getPropertiesFromTimestamp(group, topTimestamp)); if (null == groupBy) { if (null != schemaGroupBy) { properties.remove(schemaGroupBy); properties.remove(groupBy);
@Test public void shouldConstructEmptyProperties() { // Given // When final Properties properties = new Properties(); // Then assertTrue(properties.isEmpty()); }
@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")); }
@Override public Object getProperty(final String name, final Properties lazyProperties) { if (null == eDef) { eDef = schema.getElement(group); if (null == eDef) { throw new IllegalArgumentException("Element definition for " + group + " could not be found in the schema"); } } final Properties props; if (eDef.getGroupBy().contains(name)) { props = elementConverter.getPropertiesFromColumnQualifier(group, key.getColumnQualifierData().getBackingArray()); } else if (name.equals(schema.getVisibilityProperty())) { props = elementConverter.getPropertiesFromColumnVisibility(group, key.getColumnVisibilityData().getBackingArray()); } else if (name.equals(timestampProperty)) { props = elementConverter.getPropertiesFromTimestamp(group, key.getTimestamp()); } else { props = elementConverter.getPropertiesFromValue(group, value); } lazyProperties.putAll(props); return props.get(name); } }
@Override public Set<Map.Entry<String, Object>> entrySet() { return properties.entrySet(); }
@Override public Set<String> keySet() { return properties.keySet(); }
@Override public void putAll(final Map<? extends String, ?> newProperties) { properties.putAll(newProperties); loadedProperties.addAll(newProperties.keySet()); }