easymock

Autowiring of beans generated by EasyMock factory-method?

烈酒焚心 提交于 2019-11-27 16:02:40
问题 I have a problem that seems really strange to me. I have the following setup: An interface: package com.example; public interface SomeDependency { } A spring component: package com.example; @Component public class SomeClass { } A spring test config with a mocked bean generated by EasyMock: <beans ....> <context:component-scan base-package="com.example"/> <bean id="someInterfaceMock" class="org.easymock.EasyMock" factory-method="createMock"> <constructor-arg value="com.example.SomeDependency"

Test that void method didn't get called with EasyMock

家住魔仙堡 提交于 2019-11-27 05:55:32
问题 Is this possible? I tried with EasyMock.expectLastCall().times(0); but EasyMock complains that times must be >=1 回答1: You could use .andThrow(new AssertionFailedError()).anyTimes(); - this is the same exception that Assert.fail() throws, but is less verbose than making an Answer . 回答2: with easymock 3.0, you need to add a .anyTimes() on the expectLastCall or the test will fail: Expectation failure on verify: myMethod(): expected: 1, actual: 0` based on nkr1pt example: expectLastCall()

EasyMock 3.0, mocking class throws java.lang.IllegalStateException: no last call on a mock available

时光总嘲笑我的痴心妄想 提交于 2019-11-27 02:34:56
问题 Running the following unit test throws the exception: java.lang.IllegalStateException: no last call on a mock available import org.easymock.*; import org.junit.*; public class MyTest { @Test public void testWithClass() { Thread threadMock = EasyMock.createMock(Thread.class); EasyMock.expect(threadMock.isAlive()).andReturn(true); } } I am not sure what I am doing wrong and can not find any good examples on the web. How do you mock a class using EasyMock 3.0. What is wrong with the above unit

NoClassDefFoundError when using Powermock

╄→尐↘猪︶ㄣ 提交于 2019-11-27 02:31:08
问题 I'm running a junit test case using the PowerMock test runner. I'm using the following command line to execute it: java -cp .:junit-4.9b2.jar:easymock-3.0.jar:powermock-easymock-1.4.8-full.jar org.junit.runner.JUnitCore SampleTest When doing so I am receiving this error: initializationError(SampleTest) java.lang.NoClassDefFoundError: org/junit/internal/runners/TestClassRunner ... How can I fix it? 回答1: I just solved this one now, when I added the @RunWith(PowerMockRunner.class) attribute,

How do I mock static methods in a class with easymock?

点点圈 提交于 2019-11-27 01:33:21
Suppose I have a class like so: public class StaticDude{ public static Object getGroove() { // ... some complex logic which returns an object }; } How do I mock the static method call using easy mock? StaticDude.getGroove() . I am using easy mock 3.0 Ben J Not sure how to with pure EasyMock, but consider using the PowerMock extensions to EasyMock. It has a lot of cool functions for doing just what you need - https://github.com/jayway/powermock/wiki/MockStatic Easymock is a testing framework for "for interfaces (and objects through the class extension)" so you can mock a class without an

How to mock a static final variable using JUnit, EasyMock or PowerMock

纵饮孤独 提交于 2019-11-26 19:58:43
问题 I want to mock a static final variable as well as mock a i18n class using JUnit, EasyMock or PowerMock. How do I do that? 回答1: Is there something like mocking a variable? I would call that re-assign. I don't think EasyMock or PowerMock will give you an easy way to re-assign a static final field (it sounds like a strange use-case). If you want to do that there probably is something wrong with your design: avoid static final (or more commonly global constants) if you know a variable may have

How do I mock static methods in a class with easymock?

吃可爱长大的小学妹 提交于 2019-11-26 12:27:41
问题 Suppose I have a class like so: public class StaticDude{ public static Object getGroove() { // ... some complex logic which returns an object }; } How do I mock the static method call using easy mock? StaticDude.getGroove() . I am using easy mock 3.0 回答1: Not sure how to with pure EasyMock, but consider using the PowerMock extensions to EasyMock. It has a lot of cool functions for doing just what you need - https://github.com/jayway/powermock/wiki/MockStatic 回答2: Easymock is a testing

PowerMockito mock single static method and return object

若如初见. 提交于 2019-11-26 01:29:45
问题 I want to mock a static method m1 from a class which contains 2 static methods, m1 and m2. And I want the method m1 to return an object. I tried the following 1) PowerMockito.mockStatic(Static.class, new Answer<Long>() { @Override public Long answer(InvocationOnMock invocation) throws Throwable { return 1000l; } }); This is calling both m1 and m2, which has a different return type, so it gives a return type mismatch error. 2) PowerMockito.when(Static.m1(param1, param2)).thenReturn(1000l); But