Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: openmrs/openmrs-core
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 0ed421cdd24e
Choose a base ref
...
head repository: openmrs/openmrs-core
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 64a87aa12d7f
Choose a head ref
  • 2 commits
  • 2 files changed
  • 2 contributors

Commits on Jan 16, 2014

  1. Copy the full SHA
    d149f36 View commit details
  2. Merge pull request #540 from dszafranek/TRUNK-4216

    TRUNK-4216 - Equals method should not assume anything about the type of its argument
    dkayiwa committed Jan 16, 2014
    Copy the full SHA
    64a87aa View commit details
Showing with 48 additions and 2 deletions.
  1. +5 −2 api/src/main/java/org/openmrs/util/DoubleRange.java
  2. +43 −0 api/src/test/java/org/openmrs/util/DoubleRangeTest.java
7 changes: 5 additions & 2 deletions api/src/main/java/org/openmrs/util/DoubleRange.java
Original file line number Diff line number Diff line change
@@ -125,8 +125,11 @@ public String toString() {
}

public boolean equals(Object o) {
DoubleRange other = (DoubleRange) o;
return low.equals(other.low) && high.equals(other.high);
if (o instanceof DoubleRange) {
DoubleRange other = (DoubleRange) o;
return low.equals(other.low) && high.equals(other.high);
}
return false;
}

}
43 changes: 43 additions & 0 deletions api/src/test/java/org/openmrs/util/DoubleRangeTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* The contents of this file are subject to the OpenMRS Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://license.openmrs.org
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* Copyright (C) OpenMRS, LLC. All Rights Reserved.
*/
package org.openmrs.util;

import org.junit.Assert;
import org.junit.Test;
import org.openmrs.test.Verifies;

/**
* Contains methods to test behavior of DoubleRange methods
*/
public class DoubleRangeTest {

/**
* @see {@link DoubleRange#equals(Object)}
*/
@Test
@Verifies(value = "should return true for the same object type and false for different objects", method = "equals(Object o)")
public void equals_shouldReturnTrueForTheSameObjectTypeAndFalseForDifferentTypeObjects() {
Double value1 = 0.0;
Double value2 = 5.0;
Double value3 = 6.0;
DoubleRange obj = new DoubleRange(value1, value2);
DoubleRange objTest1 = new DoubleRange(value1, value2);
DoubleRange objTest2 = new DoubleRange(value1, value3);
Object objTest3 = new Object();

Assert.assertTrue(obj.equals(objTest1));
Assert.assertFalse(obj.equals(objTest2));
Assert.assertFalse(obj.equals(objTest3));
}
}