Questions tagged [jmock]

For questions about using jMock. JMock is a helper framework for test-driven development and unit testing.

According to the jMock project website,

JMock is a library that supports test-driven development of Java code with mock objects.

Mock objects help you design and test the interactions between the objects in your programs.

The jMock library:

  • makes it quick and easy to define mock objects, so you don't break the rhythm of programming
  • lets you precisely specify the interactions between your objects, reducing the brittleness of your tests
  • works well with the autocompletion and refactoring features of your IDE
  • plugs into your favourite test framework
  • is easy to extend
257 questions
7
votes
3 answers

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

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…
Mike S
  • 89
  • 2
  • 6
7
votes
2 answers

Using JMock on the Android

How can I use JMock on the Android? I've several posts saying its not possible, but surely there's some way to do it? The issue seems to be getting the Android to even recognize the JMock jar file. So maybe there's a solution with putting the…
Ron Romero
  • 9,211
  • 8
  • 43
  • 64
7
votes
2 answers

Need help with writing test

I'm trying to write a test for this class its called Receiver : public void get(People person) { if(null != person) { LOG.info("Person with ID " + person.getId() + " received"); processor.process(person); …
London
  • 14,986
  • 35
  • 106
  • 147
7
votes
4 answers

How to get started with testing(jMock)

I'm trying to learn how to write tests. I'm also learning Java, I was told I should learn/use/practice jMock, I've found some articles online that help to certain extend like…
London
  • 14,986
  • 35
  • 106
  • 147
7
votes
4 answers

What is the best way to use Guice and JMock together?

I have started using Guice to do some dependency injection on a project, primarily because I need to inject mocks (using JMock currently) a layer away from the unit test, which makes manual injection very awkward. My question is what is the best…
Yishai
  • 90,445
  • 31
  • 189
  • 263
7
votes
3 answers

JMock - strange syntax for adding expectations

I am currently writing a couple of tests involving JMock. I cannot understand the following structure of the code: context.checking(new Expectations() { //context is of type Mockery of course { …
Bober02
  • 15,034
  • 31
  • 92
  • 178
6
votes
2 answers

Mock a JPA CriteriaBuilder with Mockito

I have a particularly nasty JMock checking() block for a JPA query that I want to migrate to Mockito: Mockery jMock = new Mockery(); final EntityManager fakeEntityManager = jMock.mock(EntityManager.class); final CriteriaBuilder fakeCriteriaBuilder =…
seanhodges
  • 17,426
  • 15
  • 71
  • 93
6
votes
2 answers

JMock assertIsSatisfied in TearDown?

I don't know why, but I have always written my JMock tests like this: @Test public void testMyThing() throws Exception { mockery.checking(new Expectations() {{ oneOf(mockObj).foo(); }}); testObj.bar(); // calls mockObj.foo() …
Paul McKenzie
  • 19,646
  • 25
  • 76
  • 120
6
votes
1 answer

JMock Allow Other Method Calls

I'm using JMock to test the behavior of a class using an object. I want to test that the method a() is called. However, b() and c() also are called on the object too. Therefore if my expectations expect a(), it must also expect b() and c() to make…
Mike
  • 19,267
  • 11
  • 56
  • 72
6
votes
4 answers

Unit test private inner class methods

I have a Class A which has an internal Cache represented by a Class B. this inner class is private since the cache need not be visible to external consumers and is only to assist the outer class A. I am using Jmock and Java public class A { ... …
Rookie
  • 5,179
  • 13
  • 41
  • 65
6
votes
5 answers

How to mock JdbcTemplate.queryForObject() method

My method looks like this: public class Decompile extends JdbcDaoSupport public void getRunner(){ String val = this.getJdbcTemplate().queryForObject(sql,String.class, new Object[]{1001}); } } Please suggest how I would mock this.
buttowski
  • 4,657
  • 8
  • 27
  • 33
6
votes
1 answer

JMock - several invocations with different arguments

The method I want to test is calling a mock method with different arguments: public void methodToTest(){ getMock().doSomething(1); getMock().doSomething(2); getMock().doSomething(3); } In my unit test I want to know, if methodToTest really…
Darek Kay
  • 61
  • 2
5
votes
1 answer

jMock Mocking Classes and Interface

I was experimenting jMock as my mocking framework for my project. I came into a situation where I need to mock both a class and an interface. I used the ClassImposteriser.INSTANCE to initiate the impostor of the context. Supposing a class Validator…
Roy Marco Aruta
  • 705
  • 5
  • 11
  • 21
5
votes
3 answers

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

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…
Maciej Piechotka
  • 7,028
  • 6
  • 39
  • 61
5
votes
1 answer

JMock unexpected invocation

Below I am just trying to mock a class named TestWrapper and set 'allowing' expecations on it. However, when setting expectations I get error. When using easymock and just setting expectations, this doesn't seem to happen import…
Himalay Majumdar
  • 3,883
  • 14
  • 65
  • 94
1
2
3
17 18