powermock

org.powermock.reflect.exceptions.MethodNotFoundException: No method found with name '' with parameter types: [ java.util.LinkedList ]

霸气de小男生 提交于 2019-12-12 10:24:52
问题 I am developing Test classes using PowerMock , as all my Legacy code is written using Private Static methods(). When running the test class, I am getting below error: org.powermock.reflect.exceptions.MethodNotFoundException: No method found with name 'insertPaytmBilling' with parameter types: [ java.util.LinkedList ] in class com.xyz.PaytmBilling. at org.powermock.reflect.internal.WhiteboxImpl.throwExceptionIfMethodWasNotFound(WhiteboxImpl.java:1122) at org.powermock.reflect.internal

Can PowerMock instantiate an inner class for test cases?

北城以北 提交于 2019-12-12 09:36:19
问题 I'm attempting to test a class with a number of private classes (yes, I know this is generally considered poor practice for testability, but this question is not in regards to design principles). My class would look something like this: public class EnclosingClass { . . . private class InnerClass implements InnerClassType { public InnerClass(){ /* do stuff */} public int InnerClassMethod(); } } InnerClassType is a public interface I've tried instantiating the classes with powermock by doing:

PowerMock access private members

天涯浪子 提交于 2019-12-12 09:32:01
问题 After reading: https://code.google.com/p/powermock/wiki/BypassEncapsulation i realized, i don't get it. See in this example: public class Bar{ private Foo foo; public void initFoo(){ foo = new Foo(); } } How can i access the private member foo by using PowerMock (For example to verify that foo is not null)? Note: What i don't want is modifying the code with extra get methods. Edit: I realized that i missed a sample code block on the linked page with the solution. Solution: Whitebox

Mocking method calls using power mockito - org.powermock.api.mockito.ClassNotPreparedException

半世苍凉 提交于 2019-12-12 09:29:14
问题 I have an image loader class and i need to test some static methods in it. Since Mockito does not support static methods i switched to Power Mockito. But the static method i am testing has a method call Base64.encodeToString(byteArray, Base64.DEFAULT); To mock this i am using mockStatic method as below with @PrepareForTest annotation. PowerMockito.mockStatic(Base64.class); But Android studio is returning me still returning me an error as below. org.powermock.api.mockito

Class loading collision between Robolectric and Powermock

青春壹個敷衍的年華 提交于 2019-12-12 08:53:54
问题 I'm trying to write a test that needs both Robolectric 2.2 and PowerMock , as the code under test depends on some Android libraries and third party libraries with final classes that I need to mock. Given that I'm forced to use the Robolectric test runner through: @RunWith(RobolectricTestRunner.class) ...I cannot use the PowerMock test runner, so I'm trying to go with the PowerMock java agent alternative, without luck so far. I have setup everything according to this guide but I'm facing a

How to mock local variables using mockito or powermock

人盡茶涼 提交于 2019-12-12 07:16:29
问题 I have scenario like this InputStreamReader reader = new InputStreamReader(getFileAsStream(resourceResolver, iconpath)); BufferedReader bReader = new BufferedReader(reader); I have mocked till this point getFileAsStream(resourceResolver, iconpath) now I am getting one reader BufferedReader bReader = new BufferedReader(reader); but when I execute this line I get null and not able to move forward while ((iconEntry = bReader.readLine()) != null) Please tell me how can I mock this. Please note I

Mocking static Liferay method

柔情痞子 提交于 2019-12-12 04:56:51
问题 I'm trying to mock the PortalUtil.getPortal() method like so PowerMock.mockStatic(PortalUtil.class); Portal mockPortal = Mockito.mock(Portal.class); Mockito.when(PortalUtil.getPortal()).thenReturn(mockPortal); I'm getting the below error org.mockito.exceptions.misusing.MissingMethodInvocationException: when() requires an argument which has to be 'a method call on a mock'. For example: when(mock.getArticles()).thenReturn(articles); Also, this error might show up because: 1. you stub either of:

Cant mock static functions with powermock-easymock-testng (non-maven project)

醉酒当歌 提交于 2019-12-12 04:40:49
问题 To tell you first, i have tried and tried it again and now i need some help Heres my code package staticPkg; public class Static { public static final String staticMethod() { System.out.println("Static method called"); return "Static called"; } } package staticPkg; public class TargetClass { Static staticClass; public String callHere() { return Static.staticMethod(); } } package staticPkg; import org.easymock.EasyMock; import org.powermock.api.easymock.PowerMock; import org.powermock.core

dropwizard + Powermock + Mockito + Maven build error with ClassNotFoundException “ThreadSafeMockingProgress”

对着背影说爱祢 提交于 2019-12-12 03:37:20
问题 For testing static method I am using Power mock and pom.xml entry for this is <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.8.1</version> <scope>test</scope> </dependency> <dependency> <groupId>org.mockito</groupId> <artifactId>mockito-all</artifactId> <version>1.8.5</version> <scope>test</scope> </dependency> <dependency> <groupId>org.powermock</groupId> <artifactId>powermock-api-mockito</artifactId> <version>1.4.9</version> <scope>test</scope> </dependency>

Powermock to mock instance methods called from other executing methods

给你一囗甜甜゛ 提交于 2019-12-12 01:59:27
问题 In this code, i have mocked the one of the ValidateHandlerSoapClient class method which is instantiated and called this method (soapClientSpy.processSoapRequestRespons) in validateMsisdnHandlerIRSpy.validate().So soapClientSpy.processSoapRequestResponse is not working , instead the real method is called. @RunWith(PowerMockRunner.class) @PrepareForTest({ValidateMsisdnHandler.class,ValidateHandlerSoapClient.class}) public class Demo { MessageControl messageControl=PowerMockito.mock