From d1a84ef30573aec703e95ed64c54c71fcd19485a Mon Sep 17 00:00:00 2001 From: Eric Everman Date: Thu, 16 Aug 2018 11:42:34 -0500 Subject: [PATCH] Fixed a bug where the PropertyValue equals always returned false Low impact - was not used --- .../org/yarnandtail/andhow/PropertyValue.java | 11 ++- .../yarnandtail/andhow/PropertyValueTest.java | 94 +++++++++++++++++++ 2 files changed, 103 insertions(+), 2 deletions(-) create mode 100644 andhow-core/src/test/java/org/yarnandtail/andhow/PropertyValueTest.java diff --git a/andhow-core/src/main/java/org/yarnandtail/andhow/PropertyValue.java b/andhow-core/src/main/java/org/yarnandtail/andhow/PropertyValue.java index 16e691ff..c85d2b68 100644 --- a/andhow-core/src/main/java/org/yarnandtail/andhow/PropertyValue.java +++ b/andhow-core/src/main/java/org/yarnandtail/andhow/PropertyValue.java @@ -7,11 +7,18 @@ * * @author eeverman */ -public class PropertyValue { + public class PropertyValue { private final Property property; private final T value; + /** + * Overrides standard equals to return true if the Property is the same + * class instance and the values are equal. + * + * @param obj + * @return true or false based on same Property instance and equal value. + */ @Override public boolean equals(Object obj) { boolean basicPropsEq = false; @@ -28,7 +35,7 @@ public boolean equals(Object obj) { } - return false; + return basicPropsEq; } @Override diff --git a/andhow-core/src/test/java/org/yarnandtail/andhow/PropertyValueTest.java b/andhow-core/src/test/java/org/yarnandtail/andhow/PropertyValueTest.java new file mode 100644 index 00000000..13360f3a --- /dev/null +++ b/andhow-core/src/test/java/org/yarnandtail/andhow/PropertyValueTest.java @@ -0,0 +1,94 @@ +package org.yarnandtail.andhow; + +import org.junit.Test; + +import static org.junit.Assert.*; +import static org.yarnandtail.andhow.SimpleParams.*; + +/** + * + * @author ericeverman + */ +public class PropertyValueTest { + + public PropertyValueTest() { + } + + /** + * Test of equals method, of class PropertyValue. + */ + @Test + public void testEquals() { + + //Try some string properties + PropertyValue spv1 = new PropertyValue(STR_BOB, "abc"); + PropertyValue spv2 = new PropertyValue(STR_BOB, "abc"); + PropertyValue spv3 = new PropertyValue(STR_BOB, "def"); + PropertyValue spv4 = new PropertyValue(STR_BOB, null); + PropertyValue spv5 = new PropertyValue(STR_NULL, "abc"); + PropertyValue spv6 = new PropertyValue(STR_NULL, "abc"); + PropertyValue spv7 = new PropertyValue(STR_NULL, "def"); + PropertyValue spv8 = new PropertyValue(STR_NULL, null); + + // + assertTrue(spv1.equals(spv1)); + assertTrue(spv1.equals(spv2)); + assertFalse(spv1.equals(spv3)); + assertFalse(spv1.equals(spv4)); + assertFalse(spv1.equals(spv5)); + assertFalse(spv1.equals(spv6)); + assertFalse(spv1.equals(spv7)); + assertFalse(spv1.equals(spv8)); + // + assertTrue(spv2.equals(spv1)); + assertTrue(spv2.equals(spv2)); + assertFalse(spv2.equals(spv3)); + assertFalse(spv2.equals(spv4)); + assertFalse(spv2.equals(spv5)); + assertFalse(spv2.equals(spv6)); + assertFalse(spv2.equals(spv7)); + assertFalse(spv2.equals(spv8)); + // + assertFalse(spv3.equals(spv1)); + assertFalse(spv3.equals(spv2)); + assertTrue(spv3.equals(spv3)); + assertFalse(spv3.equals(spv4)); + assertFalse(spv3.equals(spv5)); + assertFalse(spv3.equals(spv6)); + assertFalse(spv3.equals(spv7)); + assertFalse(spv3.equals(spv8)); + // + assertFalse(spv5.equals(spv1)); + assertFalse(spv5.equals(spv2)); + assertFalse(spv5.equals(spv3)); + assertFalse(spv5.equals(spv4)); + assertTrue(spv5.equals(spv5)); + assertTrue(spv5.equals(spv6)); + assertFalse(spv5.equals(spv7)); + assertFalse(spv5.equals(spv8)); + // + assertFalse(spv1.equals(null)); + } + + /** + * Test of hashCode method, of class PropertyValue. + */ + @Test + public void testHashCode() { + } + + /** + * Test of getProperty method, of class PropertyValue. + */ + @Test + public void testGetProperty() { + } + + /** + * Test of getValue method, of class PropertyValue. + */ + @Test + public void testGetValue() { + } + +}