I have the following Java Enum:
enum IssueMap {
ISSUE_TYPE,
public static .... getIssueTypes(String IssueName) {
return ...;
}
}
Notice that I don't have public keyword in front of a enum!
I want to call this code into JUnit test like this:
@Test
public void genericTest() {
....... = IssueMap.getIssueTypes(....);
assertNotNull(...);
}
I get error 'com.IssueMap' is not public in 'com....'. Cannot be accessed from outside package
I can't change the original enum code. Is there some solution with reflection for example to access the enum code?
Your IssueMap enum is not private, but rather package-private. If your test class is in the same package name as your IssueMap enum then your test class should be able to access the IssueMap enum without changing the IssueMap enum
package com.myenum;
enum IssueMap {
ISSUE_TYPE,
public static .... getIssueTypes(String IssueName) {
return ...;
}
}
package com.myenum;
class IssueMapTest {
@Test
public void genericTest() {
....... = IssueMap.getIssueTypes(....);
assertNotNull(...);
}
}
Notice the package name in IssueMap and IssueMapTest are the same. Even though my IssueMap path is src/main/java/com/myenum/IssueMap.java and IssueMapTest path is src/test/java/com/myenum/IssueMapTest.java