powermock

Mockito throws NullPointer when creating a mock object

六月ゝ 毕业季﹏ 提交于 2019-12-03 12:02:14
I have an integration test in which some set up is done using Guice. I'm using Mockito to mock some of the dependencies. This has worked fine for me until now. I needed to use PowerMock for some other dependency. Now Mockito is throwing a NullPointerException while loading one of its own classes: java.lang.ExceptionInInitializerError at org.mockito.internal.exceptions.stacktrace.ConditionalStackTraceFilter.<init>(ConditionalStackTraceFilter.java:17) at org.mockito.exceptions.base.MockitoException.filterStackTrace(MockitoException.java:30) at org.mockito.exceptions.base.MockitoException.<init>

Why EclEmma doesn't coverage code with tests with @RunWith(PowerMockRunner.class)

佐手、 提交于 2019-12-03 11:46:38
I am using EclEmma with Eclipse to help me to know where is missing code tests in my project, but all tests with @RunWith(PowerMockRunner.class) are not called and thus not tested. I´m using JUnit 4.8.1 with Mockito. What could it be? Its a known bug reported for both parties: http://code.google.com/p/powermock/issues/detail?id=402 https://github.com/jacoco/eclemma/issues/15#issuecomment-9565210 eCoberture seems however to provide correct coverage. The only problem, that it seems not to be maintained anymore, and you cannot remove the highlights im Eclipse Juno. Here you can find example that

How to mock static method without powermock

杀马特。学长 韩版系。学妹 提交于 2019-12-03 11:11:12
问题 Is there any way we can mock the static util method while testing in JUnit? I know Powermock can mock static calls, but I don't want to use Powermock. Are there any alternatives? 回答1: (I assume you can use Mockito though) Nothing dedicated comes to my mind but I tend to use the following strategy when it comes to situations like that: 1) In the class under test, replace the static direct call with a call to a package level method that wraps the static call itself: public class ToBeTested{

Bad type on the operand stack in arraylength

耗尽温柔 提交于 2019-12-03 10:25:39
I am trying to test a method using powermock. i haven't written any test cases yet. Just trying to set up the class for Mocking. here is what I have so far: @RunWith(PowerMockRunner.class) @PrepareForTest({ ReadRubric.class }) public class ReadRubricTest { @Before public void setUp() throws Exception { PowerMockito.mock(ReadRubric.class); } @After public void tearDown() throws Exception { } @Test public void invalidFile() throws Exception { } } When I try to run this test I get the following error. java.lang.VerifyError: Bad type on operand stack in arraylength Exception Details: Location: com

Stub value of Build.VERSION.SDK_INT in Local Unit Test

白昼怎懂夜的黑 提交于 2019-12-03 09:41:21
问题 I am wondering if there is anyway to stub the value of Build.Version.SDK_INT ? Suppose I have the following lines in the ClassUnderTest : if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { //do work }else{ //do another work } How can I cover all the code ? I mean I want to run two tests with different SDK_INT to enter both blocks. Is it possible in android local unit tests using Mockito / PowerMockito ? Thanks 回答1: Change the value using reflection. static void setFinalStatic

How can I create dynamic proxy for final Class?

别说谁变了你拦得住时间么 提交于 2019-12-03 09:40:20
问题 In short: 1. I have some final class that I want to create dynamic proxy for it. How can I do it? 2. Can I convert MethodHandle to Method? Details First of all, does exists any API to convert MethodHandle to Method? Something like in java.lang.invoke.MethodHandles public MethodHandle unreflect(Method m) throws IllegalAccessException; but the opposite way arrond? Let say I want to create dynamic java.lang.reflect.Method. It is defiend as public final class Method extends AccessibleObject

Runtime error PowerMock + Mockito: ProxyFrameworkImpl could not be located in classpath

匿名 (未验证) 提交于 2019-12-03 08:46:08
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am trying to use PowerMock with the Android InstrumentTestCase Since my test runs on an Android device the libraries needs to be added to the apk. I encounter big issues with powermock+mockito and Dex files. I have a runtime error with only powermock+mockito in my dependencies: org.powermock.api.extension.proxyframework.ProxyFrameworkImpl could not be located in classpath. And a compilation error if I include either cglib/cglib-nodep (has suggested in answers ): com.android.dex.DexException: Multiple dex files define Lnet/sf/cglib/beans

How to mock An Interface Java PowerMockito

匿名 (未验证) 提交于 2019-12-03 08:46:08
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I m trying to mock an interface. public interface FlowCopyParamsBusinessManager { List < FlowCopyParams > findByAppli ( String application , String sourcePattern ) throws FlowCopyParamsBusinessException ; } In my code, when i call this method findByAppli , i would like to return a list of FlowCopyParams. List < FlowCopyParams > lstFlowCopyParams = flowCopyParamsBusinessManager . findByAppli ( "TOTO" , "TATA); Here my try in the class test: @BeforeClass public static void mockBeanIn () throws Exception { List < FlowCopyParams >

Mocking a final method with PowerMock + EasyMock

匿名 (未验证) 提交于 2019-12-03 08:44:33
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I'm trying to mock a call to the final method ResourceBundle.getString() . With PowerMock 1.4.12 and EasyMock 3.1, the call is not being mocked; instead, the "real" method is called. My test class: @RunWith ( PowerMockRunner . class ) @PrepareForTest ( ResourceBundle . class ) public class TestSuite { @Before public void setUp () throws Exception { ResourceBundle resourceBundleMock = PowerMock . createNiceMock ( ResourceBundle . class ); expect ( resourceBundleMock . getString ( BundleConstants . QUEUE )). andReturn ( "Queue" );

PowerMock: How to unmock a method?

匿名 (未验证) 提交于 2019-12-03 08:36:05
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a static method that is mocked using PowerMock to throw an exception. (It deletes files.) Unfortunately, during my @After (after-each-test) method, I need to call this method without the mocks. How can I umock a method? I don't see an equivalent to Mockito.reset() . [ Ref: mockito : how to unmock a method? ] Example: @RunWith(PowerMockRunner.class) @PrepareForTest(PathUtils.class) // Important: This class has a static method we want to mock. public class CleaningServiceImplTest2 extends TestBase { public static final File testDirPath