@RunWith(PowerMockRunner.class)
@PrepareForTest(Topic_Service.class)
class Topic_Service_test
{
private Topic_Service topic_service = PowerMockito.spy(new Topic_Service());
@Test
void testing_test() throws Exception
{
PowerMockito.doReturn("hello").when(topic_service, "test_help");
String s = topic_service.testing();
Assertions.assertEquals("hello testing",s);
}
}
@Service
public class Topic_Service
{
private String test_help()
{
return "test_help";
}
public String testing()
{
return test_help() + " " + "testing";
}
}
POM.XML Dependencies
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mockito/mockito-core -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version> 2.8.47</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>1.7.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito2</artifactId>
<version>1.7.0</version>
<scope>test</scope>
</dependency>
ОШИБКА: -
WARNING: An illegal reflective access operation has occurred WARNING: Illegal reflective access by org.powermock.reflect.internal.WhiteboxImpl (file:/home/an.kumar1/.m2/repository/org/powermock/powermock-reflect/1.7.0/powermock-reflect-1.7.0.jar) to method java.lang.Object.finalize() WARNING: Please consider reporting this to the maintainers of org.powermock.reflect.internal.WhiteboxImpl WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations WARNING: All illegal access operations will be denied in a future release
org.opentest4j.AssertionFailedError: Expected :hello testing Actual :null
Может кто-нибудь помочь? Заранее спасибо