0

I have a class called Calculator with the four basic operations of adding, subtracting, dividing and multiplying

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;
        }

    }

I'm using a Maven project and my pom.xml file:

<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>

I created a test in JUnit as follows:

public void testSumWithAssertThat() {
        int expectedValue = 2;
        int returnedValue = calculator.add(1, 1);       
        assertThat(returnedValue, is(expectedValue));
    }

I'm getting the following exception:

java.lang.SecurityException: class "org.hamcrest.Matchers"'s signer information does not match signer information of other classes in the same package

Why are you throwing an exception? What's going wrong with this simple code?

ricardoramos
  • 891
  • 3
  • 18
  • 35
  • 1
    read here http://junit.sourceforge.net/javadoc/org/junit/Assert.html#assertThat(java.lang.String, T, org.hamcrest.Matcher) – DimaSan Nov 10 '16 at 09:48

1 Answers1

1

Make sure that hamcrest.jar is before the JUnit library included in the classpath will resolves the issue.

Umais Gillani
  • 608
  • 4
  • 9