我有一个名为Calculator的类,它有四个基本操作:加,减,除和乘
public class Calculator{
public int add(int a, int b) {
return a + b;
}
public int subtract(int a, int b) {
return a - b;
}
public double multiply(double a, double b) {
return a * b;
}
public double divide(double a, double b) {
if (b == 0) {
throw new ArithmeticException("Division by zero.");
}
return a / b;
}
}
我正在使用Maven项目和我的pom.xml文件:
<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>br.usp.icmc</groupId>
<artifactId>Calculadora</artifactId>
<version>0.0.1</version>
<dependencies>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
<version>1.3</version>
</dependency>
</dependencies>
</project>
我在JUnit中创建了一个测试,如下所示:
public void testSumWithAssertThat() {
int expectedValue = 2;
int returnedValue = calculator.add(1, 1);
assertThat(returnedValue, is(expectedValue));
}
我收到以下异常:
java.lang.SecurityException: class "org.hamcrest.Matchers"'s signer information does not match signer information of other classes in the same package
你为什么要抛出异常?这个简单的代码出了什么问题?
答案 0 :(得分:1)
确保 hamcrest.jar 位于类路径中包含的 JUnit库之前解决问题。