Skip to content

Commit

Permalink
compareTo should throw NullPointerException per spec (#35)
Browse files Browse the repository at this point in the history
* compareTo should throw NullPointerException per spec

* consistent spelling
  • Loading branch information
elharo authored Dec 28, 2020
1 parent b40df73 commit c6acce8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,12 @@ public String getVersion()
/**
* Specifies if this version is greater or equal to the specified version.
*
* @param parmVersion the version to check
* @param paramVersion the version to check
* @return true if this version is greater or equal to <tt>version</tt>
*/
public boolean ge( JavaEEVersion parmVersion )
public boolean ge( JavaEEVersion paramVersion )
{
return this.compareTo( parmVersion ) >= 0;
return this.compareTo( paramVersion ) >= 0;
}

/**
Expand Down Expand Up @@ -176,7 +176,7 @@ private static boolean isValid( String paramVersion )
{
if ( paramVersion == null )
{
throw new IllegalArgumentException( "version could not be null." );
throw new NullPointerException( "version cannot be null." );
}
// @formatter:off
return VERSION_1_3.equals( paramVersion )
Expand All @@ -193,7 +193,7 @@ public int compareTo( JavaEEVersion otherVersion )
{
if ( otherVersion == null )
{
throw new IllegalArgumentException( "other object to compare to could not be null." );
throw new NullPointerException( "other object to compare to could not be null." );
}
return index.compareTo( otherVersion.index );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,9 @@ public void testGetVersion()
assertEquals( "5", JavaEEVersion.FIVE.getVersion() );
}

public void testGetJavaEEVersionValid()
public void testGetJavaEEVersionValid() throws InvalidJavaEEVersion
{
try
{
assertEquals( JavaEEVersion.SIX, JavaEEVersion.getJavaEEVersion( "6" ) );
}
catch ( InvalidJavaEEVersion invalidJavaEEVersion )
{
fail( "No exception should have been thrown but got [" + invalidJavaEEVersion.getMessage() + "]" );
}
assertEquals( JavaEEVersion.SIX, JavaEEVersion.getJavaEEVersion( "6" ) );
}

public void testGetJavaEEVersionInvalid()
Expand All @@ -122,24 +115,20 @@ public void testGetJavaEEVersionInvalid()
JavaEEVersion.getJavaEEVersion( "2.4" );
fail( "Should have failed to get an invalid version." );
}
catch ( InvalidJavaEEVersion e )
catch ( InvalidJavaEEVersion expected )
{
// OK
}
}

public void testGetJavaEEVersionNull()
public void testGetJavaEEVersionNull() throws InvalidJavaEEVersion
{
try
{
JavaEEVersion.getJavaEEVersion( null );
fail( "Should have failed to get a 'null' version." );
}
catch ( InvalidJavaEEVersion e )
{
fail( "Should have failed with an illegal argument exception instead." );
}
catch ( IllegalArgumentException e )
catch ( NullPointerException expected )
{
// OK
}
Expand Down

0 comments on commit c6acce8

Please sign in to comment.