Home>

I'm creating JUnit.
In it, I want to test the private method, so I made it accessible using PowerMockito and
I want to test.

However, there is a method that passes an array in the method to be tested, and I do not know how to specify it.
I tried various things, but couldn't I specify the correct type?
java.lang.NoSuchMethodException
I would like you to teach me the class that should be specified.
Thank you.

java.lang.NoSuchMethodException
Corresponding source code

Tested class

private List<String>test (List<String>strList, String [] strArr) {
  List<String>res = new ArrayList<>();
  for (int i = 0;i<strList.size ();i ++) {
    res.add (strList.get (i) + "_" + strArr [0]);
  }
  return res;
}

Test class

@InjectMocks
TestClass _target;
@Before
public void setUp () throws Exception {
  _target = new TestClass ();
}
@Test
private void test_junit () throws Exception {
  Method method = DbViewerGetTableDataLogic.class.getDeclaredMethod (
      "test", List.class,/* I don't know which class to write here * /);
  method.setAccessible (true);
  List<String>strList = Arrays.asList ("list1", "list2");
  String [] arr = {"arr1", "arr2"};
  List<String>expect = Arrays.asList ("list1_arr1", "list2_arr2");
  TestClass spy = PowerMockito.spy (_target);
  List<String>actual = (List<String>) method.invoke (spy, strList, strArr);
  assertThat (actual, is (expect));
}

Comment out section

/ * I don't know which class to write here * /


I want to know the class to write in.

What I tried

String.class
Array.class
I tried, but all of them resulted in NoSuchMethodException.

I'm sorry for the introductory question, but I would appreciate it if you could teach me.