Skip to content

Commit 34f1927

Browse files
author
Björn Ekryd
committed
Adding integration test and logger tests for quiet param.
1 parent 176bb86 commit 34f1927

File tree

6 files changed

+121
-8
lines changed

6 files changed

+121
-8
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>com.github.ekryd.sortpom.its</groupId>
5+
<artifactId>quiet-sorting</artifactId>
6+
<version>0.0.1-SNAPSHOT</version>
7+
<packaging>pom</packaging>
8+
<name>SortPom Plugin :: ITs :: Quiet Sorting</name>
9+
<description>Sorting, but no messages</description>
10+
<url>no-url</url>
11+
<properties>
12+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
13+
</properties>
14+
<dependencies>
15+
<dependency>
16+
<groupId>org.apache.maven.plugin-tools</groupId>
17+
<artifactId>maven-plugin-annotations</artifactId>
18+
<version>RELEASE</version>
19+
<scope>provided</scope>
20+
</dependency>
21+
</dependencies>
22+
<build>
23+
<plugins>
24+
<plugin>
25+
<groupId>com.github.ekryd.sortpom</groupId>
26+
<artifactId>sortpom-maven-plugin</artifactId>
27+
<version>@pom.version@</version>
28+
<executions>
29+
<execution>
30+
<goals>
31+
<goal>sort</goal>
32+
</goals>
33+
<configuration>
34+
<quiet>true</quiet>
35+
</configuration>
36+
</execution>
37+
</executions>
38+
</plugin>
39+
</plugins>
40+
</build>
41+
</project>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
invoker.goals=-e clean verify
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>com.github.ekryd.sortpom.its</groupId>
5+
<artifactId>quiet-sorting</artifactId>
6+
<version>0.0.1-SNAPSHOT</version>
7+
<packaging>pom</packaging>
8+
<name>SortPom Plugin :: ITs :: Quiet Sorting</name>
9+
<description>Sorting, but no messages</description>
10+
<url>no-url</url>
11+
<properties>
12+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
13+
</properties>
14+
<dependencies>
15+
<dependency>
16+
<groupId>org.apache.maven.plugin-tools</groupId>
17+
<artifactId>maven-plugin-annotations</artifactId>
18+
<version>RELEASE</version>
19+
<scope>provided</scope>
20+
</dependency>
21+
</dependencies>
22+
<build>
23+
<plugins>
24+
<plugin>
25+
<groupId>com.github.ekryd.sortpom</groupId>
26+
<artifactId>sortpom-maven-plugin</artifactId>
27+
<version>@pom.version@</version>
28+
<executions>
29+
<execution>
30+
<goals>
31+
<goal>sort</goal>
32+
</goals>
33+
<configuration>
34+
<quiet>true</quiet>
35+
</configuration>
36+
</execution>
37+
</executions>
38+
</plugin>
39+
</plugins>
40+
</build>
41+
</project>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
log = new File(basedir, 'build.log')
2+
sorted = new File(basedir, 'pom.xml')
3+
expected = new File(basedir, 'expected/pom.xml')
4+
backup = new File(basedir, 'pom.xml.bak')
5+
6+
assert log.exists()
7+
assert !log.text.contains('Sorting file ' + sorted.absolutePath)
8+
assert !log.text.contains('Saved backup of ' + sorted.absolutePath + ' to ' + backup.absolutePath)
9+
assert !log.text.contains('Saved sorted pom file to ' + sorted.absolutePath)
10+
assert backup.exists()
11+
assert expected.text.replaceAll('@pom.version@', projectversion).tokenize('\n').equals(sorted.text.replaceAll('\r','').tokenize('\n'))
12+
13+
return true

maven-plugin/src/main/java/sortpom/AbstractParentMojo.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
package sortpom;
22

3+
import java.io.File;
34
import org.apache.maven.plugin.AbstractMojo;
45
import org.apache.maven.plugin.MojoFailureException;
56
import org.apache.maven.plugins.annotations.Parameter;
67
import sortpom.logger.MavenLogger;
78
import sortpom.logger.SortPomLogger;
89

9-
import java.io.File;
10-
1110
/** Common parent for both SortMojo and VerifyMojo */
1211
abstract class AbstractParentMojo extends AbstractMojo {
1312

@@ -126,14 +125,14 @@ abstract class AbstractParentMojo extends AbstractMojo {
126125
@Parameter(property = "sort.sortExecutions", defaultValue = "false")
127126
boolean sortExecutions;
128127

129-
/** Set this to 'true' to bypass sortpom plugin */
130-
@Parameter(property = "sort.skip", defaultValue = "false")
131-
private boolean skip;
132-
133128
/** Whether to keep the file timestamps of old POM file when creating new POM file. */
134129
@Parameter(property = "sort.keepTimestamp", defaultValue = "false")
135130
boolean keepTimestamp;
136131

132+
/** Set this to 'true' to bypass sortpom plugin */
133+
@Parameter(property = "sort.skip", defaultValue = "false")
134+
private boolean skip;
135+
137136
/** Set this to 'true' to disable plugin info output */
138137
@Parameter(property = "sort.quiet", defaultValue = "false")
139138
private boolean quiet;

maven-plugin/src/test/java/sortpom/logger/MavenLoggerTest.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,29 @@ void infoShouldOutputInfoLevel() {
3737
verifyNoMoreInteractions(logMock);
3838
}
3939

40+
@Test
41+
void quietLoggingShouldOutputInfoOnDebugLevel() {
42+
var quietMavenLogger = new MavenLogger(logMock, true);
43+
quietMavenLogger.info("Gurka");
44+
45+
verify(logMock).debug("Gurka");
46+
verifyNoMoreInteractions(logMock);
47+
}
48+
49+
@Test
50+
void quietLoggingShouldStillOutputErrorLevel() {
51+
var quietMavenLogger = new MavenLogger(logMock, true);
52+
quietMavenLogger.error("Error!");
53+
54+
verify(logMock).error("Error!");
55+
verifyNoMoreInteractions(logMock);
56+
}
57+
4058
@Test
4159
void errorShouldOutputErrorLevel() {
42-
mavenLogger.error("Gurka");
60+
mavenLogger.error("Error!");
4361

44-
verify(logMock).error("Gurka");
62+
verify(logMock).error("Error!");
4563
verifyNoMoreInteractions(logMock);
4664
}
4765
}

0 commit comments

Comments
 (0)