jmock

maven - How to solve this error : “The POM for XXX is invalid”?

时间秒杀一切 提交于 2019-12-11 01:31:58
问题 I'm building a simple project with maven. I'm unable to get it to build because a transitive dependencies is missing, namely objenesis 1.0 . I run maven in debug mode and got this message: [DEBUG] ======================================================================= [WARNING] The POM for org.jmock:jmock-junit4:jar:2.6.0 is invalid, transitive dependencies (if any) will not be available: 1 problem was encountered while building the effective model for org.jmock:jmock-junit4:2.6.0 [ERROR]

How to use JMock to test mocked methods inside a mocked method

自闭症网瘾萝莉.ら 提交于 2019-12-11 00:52:53
问题 I'm having trouble determining how to mock a particular piece of code. Here is my method: public void sendNotifications(NotificationType type, Person person) { List<Notification> notifications = findNotifications(type); for(Notification notification : notifications) { notification.send(person); } } I would like to be able to use JMock to test that findNotifications is called and that and returns the expected value and that send() is called. findNotifications calls my Dao which is mocked.

How to mock a static variable in java using JMock

喜夏-厌秋 提交于 2019-12-10 23:14:35
问题 I have a Unit testing problem where a class has a static variable which wants to load the Spring Application Ctx. This class DOES NOT come out of the Bean Factory and I cannot change this fact. static ApplicationContext applicationContext = ...; This works fine, but is hard to JMock , or atleast I don't know a way and until I can the Spring Ctx wants to start up. Not ideal for a unit test situation. Is there a work around that anyone knows? I have the option to change the static variable to

JMock with(instanceOf(Integer.class)) does not compile in Java 8

一曲冷凌霜 提交于 2019-12-08 05:40:30
问题 After upgrading to Java 8. I now have compile errors of the following kind: The method with(Matcher<Object>) is ambiguous for the type new Expectations(){} It is caused by this method call: import org.jmock.Expectations; public class Ambiguous { public static void main(String[] args) { Expectations expectations = new Expectations(); expectations.with(org.hamcrest.Matchers.instanceOf(Integer.class)); } } It seems like with is returned from instanceOf() is ambiguous from what with() expects, or

JMock with(instanceOf(Integer.class)) does not compile in Java 8

断了今生、忘了曾经 提交于 2019-12-07 14:06:30
After upgrading to Java 8. I now have compile errors of the following kind: The method with(Matcher<Object>) is ambiguous for the type new Expectations(){} It is caused by this method call: import org.jmock.Expectations; public class Ambiguous { public static void main(String[] args) { Expectations expectations = new Expectations(); expectations.with(org.hamcrest.Matchers.instanceOf(Integer.class)); } } It seems like with is returned from instanceOf() is ambiguous from what with() expects, or vice versa. Is there a way to fix this? There is some easy ways to help the compiler. assign the

How to test protected methods of abstract class using JUnit and JMock

社会主义新天地 提交于 2019-12-07 06:47:51
问题 I have such situation - I have interface (say MyInterface ) and simple partial implementation ( AbstractMyInterface ). The latter adds a few protected methods which I would like to test. Currently I simply write by hand a mock object which extends AbstractMyInterface and export protected methods as public. Is there a simpler way of doing this - for example using JMock+scripting? 回答1: I cannot see any problem with testing protected methods with JUnit. As long as package structure for tests

Unit testing using MockMultipartHttpServletRequest (throws NullPointerException in ItemInputStream.makeAvailable)

时间秒杀一切 提交于 2019-12-07 01:15:09
问题 I've written a transformer class that takes an HttpServletRequest and transforms it into another type that holds a pointer to the InputStream from the servlet request. (The idea is to abstract the incoming transport protocol from the request handling, so I could also write a similar transformer from FTP, for instance.) Now I'm trying to write a unit test for this, and I'm having problems. I've managed to figure out the correct boilerplate to create a valid Multipart HTTP request (using the

Unit testing a Swing component

 ̄綄美尐妖づ 提交于 2019-12-05 20:03:21
问题 I am writing a TotalCommander-like application. I have a separate component for file list, and a model for it. Model support listeners and issues a notification for events like CurrentDirChanged etc. in following manner: private void fireCurrentDirectoryChanged(final IFile dir) { if (SwingUtilities.isEventDispatchThread()) for (FileTableEventsListener listener : tableListeners) listener.currentDirectoryChanged(dir); else { SwingUtilities.invokeLater(new Runnable() { public void run() { for

Unit testing a Swing component

早过忘川 提交于 2019-12-04 03:29:49
I am writing a TotalCommander-like application. I have a separate component for file list, and a model for it. Model support listeners and issues a notification for events like CurrentDirChanged etc. in following manner: private void fireCurrentDirectoryChanged(final IFile dir) { if (SwingUtilities.isEventDispatchThread()) for (FileTableEventsListener listener : tableListeners) listener.currentDirectoryChanged(dir); else { SwingUtilities.invokeLater(new Runnable() { public void run() { for (FileTableEventsListener listener : tableListeners) listener.currentDirectoryChanged(dir); } }); } } I've

Can I mock a super class method call?

旧巷老猫 提交于 2019-12-04 01:18:42
Sometimes, you want to test a class method and you want to do an expectation on a call of a super class method. I did not found a way to do this expectation in java using easymock or jmock (and I think it is not possible). There is a (relative) clean solution, to create a delegate with the super class method logic and then set expectations on it, but I don't know why and when use that solution ¿any ideas/examples? Thanks Cem Catikkas Well, you can if you want to. I don't know if you are familiar with JMockit , go check it out. The current version is 0.999.17 In the mean time, let's take a look