easymock

Mocking super method call using easymock/powermock

淺唱寂寞╮ 提交于 2019-12-11 16:14:44
问题 I integrated easymock with my Spring project and performed most of the unit tests. But got an issue with not able to mock the super method. When I run my test class it says method not supported. Any idea what's going wrong as I tried my best for last couple of days and not able to get any clue on how to mock the super method. org.springframework.security.authentication.AuthenticationServiceException: Authentication method not supported: at org.springframework.security.web.authentication

Not able to mock constructor using PowerMock

北城以北 提交于 2019-12-11 09:23:31
问题 Here in below code i am not able to Mock Constructor using PowerMock. I want to MOck below statement. APSPPortletRequest wrappedRequest = new APSPPortletRequest(request); below are my mocking steps @PrepareForTest({APSPPortletRequest.class}) @RunWith(PowerMockRunner.class) public class ReminderPortletControllerTest { private PortletRequest requestMock; private APSPPortletRequest apspPortletRequestMock; public void setUp() throws Exception { requestMock = EasyMock.createNiceMock(PortletRequest

EasyMock: Partially mocked class

与世无争的帅哥 提交于 2019-12-11 08:25:19
问题 Do all the methods that are not mocked on a mocked class work work as normal? E.G. Given the object public class Shape { public void createShape(...){ .... } public void removeShape(...){ .... } ... } if this was mocked out like shape = createMock(Shape.class, new Method[]{Shape.class.getMethod("removeShape", new Class[]{...})}); would all the other methods like createShape() work or do you have to mock out all methods you want to use? 回答1: In short, yes. Partial Mocks work exactly like an

PowerMock + EasyMock: private void method without invokation

跟風遠走 提交于 2019-12-11 06:36:26
问题 Good time! I need to substitute the class' private void method with a mock implementation, and can't to figure out how to do this. I've tried to use such a construction: Test test = PowerMock.createPartialMock(Test.class, "setId"); PowerMock.expectPrivate(test , "setId", EasyMock.anyLong()).andAnswer( new IAnswer<Void>() { @Override public Void answer() throws Throwable { return null; } }); PowerMock.replay(test); but the internal PowerMock's class called WhiteBox invokes my "setId" method

EasyMock - mock object returned from new Object

﹥>﹥吖頭↗ 提交于 2019-12-11 00:52:36
问题 Is it possible, with a capture for example, to return a mock when a method is called from a new object? To make it more concrete: SecurityInterface client = new SecurityInterface(); port = client.getSecurityPortType(); --> I want to mock this. easymock version: 3.3.1 回答1: Yes, if you also use Powermock your test code can intercept the calls to new and return a mock instead. So you can return a mock for new SecurityInterface() and then mock its getter Powermock is compatible with Easymock

PowerMock - Mock a Singleton with a Private Constructor

此生再无相见时 提交于 2019-12-10 22:42:32
问题 I'm using PowerMock with EasyMock, and wondered how I might mock a singleton with a private constructor? Let's say I have the following class: public class Singleton { private static Singleton singleton = new Singleton(); private Singleton() { } public static Singleton getInstance() { return singleton; } public int crazyServerStuff() { ... } } And a class which uses this: public class Thing { public Thing() {} public int doStuff(Singleton s) { return s.crazyServerStuff() + 42; } } How might I

Unit Testing Composite Service Methods

眉间皱痕 提交于 2019-12-10 15:30:35
问题 I am writing (junit) unit tests for a class which implements an exposed interface with methods like: public Set<Setting> getUserSettings(); public Set<Setting> getOrganizationSettings(); public Set<Setting> getDefaults(); public Set<Setting> getAllSettings(); The methods for getting Settings from a specific layer do IO from various places for retrieving their results. getAllSettings() Returns a single set of all the Settings at all levels, with the 'uppermost' level having preference (i.e. if

What is the analogon of Mockito.spy/doReturn in EasyMock?

[亡魂溺海] 提交于 2019-12-10 12:35:56
问题 Imagine, I have following class: public class TestClass { public class Index<X> { } public class IndexData { private final Index<?> index; private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); public IndexData(final Index<?> index) { super(); this.index = index; } public Index<?> getIndex() { return index; } public Lock getReadLock() { return lock.readLock(); } public Lock getWriteLock() { return lock.writeLock(); } } public void add(final InputClass input) { final

How Configure EasyMock Class Extension 3.1?

两盒软妹~` 提交于 2019-12-10 09:42:20
问题 I want to add EasyMock Class Extension 3.1 to my project and I have a problem with dependencies of EasyMock 3.1 CE. I add dependencies : cglib-2.2.2.jar and asm-4.0.jar and throws exception : java.lang.VerifyError: class net.sf.cglib.core.DebuggingClassWriter overrides final method visit.(IILjava/lang/String;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;)V When I use cglib-nodep-2.1_3.jar and asm-4.0.jar throws another exception: java.lang.NoClassDefFoundError: org/objenesis

java.lang.IllegalStateException: missing behavior definition for the preceding method call getMessage(“title”)

ぐ巨炮叔叔 提交于 2019-12-09 07:37:48
问题 I'm using EasyMock(version 2.4) and TestNG for writing UnitTest. I have a following scenario and I cannot change the way class hierarchy is defined. I'm testing ClassB which is extending ClassA. ClassB look like this public class ClassB extends ClassA { public ClassB() { super("title"); } @Override public String getDisplayName() { return ClientMessages.getMessages("ClassB.title"); } } ClassA code public abstract class ClassA { private String title; public ClassA(String title) { this.title =