Is it possible to create a mock object that implements multiple interfaces with EasyMock?

Although I fundamentally agree with Nick Holt’s answer, I thought I should point out that mockito allows to do what you ask with the following call : Foo mock = Mockito.mock(Foo.class, withSettings().extraInterfaces(Bar.class)); Obviously you’ll have to use the cast: (Bar)mock when you need to use the mock as a Bar but that cast will not … Read more

EasyMock andReturn() vs andStubReturn()

You use a stub return for a method call on the mock that you expect to happen but aren’t otherwise interested in. You use a regular return for a “regular” method call. Consider the following method: public void someMethod(String arg) { if (logger.isDebugEnabled()) { logger.debug(“Calling doSomething() on service ” + service.getName().hashCode()); } service.postMessage(“{” + arg … Read more

EasyMock: Void Methods

If I understand what you want to do correctly, you should be able to use andAnswer(): mockObject.someMethod(eq(param1), eq(param2)); expectLastCall().andAnswer(new IAnswer() { public Object answer() { //supply your mock implementation here… SomeClass arg1 = (SomeClass) getCurrentArguments()[0]; AnotherClass arg2 = (AnotherClass) getCurrentArguments()[1]; arg1.doSomething(blah); //return the value to be returned by the method (null for void) return null; … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)