forked from mojohaus/license-maven-plugin
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
331 Fix for issue mojohaus#331 plus unit tests.
- Loading branch information
Aaron Digulla
committed
May 10, 2019
1 parent
98fb027
commit 5f8947e
Showing
3 changed files
with
194 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
162 changes: 162 additions & 0 deletions
162
src/test/java/org/codehaus/mojo/license/LicenseMojoUtilsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
package org.codehaus.mojo.license; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
import java.io.File; | ||
|
||
import org.junit.Test; | ||
|
||
public class LicenseMojoUtilsTest | ||
{ | ||
private String resolvedUrl; | ||
private File deprecatedFile; | ||
private String url; | ||
private File basedir = new File( "" ); | ||
private MockLogger log = new MockLogger(); | ||
|
||
@Test | ||
public void testIsValidNull() | ||
{ | ||
assertFalse( LicenseMojoUtils.isValid( null ) ); | ||
} | ||
|
||
@Test | ||
public void testIsValidEmpty() | ||
{ | ||
// TODO is this correct? | ||
assertTrue( LicenseMojoUtils.isValid( "" ) ); | ||
} | ||
|
||
@Test | ||
public void testIsValidBlank() | ||
{ | ||
// TODO is this correct? | ||
assertTrue( LicenseMojoUtils.isValid( " " ) ); | ||
} | ||
|
||
@Test | ||
public void testIsValidNonexistingClasspathResource() | ||
{ | ||
assertTrue( LicenseMojoUtils.isValid( "classpath:noSuchResource" ) ); | ||
} | ||
|
||
@Test | ||
public void testIsValidClasspathResource() | ||
{ | ||
assertTrue( LicenseMojoUtils.isValid( "classpath:log4j.properties" ) ); | ||
} | ||
|
||
@Test | ||
public void testIsValidHttpResource() | ||
{ | ||
assertTrue( LicenseMojoUtils.isValid( "http://foo/bar/baz" ) ); | ||
} | ||
|
||
@Test | ||
public void testPrepareThirdPartyOverrideUrlNull() | ||
{ | ||
LicenseMojoUtils.prepareThirdPartyOverrideUrl( resolvedUrl, deprecatedFile, url, basedir, log ); | ||
} | ||
|
||
@Test | ||
public void testPrepareThirdPartyOverrideUrlBothOverrides() | ||
{ | ||
deprecatedFile = new File( "src/test/resources/overrides.properties" ); | ||
url = "classpath:overrides.properties"; | ||
try | ||
{ | ||
LicenseMojoUtils.prepareThirdPartyOverrideUrl( resolvedUrl, deprecatedFile, url, basedir, log ); | ||
} | ||
catch( IllegalArgumentException e ) | ||
{ | ||
assertEquals( "You can't use both overrideFile and overrideUrl", e.getMessage() ); | ||
} | ||
} | ||
|
||
@Test | ||
public void testPrepareThirdPartyOverrideUrlNonExistingDeprecatedFile() | ||
{ | ||
deprecatedFile = new File( "foo" ); | ||
String actual = runTestAndJoinResults(); | ||
assertEquals( | ||
"resolved=file:///inexistent\n" | ||
+ "valid=false\n" | ||
+ "WARN 'overrideFile' mojo parameter is deprecated. Use 'overrideUrl' instead.\n" | ||
+ "WARN overrideFile [.../foo] was configured but doesn't exist\n" | ||
+ "DEBUG No (valid) URL and no file [.../override-THIRD-PARTY.properties] found; not loading any overrides" | ||
, actual ); | ||
} | ||
|
||
@Test | ||
public void testPrepareThirdPartyOverrideUrlDeprecatedFile() | ||
{ | ||
deprecatedFile = new File( "src/test/resources/overrides.properties" ); | ||
String actual = runTestAndJoinResults(); | ||
assertEquals( | ||
"resolved=file:/.../overrides.properties\n" | ||
+ "valid=true\n" | ||
+ "WARN 'overrideFile' mojo parameter is deprecated. Use 'overrideUrl' instead.\n" | ||
+ "DEBUG Loading overrides from file file:/.../overrides.properties" | ||
, actual ); | ||
} | ||
|
||
@Test | ||
public void testPrepareThirdPartyOverrideClasspathResource() | ||
{ | ||
url = "classpath:overrides.properties"; | ||
String actual = LicenseMojoUtils.prepareThirdPartyOverrideUrl( resolvedUrl, deprecatedFile, url, basedir, log ); | ||
assertEquals( url, actual ); | ||
assertTrue( LicenseMojoUtils.isValid(actual) ); | ||
assertEquals( "DEBUG Loading overrides from URL classpath:overrides.properties", log.dump() ); | ||
} | ||
|
||
@Test | ||
public void testPrepareThirdPartyOverrideInvalidUrl() | ||
{ | ||
url = "foo://localhost/bar"; | ||
String actual = runTestAndJoinResults(); | ||
assertEquals( | ||
"resolved=file:///inexistent\n" | ||
+ "valid=false\n" | ||
+ "WARN Unsupported or invalid URL [foo://localhost/bar] found in overrideUrl; supported are 'classpath:' URLs and anything your JVM supports (file:, http: and https: should always work)\n" | ||
+ "DEBUG No (valid) URL and no file [.../override-THIRD-PARTY.properties] found; not loading any overrides" | ||
, actual ); | ||
} | ||
|
||
@Test | ||
public void testPrepareThirdPartyOverridePreventReinit() | ||
{ | ||
resolvedUrl = "classpath:overrides.properties"; | ||
deprecatedFile = new File( "foo" ); | ||
url = "classpath:bar"; | ||
String actual = runTestAndJoinResults(); | ||
assertEquals( | ||
"resolved=classpath:overrides.properties\n" | ||
+ "valid=true\n" | ||
+ "WARN 'overrideFile' mojo parameter is deprecated. Use 'overrideUrl' instead." | ||
, actual ); | ||
} | ||
|
||
/** Allow to validate several test results in one assert */ | ||
private String runTestAndJoinResults() | ||
{ | ||
String result = LicenseMojoUtils.prepareThirdPartyOverrideUrl( resolvedUrl, deprecatedFile, url, basedir, log ); | ||
File defaultOverride = new File ( LicenseMojoUtils.DEFAULT_OVERRIDE_THIRD_PARTY ); | ||
String dump = log.dump() | ||
.replace( defaultOverride.getAbsolutePath(), ".../" + defaultOverride.getName() ); | ||
|
||
if ( deprecatedFile != null ) | ||
{ | ||
dump = dump | ||
.replace( deprecatedFile.toURI().toString(), "file:/.../" + deprecatedFile.getName() ) | ||
.replace( deprecatedFile.getAbsolutePath(), ".../" + deprecatedFile.getName() ); | ||
result = result | ||
.replace( deprecatedFile.toURI().toString(), "file:/.../" + deprecatedFile.getName() ); | ||
} | ||
|
||
String actual = "resolved=" + result + "\n" | ||
+ "valid=" + LicenseMojoUtils.isValid( result ) + "\n" | ||
+ dump; | ||
return actual; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
org.jboss.xnio--xnio-api--3.3.6.Final=The Apache Software License, Version 2.0 |