Skip to content

Commit 6dc01d8

Browse files
authored
Merge pull request #65 from powerunit/extensions/org.apache.commons.collections4
Optional support for commons-collections4 - Close #64
2 parents cb8b6eb + 775057d commit 6dc01d8

File tree

11 files changed

+510
-23
lines changed

11 files changed

+510
-23
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ after_success:
3737
- "curl -s https://report.ci/annotate.py | python - --name annotate$TRAVIS_OS_NAME$TRAVIS_JDK_VERSION --tool java --input maven.log"
3838
- "curl -s https://report.ci/upload.py | python - --name upload$TRAVIS_OS_NAME$TRAVIS_JDK_VERSION --include='*.xml' --framework=junit"
3939
- "(cd target/dependency && java -jar codacy-coverage-reporter-6.0.0-assembly.jar report -l Java -r ../site/jacoco/jacoco.xml)"
40-
- if [[ "$TRAVIS_JDK_VERSION" = oraclejdk9 ]]; then mvn site ; fi
41-
- if [[ "$TRAVIS_JDK_VERSION" = oraclejdk9 ]]; then git fetch --unshallow ; fi
4240
- if [[ "$TRAVIS_JDK_VERSION" = oraclejdk9 ]]; then mvn sonar:sonar -Dsonar.projectKey=powerunit_powerunit-extensions-exceptions ; fi
41+
- if [[ "$TRAVIS_JDK_VERSION" = oraclejdk9 ]]; then rm -f target/classes/module-info.class; mvn site ; fi
42+
- if [[ "$TRAVIS_JDK_VERSION" = oraclejdk9 ]]; then git fetch --unshallow ; fi
4343
before_deploy:
4444
- git config --local user.name "powerunitci"
4545
- git config --local user.email "powerunitci@powerunit.ch"

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,13 @@ Also, some dedicated, _ready to used_, Exception Mapper are provided :
161161
* `saxExceptionMapper()` - Return an exception mapper that adds to the message of the `RuntimeException` the SAX Error from the underlying exception. **This is only usable when the module java.xml is available**.
162162
* `transformerExceptionMapper()` - Return an exception mapper that adds to the message of the `RuntimeException` the Transformer Error from the underlying exception. **This is only usable when the module java.xml is available**.
163163

164+
### CommonsCollections4Helper
165+
166+
_This helper is only available since version 2.2.0 and only if the commons-collections4 library is available_
167+
168+
The class `CommonsCollections4Helper` provides several static methods to convert interface
169+
from this library to the corresponding version in commons-collections4.
170+
164171
## Reference
165172

166173
The following classes are provided:

pom.xml

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,26 @@
379379
</dependency>
380380
</dependencies>
381381
</plugin>
382-
382+
<plugin>
383+
<artifactId>maven-invoker-plugin</artifactId>
384+
<configuration>
385+
<cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo>
386+
<localRepositoryPath>${project.build.directory}/local-repo</localRepositoryPath>
387+
<preBuildHookScript>prepare.bsh</preBuildHookScript>
388+
<postBuildHookScript>verify.bsh</postBuildHookScript>
389+
<settingsFile>src/it/settings.xml</settingsFile>
390+
<invokerPropertiesFile>params.properties</invokerPropertiesFile>
391+
</configuration>
392+
<executions>
393+
<execution>
394+
<id>integration-test</id>
395+
<goals>
396+
<goal>install</goal>
397+
<goal>run</goal>
398+
</goals>
399+
</execution>
400+
</executions>
401+
</plugin>
383402
</plugins>
384403
<resources>
385404
<resource>
@@ -439,26 +458,6 @@
439458
</execution>
440459
</executions>
441460
</plugin>
442-
<plugin>
443-
<artifactId>maven-invoker-plugin</artifactId>
444-
<configuration>
445-
<cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo>
446-
<localRepositoryPath>${project.build.directory}/local-repo</localRepositoryPath>
447-
<preBuildHookScript>prepare.bsh</preBuildHookScript>
448-
<postBuildHookScript>verify.bsh</postBuildHookScript>
449-
<settingsFile>src/it/settings.xml</settingsFile>
450-
<invokerPropertiesFile>params.properties</invokerPropertiesFile>
451-
</configuration>
452-
<executions>
453-
<execution>
454-
<id>integration-test</id>
455-
<goals>
456-
<goal>install</goal>
457-
<goal>run</goal>
458-
</goals>
459-
</execution>
460-
</executions>
461-
</plugin>
462461
</plugins>
463462
</build>
464463
</profile>
@@ -546,5 +545,12 @@
546545
<scope>test</scope>
547546
<optional>true</optional>
548547
</dependency>
548+
<dependency>
549+
<groupId>org.apache.commons</groupId>
550+
<artifactId>commons-collections4</artifactId>
551+
<scope>compile</scope>
552+
<optional>true</optional>
553+
<version>4.4</version>
554+
</dependency>
549555
</dependencies>
550556
</project>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
invoker.java.version=9
2+
invoker.goals.1=dependency:resolve
3+
invoker.goals.2=dependency:resolve-plugins
4+
invoker.goals.3=dependency:go-offline
5+
invoker.goals.4=clean install
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<groupId>ch.powerunit.demo</groupId>
6+
<artifactId>collections</artifactId>
7+
<version>@project.version@ </version>
8+
<name>Powerunit - Java Testing framework for JDK 1.8 - HelloWorld Maven</name>
9+
<packaging>jar</packaging>
10+
11+
<properties>
12+
<maven.compiler.source>9</maven.compiler.source>
13+
<maven.compiler.target>9</maven.compiler.target>
14+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15+
<jaxb-api.version>2.3.0.1</jaxb-api.version>
16+
</properties>
17+
18+
<build>
19+
<pluginManagement>
20+
<plugins>
21+
<plugin>
22+
<groupId>org.apache.maven.plugins</groupId>
23+
<artifactId>maven-compiler-plugin</artifactId>
24+
<version>3.8.1</version>
25+
</plugin>
26+
<plugin>
27+
<groupId>org.apache.maven.plugins</groupId>
28+
<artifactId>maven-dependency-plugin</artifactId>
29+
<version>3.1.1</version>
30+
</plugin>
31+
<plugin>
32+
<groupId>org.codehaus.mojo</groupId>
33+
<artifactId>exec-maven-plugin</artifactId>
34+
<version>1.6.0</version>
35+
</plugin>
36+
</plugins>
37+
</pluginManagement>
38+
39+
<plugins>
40+
<plugin>
41+
<groupId>org.apache.maven.plugins</groupId>
42+
<artifactId>maven-jar-plugin</artifactId>
43+
<configuration>
44+
<archive>
45+
<manifest>
46+
<mainClass>ch.powerunittest.samples.FunctionSamplesTest</mainClass>
47+
</manifest>
48+
</archive>
49+
</configuration>
50+
</plugin>
51+
<plugin>
52+
<groupId>org.codehaus.mojo</groupId>
53+
<artifactId>exec-maven-plugin</artifactId>
54+
<executions>
55+
<execution>
56+
<id>Test main 1</id>
57+
<goals>
58+
<goal>exec</goal>
59+
</goals>
60+
<phase>package</phase>
61+
<configuration>
62+
<executable>java</executable>
63+
<longModulepath>false</longModulepath>
64+
<arguments>
65+
<argument>--module-path</argument>
66+
<argument>${project.build.directory}/../../../local-repo/ch/powerunit/extensions/powerunit-extensions-exceptions/@project.version@/powerunit-extensions-exceptions-@project.version@.jar${path.separator}${project.build.directory}/${project.build.finalName}.jar</argument>
67+
<argument>--module</argument>
68+
<argument>powerunit.test/ch.powerunittest.samples.CollectionsTest</argument>
69+
<argument>NO</argument>
70+
</arguments>
71+
</configuration>
72+
</execution>
73+
<execution>
74+
<id>Test main 2</id>
75+
<goals>
76+
<goal>exec</goal>
77+
</goals>
78+
<phase>package</phase>
79+
<configuration>
80+
<executable>java</executable>
81+
<longModulepath>false</longModulepath>
82+
<arguments>
83+
<argument>--module-path</argument>
84+
<argument>${project.build.directory}/../../../local-repo/org/apache/commons/commons-collections4/4.4/commons-collections4-4.4.jar${path.separator}${project.build.directory}/../../../local-repo/ch/powerunit/extensions/powerunit-extensions-exceptions/@project.version@/powerunit-extensions-exceptions-@project.version@.jar${path.separator}${project.build.directory}/${project.build.finalName}.jar</argument>
85+
<argument>--add-modules</argument>
86+
<argument>org.apache.commons.collections4</argument>
87+
<argument>--module</argument>
88+
<argument>powerunit.test/ch.powerunittest.samples.CollectionsTest</argument>
89+
<argument>YES</argument>
90+
</arguments>
91+
</configuration>
92+
</execution>
93+
</executions>
94+
</plugin>
95+
</plugins>
96+
97+
</build>
98+
99+
<dependencies>
100+
<dependency>
101+
<groupId>ch.powerunit.extensions</groupId>
102+
<artifactId>powerunit-extensions-exceptions</artifactId>
103+
<version>@project.version@</version>
104+
</dependency>
105+
<dependency>
106+
<groupId>org.apache.commons</groupId>
107+
<artifactId>commons-collections4</artifactId>
108+
<scope>compile</scope>
109+
<optional>true</optional>
110+
<version>4.4</version>
111+
</dependency>
112+
</dependencies>
113+
114+
</project>
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/**
2+
* Powerunit - A JDK1.8 test framework
3+
* Copyright (C) 2014 Mathieu Boretti.
4+
*
5+
* This file is part of Powerunit
6+
*
7+
* Powerunit is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* Powerunit is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with Powerunit. If not, see <http://www.gnu.org/licenses/>.
19+
*/
20+
package ch.powerunittest.samples;
21+
22+
import java.util.function.Function;
23+
24+
import java.io.IOException;
25+
26+
import ch.powerunit.extensions.exceptions.CommonsCollections4Helper;
27+
import ch.powerunit.extensions.exceptions.ExceptionHandlerSupport;
28+
import ch.powerunit.extensions.exceptions.ExceptionMapper;
29+
import ch.powerunit.extensions.exceptions.FunctionWithException;
30+
import ch.powerunit.extensions.exceptions.WrappedException;
31+
32+
public class CollectionsTest {
33+
34+
public static void sample1() {
35+
36+
FunctionWithException<String, String, IOException> fonctionThrowingException = x -> x;
37+
38+
Function<String, String> functionThrowingRuntimeException = FunctionWithException
39+
.unchecked(fonctionThrowingException);
40+
41+
if (!"x".equals(functionThrowingRuntimeException.apply("x"))) {
42+
throw new IllegalArgumentException("The result is not correct");
43+
}
44+
45+
}
46+
47+
public static void sample2() {
48+
49+
try {
50+
CommonsCollections4Helper.asPredicate(x -> true);
51+
} catch (NoClassDefFoundError e) {
52+
e.printStackTrace();
53+
return;
54+
}
55+
throw new IllegalArgumentException("No exception thrown");
56+
}
57+
58+
public static void sample3() {
59+
60+
if (!CommonsCollections4Helper.asPredicate(x -> true).evaluate("x")) {
61+
throw new IllegalArgumentException("Should be true");
62+
}
63+
}
64+
65+
public static void main(String[] args) {
66+
sample1();
67+
if (args.length > 0 && "NO".equals(args[0])) {
68+
sample2();
69+
} else if (args.length > 0 && "YES".equals(args[0])) {
70+
sample3();
71+
}
72+
}
73+
74+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module powerunit.test {
2+
requires powerunit.exceptions;
3+
requires static org.apache.commons.collections4;
4+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import java.io.*;

0 commit comments

Comments
 (0)