easymock

Getting exception from EasyMock's “nice mock” with a debugger attached

↘锁芯ラ 提交于 2019-12-12 12:02:41
问题 (Disclaimer - EasyMock newb) According to the documentation (and this post), if I wanted to use EasyMock to generate stub objects, I should use EasyMock.createNiceMock() . A "nice mock" is actually a stub - i.e an object that doesn't participate in validation, just returns values. However, the following snippet fails for me with an IllegalStateException("missing behavior definition for the preceding method") , on the second foo.translate() line. Foo foo = EasyMock.createNiceMock(Foo.class);

EasyMock “Unexpected method call” despite of expect method declaration

元气小坏坏 提交于 2019-12-12 10:53:20
问题 My EasyMock's expected method is perceived as unexpected, although I do not use and strict mocks, and the method is already declared before being replied. Test fails in this line of code: Intent batteryIntent = context.getApplicationContext().registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); Test: @Before public void setUp() { mocksControl = createControl(); contextMock = mocksControl.createMock(Context.class); //(...) } @Test public void test() { expect(contextMock

Junit with new Date()

旧街凉风 提交于 2019-12-12 10:37:24
问题 What would the junit test be when i have the following method: @Override public void saveLastSuccesfullLogin(final User user) { gebruiker.setLastLogin(new Date()); storeUser(user); } submethode storeUser: @Override public void storeUser(final User user) { EntityManager em = emf.createEntityManager(); em.getTransaction().begin(); em.merge(user); em.getTransaction().commit(); em.close(); } The problem i have is the date, being set for the entity user and then stored. Im using junit and easymock

During suite tests EasyMock says 0 matchers expected 1 recorded

旧街凉风 提交于 2019-12-12 08:19:39
问题 So I've been using EasyMock's class extension for a while now. All of a sudden I'm getting this exception, but only when I run the entire test suite: java.lang.IllegalStateException: 0 matchers expected, 1 recorded. at org.easymock.internal.ExpectedInvocation.createMissingMatchers(ExpectedInvocation.java:42) at org.easymock.internal.ExpectedInvocation.<init>(ExpectedInvocation.java:34) at org.easymock.internal.ExpectedInvocation.<init>(ExpectedInvocation.java:26) at org.easymock.internal

EasyMock: andAnswer() vs andDelegateTo()

旧时模样 提交于 2019-12-12 05:09:33
问题 Which are differences between andAnswer() and andDelegateTo() methods in EasyMock in terms of usage? First difference I know that when andAnswer method is used, it is skipped the constructor call. This is important if the constructor makes extra things. class Dummy { public Dummy(Object someArgument) { // some validations of arguments System.out.println("the constructor is called"); } public Object method() { System.out.println("the method is called"); return new Object(); } } @Test public

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

Easymock3 Spring4.0.0.RELEASE cglib compatibility

僤鯓⒐⒋嵵緔 提交于 2019-12-12 04:39:09
问题 I followed the advice given here to try some unit tests with spring aop enabled methods. However, I suspect that the repackaged cglib classes under spring-core and the cglib-nodep-2.2.jar conflict with each other, causing my class being proxied to be loaded by the classloader twice. This results in the following error: Caused by: java.lang.LinkageError: loader (instance of sun/misc/Launcher$AppClassLoader): attempted duplicate class definition for name: Tools: easmock-3.0 (with cglib-nodep-2

Mock No Longer Being Called When Converting from EasyMock 1 to EasyMock 2/3

旧时模样 提交于 2019-12-12 04:37:41
问题 I have a test that includes the following EasyMock 1 code: persistenceManager.getCount(linkCodeAttributeCriteria); persistenceManagerControl.setDefaultReturnValue(0); persistenceManagerControl.replay(); //Run a method persistenceManagerControl.verify(); Now that my company is finally upgrading their EasyMock code, I have changed it to the following code: expect(persistenceManager.getCount(linkCodeAttributeCriteria)).andReturn(0); replay(persistenceManager); //Run a method verify

Unit testing a method with easymock

这一生的挚爱 提交于 2019-12-12 03:43:07
问题 So I have the bellow method which I want to perform a unit test on. public List<Project> getProjects(Task task) { Criteria<Project> criteria = this.myRepository.getCriteria(Project.class); criteria.add(Comparison.eq("order", task.getOrder())); criteria.addOrder(Order.asc("projectNumber")); return this.myRepository.findList(Project.class, criteria); } So it actually gets the task object(It is a JPA model object) and goes throw the project table and finds all the projects which have this

Autowiring beans implementing same interface - how to autowire a particular dependency bean in a JUnit Test?

我是研究僧i 提交于 2019-12-11 20:40:01
问题 I have a Spring 3.1/Java/Tomcat application. I have a service class that is as follows: public class SomeServiceImpl implements SomeService { @Autowired public AnotherService anotherService; // other code... This uses another service class AnotherService which is autowired. Both these services classes are declared in a serviceContext.xml file. I am writing junit to test SomeServiceImpl and use autowired to inject the class under test (SomeService) as well as the mock (EasyMock) dependency