Skip to content

Instantly share code, notes, and snippets.

@siordache
Created August 11, 2015 15:28
Show Gist options
  • Save siordache/a6f5b05d5c819cd825b6 to your computer and use it in GitHub Desktop.
Save siordache/a6f5b05d5c819cd825b6 to your computer and use it in GitHub Desktop.
A Spock specification that fails in Java 8 with CGLIB 3.1 but works with CGLIB 3.2
public class Range<T extends Number> implements Comparable<Range<T>> {
private final T minVal;
private final T maxVal;
public Range(T minVal, T maxVal) {
this.minVal = minVal;
this.maxVal = maxVal;
}
@Override
public int compareTo(Range<T> other) {
double myLen = maxVal.doubleValue() - minVal.doubleValue();
double otherLen = other.maxVal.doubleValue() - other.minVal.doubleValue();
return Double.compare(myLen, otherLen);
}
}
import spock.lang.Specification
class RangeSpec extends Specification {
def "compare ranges"() {
given:
Range<Integer> range1 = Spy(constructorArgs: [3, 5])
Range<Integer> range2 = Spy(constructorArgs: [2, 6])
expect:
range1.compareTo(range2) < 0
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment