-
-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
54e69d9
commit 44476a0
Showing
7 changed files
with
229 additions
and
1 deletion.
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
156 changes: 156 additions & 0 deletions
156
license-maven-plugin/src/test/java/com/mycila/maven/plugin/license/XmlPerLineTest.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,156 @@ | ||
/** | ||
* Copyright (C) 2008 Mycila (mathieu.carbou@gmail.com) | ||
* <p> | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* <p> | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.mycila.maven.plugin.license; | ||
|
||
import com.mycila.maven.plugin.license.util.FileUtils; | ||
import org.apache.maven.plugin.MojoExecutionException; | ||
import org.apache.maven.plugin.testing.stubs.MavenProjectStub; | ||
import org.junit.Test; | ||
|
||
import java.io.File; | ||
import java.util.Collections; | ||
|
||
import static org.hamcrest.CoreMatchers.equalTo; | ||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.fail; | ||
|
||
/** | ||
* @author Mathieu Carbou (mathieu.carbou@gmail.com) | ||
*/ | ||
public final class XmlPerLineTest { | ||
|
||
@Test | ||
public void test_add() throws Exception { | ||
File tmp = new File("target/test/issues/issue-191/test_add"); | ||
FileUtils.copyFilesToFolder(new File("src/test/resources/issues/issue-191"), tmp); | ||
|
||
AbstractLicenseMojo plugin = new LicenseFormatMojo(); | ||
plugin.project = new MavenProjectStub(); | ||
plugin.defaultBasedir = tmp; | ||
plugin.legacyConfigHeader = "src/test/resources/issues/issue-191/header1.txt"; | ||
plugin.legacyConfigIncludes = new String[]{"file.xml"}; | ||
plugin.mapping = Collections.singletonMap("xml", "XML_PER_LINE"); | ||
|
||
plugin.execute(); | ||
|
||
String processed = FileUtils.read(new File(tmp, "file.xml"), System.getProperty("file.encoding")); | ||
String expected = FileUtils.read(new File("src/test/resources/issues/issue-191/expected1.xml"), System.getProperty("file.encoding")); | ||
assertThat(processed, is(equalTo(expected))); | ||
} | ||
|
||
@Test | ||
public void test_update() throws Exception { | ||
File tmp = new File("target/test/issues/issue-191/test_update"); | ||
FileUtils.copyFilesToFolder(new File("src/test/resources/issues/issue-191"), tmp); | ||
|
||
AbstractLicenseMojo plugin = new LicenseFormatMojo(); | ||
plugin.project = new MavenProjectStub(); | ||
plugin.defaultBasedir = tmp; | ||
plugin.legacyConfigHeader = "src/test/resources/issues/issue-191/header1.txt"; | ||
plugin.legacyConfigIncludes = new String[]{"file.xml"}; | ||
plugin.mapping = Collections.singletonMap("xml", "XML_PER_LINE"); | ||
|
||
plugin.execute(); | ||
|
||
plugin = new LicenseFormatMojo(); | ||
plugin.project = new MavenProjectStub(); | ||
plugin.defaultBasedir = tmp; | ||
plugin.legacyConfigHeader = "src/test/resources/issues/issue-191/header2.txt"; | ||
plugin.legacyConfigIncludes = new String[]{"file.xml"}; | ||
plugin.mapping = Collections.singletonMap("xml", "XML_PER_LINE"); | ||
|
||
plugin.execute(); | ||
|
||
String processed = FileUtils.read(new File(tmp, "file.xml"), System.getProperty("file.encoding")); | ||
String expected = FileUtils.read(new File("src/test/resources/issues/issue-191/expected2.xml"), System.getProperty("file.encoding")); | ||
assertThat(processed, is(equalTo(expected))); | ||
} | ||
|
||
@Test | ||
public void test_remove() throws Exception { | ||
File tmp = new File("target/test/issues/issue-191/test_remove"); | ||
FileUtils.copyFilesToFolder(new File("src/test/resources/issues/issue-191"), tmp); | ||
|
||
AbstractLicenseMojo plugin = new LicenseFormatMojo(); | ||
plugin.project = new MavenProjectStub(); | ||
plugin.defaultBasedir = tmp; | ||
plugin.legacyConfigHeader = "src/test/resources/issues/issue-191/header1.txt"; | ||
plugin.legacyConfigIncludes = new String[]{"file.xml"}; | ||
plugin.mapping = Collections.singletonMap("xml", "XML_PER_LINE"); | ||
|
||
plugin.execute(); | ||
|
||
plugin = new LicenseRemoveMojo(); | ||
plugin.project = new MavenProjectStub(); | ||
plugin.defaultBasedir = tmp; | ||
plugin.legacyConfigHeader = "src/test/resources/issues/issue-191/header1.txt"; | ||
plugin.legacyConfigIncludes = new String[]{"file.xml"}; | ||
plugin.mapping = Collections.singletonMap("xml", "XML_PER_LINE"); | ||
|
||
plugin.execute(); | ||
|
||
String processed = FileUtils.read(new File(tmp, "file.xml"), System.getProperty("file.encoding")); | ||
String expected = FileUtils.read(new File("src/test/resources/issues/issue-191/file.xml"), System.getProperty("file.encoding")); | ||
assertThat(processed, is(equalTo(expected))); | ||
} | ||
|
||
@Test | ||
public void test_check_failed() throws Exception { | ||
File tmp = new File("target/test/issues/issue-191/test_check_failed"); | ||
FileUtils.copyFilesToFolder(new File("src/test/resources/issues/issue-191"), tmp); | ||
|
||
AbstractLicenseMojo plugin = new LicenseCheckMojo(); | ||
plugin.project = new MavenProjectStub(); | ||
plugin.defaultBasedir = tmp; | ||
plugin.legacyConfigHeader = "src/test/resources/issues/issue-191/header1.txt"; | ||
plugin.legacyConfigIncludes = new String[]{"file.xml"}; | ||
plugin.mapping = Collections.singletonMap("xml", "XML_PER_LINE"); | ||
|
||
|
||
try { | ||
plugin.execute(); | ||
fail(); | ||
} catch (MojoExecutionException e) { | ||
assertEquals("Some files do not have the expected license header", e.getMessage()); | ||
} | ||
} | ||
|
||
@Test | ||
public void test_check_success() throws Exception { | ||
File tmp = new File("target/test/issues/issue-191/test_check_success"); | ||
FileUtils.copyFilesToFolder(new File("src/test/resources/issues/issue-191"), tmp); | ||
|
||
AbstractLicenseMojo plugin = new LicenseFormatMojo(); | ||
plugin.project = new MavenProjectStub(); | ||
plugin.defaultBasedir = tmp; | ||
plugin.legacyConfigHeader = "src/test/resources/issues/issue-191/header1.txt"; | ||
plugin.legacyConfigIncludes = new String[]{"file.xml"}; | ||
plugin.mapping = Collections.singletonMap("xml", "XML_PER_LINE"); | ||
|
||
plugin.execute(); | ||
|
||
plugin = new LicenseCheckMojo(); | ||
plugin.project = new MavenProjectStub(); | ||
plugin.defaultBasedir = tmp; | ||
plugin.legacyConfigHeader = "src/test/resources/issues/issue-191/header1.txt"; | ||
plugin.legacyConfigIncludes = new String[]{"file.xml"}; | ||
plugin.mapping = Collections.singletonMap("xml", "XML_PER_LINE"); | ||
|
||
plugin.execute(); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
license-maven-plugin/src/test/resources/issues/issue-191/expected1.xml
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,21 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<!-- Copyright (c) 2006-2009 --> | ||
<!-- --> | ||
<!-- All rights reserved. --> | ||
<!-- --> | ||
<!-- Licensed under the Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0 --> | ||
<!-- --> | ||
<!-- Unless required by applicable law or agreed to in writing, software --> | ||
<!-- distributed under the License is distributed on an "AS IS" BASIS, --> | ||
<!-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --> | ||
<!-- See the License for the specific language governing permissions and --> | ||
<!-- limitations under the License. --> | ||
|
||
<plugin> | ||
<groupId>com.mycila</groupId> | ||
</plugin> |
19 changes: 19 additions & 0 deletions
19
license-maven-plugin/src/test/resources/issues/issue-191/expected2.xml
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,19 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<!-- Copyright (c) 2006-2009 --> | ||
<!-- --> | ||
<!-- Licensed under the Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0 --> | ||
<!-- --> | ||
<!-- Unless required by applicable law or agreed to in writing, software --> | ||
<!-- distributed under the License is distributed on an "AS IS" BASIS, --> | ||
<!-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --> | ||
<!-- See the License for the specific language governing permissions and --> | ||
<!-- limitations under the License. --> | ||
|
||
<plugin> | ||
<groupId>com.mycila</groupId> | ||
</plugin> |
4 changes: 4 additions & 0 deletions
4
license-maven-plugin/src/test/resources/issues/issue-191/file.xml
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,4 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<plugin> | ||
<groupId>com.mycila</groupId> | ||
</plugin> |
15 changes: 15 additions & 0 deletions
15
license-maven-plugin/src/test/resources/issues/issue-191/header1.txt
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,15 @@ | ||
Copyright (c) 2006-2009 | ||
|
||
All rights reserved. | ||
|
||
Licensed under the Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. |
13 changes: 13 additions & 0 deletions
13
license-maven-plugin/src/test/resources/issues/issue-191/header2.txt
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,13 @@ | ||
Copyright (c) 2006-2009 | ||
|
||
Licensed under the Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. |