0
votes

I created the following code which throws me "java.lang.IllegalArgumentException: argument type mismatch" exception. I believe it is caused by the incorrect return type Iterable. But I tried with Collection and Iterable, both throws me the argument type mismatch exception. Can someone please help? Thanks in advance. From the trace, it throws the exception after finishing the input() method.

@Parameterized.Parameters
public static Iterable<Object[]> input() {
    ArrayList<String>srcList = new ArrayList<String>();
    ArrayList<String>otherList = new ArrayList<String>();

    return Arrays.asList(new Object[][] {
        {srcList.add("https://www.test1.com"),20},
        {otherList.add("https://www.test2.com"),20}
    });
}

public WDDiffJunit2(ArrayList<String> url, int errCount) {
    this.url = url;
    this.errCount = errCount;
}

@Test
public void Test3() {     
    System.out.println("start test3");     
    loginPresenter.setModel(loginModel);
    loginPresenter.readProperties();
    loginPresenter.login();
    diffPresenter.setModel(diffModel);
    diffPresenter.setLoginModel(loginModel);
        assertEquals(errCount,diffPresenter.getExtractMaps(url,false).values().size());
}


public HashMap<String, String> getExtractMaps(ArrayList<String> urls, boolean isSource) {
     HashMap<String, String> a = new HashMap<String, String>();
     a.put("a","a");
     return a;
}

Stack Trace

java.lang.IllegalArgumentException: argument type mismatch at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:526) at org.junit.runners.Parameterized$TestClassRunnerForParameters.createTest(Parameterized.java:86) at org.junit.runners.BlockJUnit4ClassRunner$1.runReflectiveCall(BlockJUnit4ClassRunner.java:236) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) at org.junit.runners.BlockJUnit4ClassRunner.methodBlock(BlockJUnit4ClassRunner.java:233) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222) at org.junit.runners.ParentRunner.run(ParentRunner.java:300) at org.junit.runners.Suite.runChild(Suite.java:128) at org.junit.runners.Suite.runChild(Suite.java:24) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28) at org.junit.runners.ParentRunner.run(ParentRunner.java:300) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

1
As mentioned on top, It throws me java.lang.IllegalArgumentException: argument type mismatch exception.Lazyworm
Forgot to add the constructor. Thanks in advance. public WDTeamcityDiffJunit2(ArrayList<String> url, int errCount) { this.url = url; this.errCount = errCount; }Lazyworm
First of all, "I am getting an exception" is not really a question, but a story. Second of all, even if there were a question here, there would not be enough information here to be able to answer it. Please review our SO Question Checklist to help you to ask a good question, and thus get a good answer. Finally, please do not post code in comments, as it doesn't format well. Please use the edit button above to edit your question.Joe C
From the checklist: "If your program throws an exception, have you included the exception, with both the message and the stack trace?"Joe C
I included the exception in the original message. Now even highlighted. Please let me know if it is acceptable and remove the negative if it is fine with you.Lazyworm

1 Answers

1
votes

Replace ...

@Parameterized.Parameters
public static Iterable<Object[]> input() {
    ArrayList<String>srcList = new ArrayList<String>();
    ArrayList<String>otherList = new ArrayList<String>();

    return Arrays.asList(new Object[][] {
            {srcList.add("https://www.test1.com"),20},
            {otherList.add("https://www.test2.com"),20}
    });
}

... with:

@Parameterized.Parameters
public static Iterable<Object[]> input() {
    ArrayList<String> srcList = new ArrayList<String>();
    srcList.add("https://www.test1.com");
    ArrayList<String>otherList = new ArrayList<String>();
    otherList.add("https://www.test2.com");

    return Arrays.asList(new Object[][] {
            {srcList,20},
            {otherList,20}
    });
}

In its original form you were creating an Object[][] of boolean, int because srcList.add(...) returns a boolean. If you populate the srcList and otherList outside of the Object[][] initialiser then you'll end up with an Object[][] of the correct type: List, int.