-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Include/exclude project properties (#126)
- Loading branch information
1 parent
e0c06b1
commit da25f0a
Showing
4 changed files
with
147 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
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
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
90 changes: 90 additions & 0 deletions
90
src/test/java/org/codehaus/mojo/properties/WritePropertiesMojoTest.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,90 @@ | ||
package org.codehaus.mojo.properties; | ||
|
||
import java.io.File; | ||
import java.io.FileReader; | ||
import java.io.IOException; | ||
import java.util.Collections; | ||
import java.util.Properties; | ||
import java.util.UUID; | ||
|
||
import org.apache.maven.project.MavenProject; | ||
import org.codehaus.mojo.properties.managers.JdkPropertiesManager; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.TemporaryFolder; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertFalse; | ||
|
||
public class WritePropertiesMojoTest { | ||
|
||
@Rule | ||
public TemporaryFolder temporaryFolder = new TemporaryFolder(); | ||
|
||
private MavenProject projectStub; | ||
private WriteProjectProperties writeProjectProperties; | ||
private File outputFile; | ||
|
||
@Before | ||
public void setUp() throws IOException { | ||
projectStub = new MavenProject(); | ||
writeProjectProperties = new WriteProjectProperties(Collections.singletonList(new JdkPropertiesManager())); | ||
writeProjectProperties.setProject(projectStub); | ||
outputFile = temporaryFolder.newFile(); | ||
writeProjectProperties.setOutputFile(outputFile); | ||
} | ||
|
||
@Test | ||
public void projectPropertiesAreWritten() throws Exception { | ||
String propertyKey = UUID.randomUUID().toString(); | ||
projectStub.getProperties().put(propertyKey, "foo"); | ||
|
||
writeProjectProperties.execute(); | ||
|
||
try (FileReader fr = new FileReader(outputFile)) { | ||
Properties writtenProperties = new Properties(); | ||
writtenProperties.load(fr); | ||
|
||
assertEquals("foo", writtenProperties.getProperty(propertyKey)); | ||
} | ||
} | ||
|
||
@Test | ||
public void onlyIncludedPropertiesAreWritten() throws Exception { | ||
String includedKey = UUID.randomUUID().toString(); | ||
projectStub.getProperties().put(includedKey, "foo"); | ||
String excludedKey = UUID.randomUUID().toString(); | ||
projectStub.getProperties().put(excludedKey, "foo"); | ||
|
||
writeProjectProperties.setIncludedPropertyKeys(Collections.singleton(includedKey)); | ||
writeProjectProperties.execute(); | ||
|
||
try (FileReader fr = new FileReader(outputFile)) { | ||
Properties writtenProperties = new Properties(); | ||
writtenProperties.load(fr); | ||
|
||
assertEquals("foo", writtenProperties.getProperty(includedKey)); | ||
assertFalse(writtenProperties.contains(excludedKey)); | ||
} | ||
} | ||
|
||
@Test | ||
public void onlyNonExcludedPropertiesAreWritten() throws Exception { | ||
String includedKey = UUID.randomUUID().toString(); | ||
projectStub.getProperties().put(includedKey, "foo"); | ||
String excludedKey = UUID.randomUUID().toString(); | ||
projectStub.getProperties().put(excludedKey, "foo"); | ||
|
||
writeProjectProperties.setExcludedPropertyKeys(Collections.singleton(excludedKey)); | ||
writeProjectProperties.execute(); | ||
|
||
try (FileReader fr = new FileReader(outputFile)) { | ||
Properties writtenProperties = new Properties(); | ||
writtenProperties.load(fr); | ||
|
||
assertEquals("foo", writtenProperties.getProperty(includedKey)); | ||
assertFalse(writtenProperties.contains(excludedKey)); | ||
} | ||
} | ||
} |