jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fschumac...@apache.org
Subject svn commit: r1802732 - in /jmeter/trunk: src/core/org/apache/jmeter/threads/UnmodifiableJMeterVariables.java test/src/org/apache/jmeter/threads/TestUnmodifiableJMeterVariables.java
Date Sun, 23 Jul 2017 15:48:41 GMT
Author: fschumacher
Date: Sun Jul 23 15:48:41 2017
New Revision: 1802732

URL: http://svn.apache.org/viewvc?rev=1802732&view=rev
Log:
Change equals and hashCode so that they are more independent from JMeterVariables.

Modified:
    jmeter/trunk/src/core/org/apache/jmeter/threads/UnmodifiableJMeterVariables.java
    jmeter/trunk/test/src/org/apache/jmeter/threads/TestUnmodifiableJMeterVariables.java

Modified: jmeter/trunk/src/core/org/apache/jmeter/threads/UnmodifiableJMeterVariables.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/threads/UnmodifiableJMeterVariables.java?rev=1802732&r1=1802731&r2=1802732&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/threads/UnmodifiableJMeterVariables.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/threads/UnmodifiableJMeterVariables.java Sun Jul
23 15:48:41 2017
@@ -40,8 +40,13 @@ class UnmodifiableJMeterVariables extend
 
     @Override
     public int hashCode() {
-        return variables.hashCode();
+        final int prime = 31;
+        int result = 1;
+        result = prime * result
+                + ((variables == null) ? 0 : variables.hashCode());
+        return result;
     }
+    
 
     @Override
     public String getThreadName() {
@@ -88,8 +93,21 @@ class UnmodifiableJMeterVariables extend
         return variables.get(key);
     }
 
+    @Override
     public boolean equals(Object obj) {
-        return variables.equals(obj);
+        if (this == obj)
+            return true;
+        if (obj == null)
+            return false;
+        if (getClass() != obj.getClass())
+            return false;
+        UnmodifiableJMeterVariables other = (UnmodifiableJMeterVariables) obj;
+        if (variables == null) {
+            if (other.variables != null)
+                return false;
+        } else if (!variables.equals(other.variables))
+            return false;
+        return true;
     }
  
     @Override

Modified: jmeter/trunk/test/src/org/apache/jmeter/threads/TestUnmodifiableJMeterVariables.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jmeter/threads/TestUnmodifiableJMeterVariables.java?rev=1802732&r1=1802731&r2=1802732&view=diff
==============================================================================
--- jmeter/trunk/test/src/org/apache/jmeter/threads/TestUnmodifiableJMeterVariables.java (original)
+++ jmeter/trunk/test/src/org/apache/jmeter/threads/TestUnmodifiableJMeterVariables.java Sun
Jul 23 15:48:41 2017
@@ -124,13 +124,26 @@ public class TestUnmodifiableJMeterVaria
     }
 
     @Test
-    public void testEqualsObject() {
-        assertThat(unmodifiables, CoreMatchers.is(vars));
+    public void testEqualsObjectSymmetry() {
+        UnmodifiableJMeterVariables otherUnmodifiables = new UnmodifiableJMeterVariables(vars);
+        assertThat(unmodifiables, CoreMatchers.is(otherUnmodifiables));
+        assertThat(otherUnmodifiables, CoreMatchers.is(unmodifiables));
+    }
+
+    @Test
+    public void testEqualsObjectReflexivity() {
+        assertThat(unmodifiables, CoreMatchers.is(unmodifiables));
+    }
+
+    @Test
+    public void testEqualsObjectWithJMeterVariables() {
+        assertThat(unmodifiables.equals(vars), CoreMatchers.is(vars.equals(unmodifiables)));
     }
 
     @Test
     public void testHashCode() {
-        assertThat(unmodifiables.hashCode(), CoreMatchers.is(vars.hashCode()));
+        UnmodifiableJMeterVariables otherUnmodifiables = new UnmodifiableJMeterVariables(vars);
+        assertThat(unmodifiables.hashCode(), CoreMatchers.is(otherUnmodifiables.hashCode()));
     }
 
 }



Mime
View raw message