Skip to content

Commit

Permalink
Cleaned up code using the ComparableVersion class
Browse files Browse the repository at this point in the history
prevents warnings in IDE about raw types.
  • Loading branch information
khmarbaise committed Sep 25, 2016
1 parent 343ba68 commit 62e840f
Showing 1 changed file with 9 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,10 @@
*
* @author <a href="mailto:[email protected]">Hervé Boutemy</a>
*/
@SuppressWarnings( "unchecked" )
public class ComparableVersionTest
extends TestCase
{
private Comparable newComparable( String version )
private ComparableVersion newComparable( String version )
{
ComparableVersion ret = new ComparableVersion( version );
String canonical = ret.getCanonical();
Expand All @@ -56,18 +55,18 @@ private Comparable newComparable( String version )

private void checkVersionsOrder( String[] versions )
{
Comparable[] c = new Comparable[versions.length];
ComparableVersion[] c = new ComparableVersion[versions.length];
for ( int i = 0; i < versions.length; i++ )
{
c[i] = newComparable( versions[i] );
}

for ( int i = 1; i < versions.length; i++ )
{
Comparable low = c[i - 1];
ComparableVersion low = c[i - 1];
for ( int j = i; j < versions.length; j++ )
{
Comparable high = c[j];
ComparableVersion high = c[j];
assertTrue( "expected " + low + " < " + high, low.compareTo( high ) < 0 );
assertTrue( "expected " + high + " > " + low, high.compareTo( low ) > 0 );
}
Expand All @@ -76,8 +75,8 @@ private void checkVersionsOrder( String[] versions )

private void checkVersionsEqual( String v1, String v2 )
{
Comparable c1 = newComparable( v1 );
Comparable c2 = newComparable( v2 );
ComparableVersion c1 = newComparable( v1 );
ComparableVersion c2 = newComparable( v2 );
assertTrue( "expected " + v1 + " == " + v2, c1.compareTo( c2 ) == 0 );
assertTrue( "expected " + v2 + " == " + v1, c2.compareTo( c1 ) == 0 );
assertTrue( "expected same hashcode for " + v1 + " and " + v2, c1.hashCode() == c2.hashCode() );
Expand All @@ -87,8 +86,8 @@ private void checkVersionsEqual( String v1, String v2 )

private void checkVersionsOrder( String v1, String v2 )
{
Comparable c1 = newComparable( v1 );
Comparable c2 = newComparable( v2 );
ComparableVersion c1 = newComparable( v1 );
ComparableVersion c2 = newComparable( v2 );
assertTrue( "expected " + v1 + " < " + v2, c1.compareTo( c2 ) < 0 );
assertTrue( "expected " + v2 + " > " + v1, c2.compareTo( c1 ) > 0 );
}
Expand Down Expand Up @@ -224,7 +223,7 @@ public void testReuse()
ComparableVersion c1 = new ComparableVersion( "1" );
c1.parseVersion( "2" );

Comparable c2 = newComparable( "2" );
ComparableVersion c2 = newComparable( "2" );

assertEquals( "reused instance should be equivalent to new instance", c1, c2 );
}
Expand Down

0 comments on commit 62e840f

Please sign in to comment.