Questions tagged [powermockito]

Use this tag for questions about PowerMockito, a Java Framework that allows the mocking of usually un-mockable types, i.e. statics, and private methods, in conjunction with the Mockito framework. Questions about using PowerMock with EasyMock should be tagged [powermock] instead.

PowerMockito is used in addition with the Java Framework Mockito. PowerMockito's main strength is the ability to mock Static and Private Methods. A good example of PowerMocktio is the ability to mock Singletons which are generally difficult when unit testing.

Heres a great link to starting out with PowerMockito: Using PowerMock with Mockito

1326 questions
-1
votes
1 answer

Testing a method which calls a static method of a final class

I have been trying write a test method for a class which just makes a call to static method of a final Util class. This is the class I am trying to test public class Processor { public Double calculateAmount(Double total, List
Turan
  • 1
  • 2
-1
votes
2 answers

Powermockito static method call

I have a class A which has a static method testA(String auditUser, Timestamp timestamp) which calls a static method of class B if auditUser is admin. I am trying to write test for class A. How can I verify the static method of B got called or…
Appu2506
  • 1
  • 2
-1
votes
1 answer

Is there any way to Mock the private method , which is there in other class

As per my knowledge, We can Mock the private method in same class by using PowerMockito. With in the same class is working fine for me , but when i'm calling private method from the other class it's not working. Below Example i've 2 classes ,…
Praveen
  • 3
  • 7
-1
votes
1 answer

Mock a void method

//Original method: @Autowired private ConversionServiceValidator validator; public CRSConversionResult convertCRS(ConvertCrsVo convertCrsVo) throws Exception { if (validator.isSameSourceAndTarget(convertCrsVo)) throw new…
arun
  • 57
  • 7
-1
votes
1 answer

java.lang.IllegalAccessException:.cannot access the member of class CrossOrigin with modifiers "private static"

I am trying to mock the controller class with some endpoints annotated with @CrossOrigin. it is giving this exception. Caused by: java.lang.IllegalAccessException: Class net.bytebuddy.description.annotation.AnnotationDescription$ForLoadedAnnotation…
-1
votes
1 answer

PowerMockito.doNothing() throws Null Pointer Exception

I am mocking ObjectOutputStream void method .writeObject() but it is throwing null pointer exception. How do i mock the void functions using Mockito/PowerMockito. Class public class SomeClass { public void someMethod() { //something …
TheDominus
  • 179
  • 3
  • 11
-1
votes
1 answer

Can't mock the methods inside the constructor

Here is my first class where the constructor has an object calling methods in other class. Class Search{ public Search(String username, JSONObject accounts) throws Exception { Credentials credentials = new Credentials(username); …
Batman
  • 103
  • 3
  • 12
-1
votes
1 answer

How to mock if condition using JUnit?

I am trying to mock a method using mockito. How to mock if condition using mockito? Here is my code @Override public RemedyWrapperOutput createRemedyTicket(RemedyWrapperInput remedyWrapperInput) throws Exception { logger.info("Inside…
Yashaswini H
  • 1
  • 1
  • 1
  • 1
-1
votes
1 answer

how to mock timestamp and date function in java?

how to mock following code? i dont want to change my code. Date date = new Date(); String res_timestamp=new Timestamp(date.getTime()).toString(); my code: SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); …
karthick S
  • 51
  • 1
  • 2
  • 9
-1
votes
1 answer

NoClassDefFoundError when using @RunWith(PowerMockRunner.class)

I am running a junit test case using the PowerMock test runner. When I'm running the class, I'm receiving this error: java.lang.NoClassDefFoundError: org/powermock/tests/utils/TestSuiteChunker Caused by: java.lang.ClassNotFoundException:…
karthick S
  • 51
  • 1
  • 2
  • 9
-1
votes
1 answer

PowerMockito final Static method calls actual method

I have statements like public void dummyMethod() { CreateTableRequest ctr = dynamoDBMapper.generateCreateTableRequest(RolePolicies.class); ctr.setProvisionedThroughput(new ProvisionedThroughput(30L, 5L)); …
MalTec
  • 1,350
  • 2
  • 14
  • 33
-1
votes
5 answers

Java Futures returning null while using Mockito

class Student{ int age; String name; } class Demo{ public void getStudentList() { Future> future = client.getAsyncData(); List response = futures.get(100l, TimeUnit .MILLISECONDS); } } class StudentTest{ …
rUCHit31
  • 334
  • 1
  • 3
  • 15
-1
votes
3 answers

How to test a void function with sequential calls

How can one test a function that does not return a value, but uses given arguments to construct some values which are being sent to a sequential function? For example public void handleSomeEvent(String str1, String str2){ MyObject obj1 = new…
iddqd
  • 1,225
  • 2
  • 16
  • 34
-1
votes
1 answer

How to mock new instance where it return interface reference

I have a scenario like this MyInterface myObject = new MyInterfaceImplementedClass(); myObject.get(...) I want to mock the MyInterfaceImplementedClass, I tried like below private MyInterface mockMyObject private MyInterfaceImplementedClass…
-1
votes
1 answer

mockito Powermockito object mapper

I am using the following to mock writeValueAsString(any()) method in the object mapper. However the writeValueAsString method is not getting mocked and getting called in the method I am testing in the application. I did try spy as well but it did…
user9063834
  • 85
  • 1
  • 8