0

I have a test class testing whether a ParseExeption is thrown when invalid terms are added to command line arguments (or if some are missing). Without Mockito's packages installed into the project, the tests pass. Once I install Mockito via gradle, the tests fail with the following messages.

java.lang.NoSuchMethodError: org.hamcrest.Matcher.describeMismatch(Ljava/lang/Object;Lorg/hamcrest/Description;)V

at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:18)
at org.junit.Assert.assertThat(Assert.java:956)
at org.junit.Assert.assertThat(Assert.java:923)
at org.junit.rules.ExpectedException.handleException(ExpectedException.java:252)
at org.junit.rules.ExpectedException.access$000(ExpectedException.java:106)
at org.junit.rules.ExpectedException$ExpectedExceptionStatement.evaluate(ExpectedException.java:241)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:27)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)

The code for the tests:

import org.apache.commons.cli.ParseException;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

import java.io.File;


public class CliTest {

    private File testFile = new File(System.getProperty("user.dir")
            + File.separator
            + "src/test/resources/xsbf161.r1r2.43bp.breakseq.excl.Xsam");

    private File validRangeFile = new File(System.getProperty("user.dir")
            + File.separator
            + "src/test/resources/60XMF009-1-UX.csv");

    private File validRangeFile2 = new File(System.getProperty("user.dir")
            + File.separator
            + "src/test/resources/hellod.csv");

    Cli cli;

    @Before
    public void setup(){

    }

    @Rule
    public ExpectedException thrown = ExpectedException.none();

    @Test
    public void noInputFilethrowsException() throws ParseException{
        String[] args = {"--st1=PPE....,XSam"};

        thrown.expect(ParseException.class);
        thrown.expectMessage("No input file");

        cli = new Cli(args);
        cli.parse();
    }

    @Test
    public void invalidFileThrowsParseException() throws ParseException{
        String[] args = {"--if=doesntexist.Xsam","--st1=PPE....,XSam"};
        thrown.expect(ParseException.class);
        thrown.expectMessage("Input file does not exist");

        cli = new Cli(args);
        cli.parse();
    }

    @Test
    public void noStreamsThrowsParseException() throws ParseException{
        String[] args = {String.format("--if=%s", testFile.toString())};

        thrown.expect(ParseException.class);
        thrown.expectMessage("No streams selected");

        cli = new Cli(args);
        cli.parse();

    }


}

gradle import order:

compile group: 'junit', name: 'junit', version: '4.12'
// https://mvnrepository.com/artifact/commons-cli/commons-cli
compile group: 'commons-cli', name: 'commons-cli', version: '1.4'
// https://mvnrepository.com/artifact/org.mockito/mockito-all
testCompile group: 'org.mockito', name: 'mockito-all', version: '1.10.19'
Arty
  • 749
  • 2
  • 11
  • 24
Sam
  • 922
  • 1
  • 10
  • 23
  • Can you please post the order of your imports? – Kirill Feb 26 '18 at 09:42
  • Yes, it was a complication of using mockito-all rather than mockito-core. That solved the issue. You can mark it as a dupilcate. – Sam Feb 26 '18 at 09:50

0 Answers0