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
0
votes
0 answers

How to inject a mocked service into a dynamically created class

So I have a @Spy which performs a new object creation, related to the refactoring pattern of -> (Method to Object) however, that newly created instance does not have its dependent services injected in. The code is obviously not my property to post…
0
votes
0 answers

mockito and powermockito throws AbstractMethodError while mocking groovy test files

I'm trying to mock a final class (java.net.URL) and use it in a very simple Wrapper class: ClassToTest.groovy. The tester class is given further below and is: ClassToTestTester.groovy. package com.icidigital.services.impl; import…
apil.tamang
  • 2,545
  • 7
  • 29
  • 40
0
votes
3 answers

Junit Mocking Private Method

I need to mock private method and should return true. In ServiceImpl-execute() my request will go to else { } and it will call "eventRequest()". Its a private boolean eventRequest(), So whenever evenRequest() will call i should return true. Can…
Mohan
  • 59
  • 1
  • 7
0
votes
1 answer

Junit - Mocking static method

I'm writting a Junit test class "ServiceImplTest.java" for following method but its getting null, while trying Marshall xmlRequest. Can anybody help me out to resolve this issue please. Thanks in…
Mohan
  • 59
  • 1
  • 7
0
votes
3 answers

Mockito - You cannot use argument matchers outside of verification or stubbing - have tried many things but still no solution

I have the following piece of code: PowerMockito.mockStatic(DateUtils.class); //And this is the line which does the exception - notice it's a static function PowerMockito.when(DateUtils.isEqualByDateTime…
Achi Even-dar
  • 427
  • 1
  • 10
  • 20
0
votes
1 answer

Power Mockito test ServletOutputStream

I am currently trying to test what is printed to a servlet output stream using power mockito but I can't find any way to do it. Here is what I have so far Routing routingMock = PowerMockito.mock( Routing.class ); HttpServletRequest httpRequestMock =…
FMC
  • 650
  • 12
  • 31
0
votes
1 answer

Issues in writing test case for a private method

I am trying to write a test case for params method in the below class. Problems while writing a JUnit test case: The problem is that the method is private and inside the method it calls for super class methods. I tried using EasyMock where I will…
user3473132
  • 95
  • 10
0
votes
1 answer

Mocking Static Methods and AEM Mocks

I'm using maven to build and test my code before installing to an instance of AEM 5.6.1. I've written unit tests that benefit from aem mocks using an implementation by wcm.io and other unit tests that require mocking static methods using…
Thomas
  • 303
  • 3
  • 14
0
votes
1 answer

Supressing or Whiteboxing issue

I have a Logger that is private static final which utilizes a server. I would like to suppress the Logger method debug, or suppress any and all interactions with the variable. I declare the logger in LoggingClass private static final Logger LOGGER…
mcha
  • 1
  • 1
0
votes
1 answer

Mocking a constructor of @Autowired service(system under test)

I have to mock jerseyclient which is being created in Constructor of subjected service. Subjected service is System under test injected via Spring's @Autowired. In constructor of the service client=client.create() method is written. We can't change…
0
votes
1 answer

How do you bypass static method calls?

I have this line which is interferring in a unit test: OtherClass.staticMethodThatWillErrorIfCalled().isAvailable(); If it wasn't static I could just mock OtherClass and then do…
Aequitas
  • 2,205
  • 1
  • 25
  • 51
0
votes
1 answer

How to mock Class object or how to mock private generic method

I have a private generic method below private Section convertFromJsonToJavaObj(JSONObject jsonObj, Class
classObj) throws SNPSysException { // logic return section; } how to mock above method
0
votes
2 answers

Verify a mocked object's method

Say I have a class like this: public class Foo { private Bar bar; public Foo(Bar bar) { this.bar = bar; } public void someMethod() { bar.someOtherMethod(); } } How would I verify that bar.someOtherMethod() is…
Will Huang
  • 325
  • 7
  • 15
0
votes
2 answers

Initializing a static final variable in a mock

I want to initialize a static final variable of a class differently when it is mocked, and when it is not. Is there any way to do this? Something like : public class Test { private static final Integer a = getA(); private static Integer…
user3575425
  • 478
  • 3
  • 11
0
votes
0 answers

Mock native objects

I'm using Robolectric and Mockito for Unit Testing. The current setup is working out great for me but I have code that is heavily dependent on a library that is calling a native dependency. I'm aware that I cannot mock native method calls using…
Jani
  • 1,400
  • 17
  • 36