Maven 测试中的编码无法正常工作
我目前正在尝试编写一个通过 Maven 运行的测试,该测试专门处理包含 UTF-8 字符的字符串。如果我在IntelliJ中运行上述测试,一切都很好,结果符合预期。如果我使用 mvn 测试运行测试,则(仅)测试 UTF-8 字符的测试失败。
这是我的测试:
@Test
public void testWithUTF8() throws InvalidKeyException, NoSuchAlgorithmException {
String signature = NFLAuth.sign("Contains UTF-8: äüöööÕßÍÑð");
Assert.assertEquals("Signature=BSY4prbinpAgzJLv6ffGm+XJb1NTIbGY6gTj8RA3lsA=", signature);
}
首先,是的,我读了关于Maven编码的问题,我做了所有的事情。有属性,它添加到编译器插件中,我甚至用file.encoding设置了JAVA_TOOL_OPTIONS,但仍然没有运气。我也不知道它使用的是什么编码,如果我在IntelliJ中尝试windows-1252,测试也会失败,但签名与maven得到的不一样。
以下是 POM:
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>***</groupId>
<artifactId>***</artifactId>
<version>1.0</version>
<name>***</name>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.4</version>
</dependency>
<dependency>
<groupId>com.apigee.edge.4g</groupId>
<artifactId>expressions</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>com.apigee.edge.4g</groupId>
<artifactId>message-flow</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>com.apigee.edge.4g</groupId>
<artifactId>kernel</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/kernel-api-1.0.0.jar</systemPath>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.10.19</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.21</version>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.9.2</version>
</dependency>
</dependencies>
</project>