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
4 answers

LocalDateTime.of returns null

I am trying to Unit test code that uses java.time.LocalDateTime. I'm able to get the mock working, however when I add time (either minutes or days) I end up with a null value. @RunWith(PowerMockRunner.class) @PrepareForTest({ LocalDateTime.class…
Adam Erstelle
  • 2,454
  • 3
  • 21
  • 35
-1
votes
1 answer

mock a public method of other class in a method (java)

I am new to Mockito. For the code: public class A{ public A{ ... B.fff(); //the function I want to mock ... } } public class B{ public boolean fff(){ ... ... //connect DB ... } } For the unit…
-1
votes
1 answer

Mock static default interface method

I need to create a unit test for the following case: Class under test: class MyProducer { private Producer producer = null; private ProducerCreator producerCreator = null; public MyProducer() { producerCreator = ProducerCreator.create(string…
Eric Abramov
  • 462
  • 4
  • 19
-1
votes
1 answer

PowerMocking Static method within Class Under Test

I am currently working on implementing a unit test for our Exit Code Manager that were implemented using static methods. The problem that I encounter is how can I mock the executeExit, which calls System.exit(), method so that it would not terminate…
Vaanz
  • 175
  • 1
  • 2
  • 14
-1
votes
1 answer

Couldn't run android unit test cases with Mockito

My Gradle Configuration: testCompile 'org.mockito:mockito-core:2.4.0' testCompile 'org.powermock:powermock-module-junit4:1.7.0RC2' testCompile 'org.powermock:powermock-api-mockito:1.7.0RC2' With these Gradle setting, when I try to run the unit test…
-1
votes
2 answers

How to mock private method which uses inject objects in java for unit test?

For testing my DedupServiceWrapperImpl class I need to mock to private method "isDedupEnabled" and "isNew". this is the class under the test: public class DedupServiceWrapperImpl implements DedupServiceWrapper { @Inject private DedupService…
m.mjn202
  • 43
  • 1
  • 9
-1
votes
1 answer

Mocking final static void method using powermock and return some values based on the arguments

I was trying to mock a final static void method inside a final class. I want to return some values using the arguments in my final method. I am using powermockito. can anyone tell me how we can mock a final static void method and return some value…
user7552694
-1
votes
1 answer

How can i mock a REST Request from Spring Framework inside a method

I got a method which includes a REST-request(Spring-Social) and i want to mock it. The thing is that i dont know how to access the call inside it or if it is possible at all. I got Mockito and PowerMock at my disposal private…
Maevy
  • 261
  • 4
  • 24
-1
votes
1 answer

How to test in scenario many methods calling one helper method

For example here is my scenario: function A() { C(); } function B() { C(); } function C() { if (someState > 0) then doSomething(); else doSomethingElse(); } I want to make all test case that coverage all code. Because C() has a…
hqt
  • 29,632
  • 51
  • 171
  • 250
-1
votes
1 answer

Cannot subclass final class when using testng

In my project there is requirement where in I need to mock final class. I am using Test-NG for unit tests. I tried different things to mock but failed to do so. I also checked different stack overflow posts. When running testng test case I am…
GauravP
  • 81
  • 3
  • 14
-1
votes
1 answer

Unfinished stubbing detected

The error below appeared in my code when using mockito: org.mockito.exceptions.misusing.UnfinishedStubbingException: Unfinished stubbing detected here: -> at…
user3123934
  • 1,001
  • 3
  • 12
  • 19
-2
votes
1 answer

How to mock an object's method using PowerMockito?

I have a class which contains a method which I want to test. Here's the class. class classOne { private static boolean doneThis = false; methodOne() { CloseableHttpResponse response = SomeClass.postData(paramOne, paramTwo); …
awesomemypro
  • 531
  • 1
  • 11
  • 32
-2
votes
1 answer

how to mock methods in the superclass through Mockito?

I am very new to Mockito framework and got blocked in the following scenario. I have two classes A and B Class A{ public HttpServletRequest getHttpReq() { return httpReq; } } Class B extends A{ public void prepare() throws…
Srividya
  • 119
  • 1
  • 1
  • 9
-2
votes
2 answers

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: Invalid use of argument matchers! Spring Boot

Mockito really kill for the below error. @Query("SELECT e FROM Employee e WHERE e.status='A' AND LOWER(e.department.useCode)=LOWER(:flag) AND e.department.status='A' ") Page findAllDetails(@Param("flag") String flag, Pageable…
Jeff Cook
  • 7,956
  • 36
  • 115
  • 186
-2
votes
3 answers

PowerMockito.mockStatic() but still getting NPE when static method is called

NOTE - I've marked 3 LINE numbers which I discuss in my question, you may need to scroll to the right in the code snippets to see. I'm really struggling unit testing a method with chained Optional.map()s. @Override public void accept(Object…
notAChance
  • 1,360
  • 4
  • 15
  • 47
1 2 3
88
89