I'm using Mockito to write a unit test in Java, and I'd like to verify that a certain method is the last one called on an object.
I'm doing something like this ... |
I need to simulate a test scenario in which I call the getBytes() method of a String object and I get an UnsupportedEncodingException.
I have tried to achieve that using the following ... |
I'd like to test an abstract class. Sure, I can manually write a mock that inherits from the class.
Can I do this using a mocking framework (I'm using Mockito) instead ... |
i am required to use mockito to create unit testing framework for existing code. I am unable to find a good place to get started with learning Mockito. Could you please ... |
How to make mock void methods.I performed observer pattern but i cant mock with mockito because i dont know the mock way with mockito.And ... |
I have a method i'd like to stub but it has a lot of parameters.
How can i avoid mocking all parameters but still stub the method.
Ex:
//Method to stub
public void myMethod(Bar ...
|
This comparison shows, that JMockit has several advantages over other frameworks.
Are there also any advantages that one of the others (JMock, EasyMock, Mockito, Unitils, PowerMock + Mockito/EasyMock) has over ... |
|
When I put a "VerificationModeFactory.times(2)" in test before, when I run all tests of the class appears this exception:
org.mockito.exceptions.verification.WantedButNotInvoked:
Wanted but not invoked:
serviceService.getServices();
If I run each test separately or remove "VerificationModeFactory.times(2)" ... |
When i create a mock object of say class Employee. It doesnt call the constructor of Employee object. I know internally Mockito uses CGLIb and reflection, creates a proxy class that ... |
I'm having a problem with ArgumentCaptor not being able to record the
arguments when calling the same method a number of times.
Basically this does not seem to work:
List<Dummy> mList ...
|
I'm testing a certain class. This class is internally instantiating a "GetMethod" object that gets passed to a "HttpClient" object that gets injected into the tested class.
I'm mocking the "HttpClient" class, ... |
Let's say I have a class
class SomeClass
{
public void methodA()
{}
public void methodB()
{}
public void someMethod()
{
methodA();
...
|
I need mock some class with final method using mockito. I have wrote something like this
@Test
public void test() {
B b = mock(B.class);
doReturn("bar ...
|
I have a line in my test that currently looks like:
Mockito.verify(mockMyObject).myMethod(Mockito.contains("apple"));
I would like to modify it to check if the parameter contains both "apple" and "banana". How would I go ... |
Hello
I'm investigating which mocking framework to use for my project and have narrowed it down to JMockit and Mockito. I notice that Mockito was voted "the ... |
I have a problem with Mockito.
Is it possible to do such a thing:
ClassX x = mock(ClassX.class)
when(x.methodB()).thenReturn("toto");
String result = x.methodA();
I'm working with Mockito 1.7.
I saw there was a "spy" system but they ... |
We try to verify the behaviour of an action with Mockito. The test code looks like this
final Type1 mock = mock(Type1.class);
new SomeAction<Type1>(mock).actionPerformed(null);
verify(mock).someMethod();
The method actionPerformed contains just the call of someMethod on ... |
I have a test but i am not quite good with it, i want to verify that when the methods login is called three times with wrong username and password it ... |
Is it possible in mockito to verify a method was called on a mock based on whether the mock was actually used in the unit-under-test?
For a simple example, I supply a ... |
I had an issue with mocking Apache Http client. The following attempt to create a mock:
DefaultHttpClient httpClient = Mockito.mock(DefaultHttpClient.class);
Fails to create a true mock. The above row gets executed without ... |
Tired of hand-crafting mocks, I am trying to introduce Mockito to my project.
Suppose I have a bunch of database accessors which isolate all Hibernate queries for given use case (or service). ... |
One of the functions I'm testing is sshing into a machine. I want to mock the ping method, that actually tries to ssh into a machine, since I am not really ... |
I have following code I want to test:
public class MessageService {
private MessageDAO dao;
public void acceptFromOffice(Message message) {
...
|
I have this Mockito code:
interface Dao {
public void doSomething();
}
class LegacyClass {
Dao dao;
public String legacyMethod() {
...
|
I have three methods like these ones:
public void method1(String str){
...
}
public void method1(String str, String str2, String str3){
...
}
public void method1(String str, String str2, Object[] ...
|
Something tells me I'm doing something wrong...it shouldn't be this hard.
I have a class that relies on some inner class. I'm creating that inner through a protected method so that I ... |
I'm working with some legacy code, where I have to implement a new Handler. And in this handler, there's an object which is unfortunately initialized by the framework using some hard-coded ... |
@Transactional(propagation = Propagation.REQUIRED)
public void exe() {
try {
Reserve ...
|
I'm trying to test some legacy code, using Mockito.
I want to stub a FooDao that is used in production as follows:
foo = fooDao.getBar(new Bazoo());
I can write:
when(fooDao.getBar(new Bazoo())).thenReturn(myFoo);
But the obvious problem is ... |
I have a method that gets called twice, and I want to capture the argument of the second method call.
Here's what I've tried:
ArgumentCaptor<Foo> firstFooCaptor = ArgumentCaptor.forClass(Foo.class);
ArgumentCaptor<Foo> secondFooCaptor = ArgumentCaptor.forClass(Foo.class);
verify(mockBar).doSomething(firstFooCaptor.capture());
verify(mockBar).doSomething(secondFooCaptor.capture());
// then do ...
|
So I have a class that looks like this.
@Inject
AnotherClass anotherClass;
public class Foo {
public Boolean someMethod(){
Holder<Boolean> booleanHolder = new ...
|
I'd like to verify calls to a logger object, so that the real implementation is still called (so I can see the output during tests).
Something like
verify(logger).error(anyString())
|
Possible Duplicate:
Java: How to test methods that call System.exit()?
In a certain scenario, I want to test that the application makes a function call to ... |
I want to test a java method that has an enhanced for on it using Mockito. The problem is that when I don't know how to set the expectations for the ... |
I came across a problem and I can't find an elegant solution.
So the problem is with a mock of Selenium web driver, and I dont know how should I test/mock void ... |
Hello I would like to know, if there is any way to dynamicaly modify behaviour of mocks in Mockito.
For example I have a method count() and I would like Mockito to ... |
Is there a way to get a mocked class to return some object no matter what arguments the function is called with?
For example, if one of my parameters' types did not ... |
The book Growing Object Oriented Software gives several examples in jMock where the state is made explicit without exposing it through an API. I really like this idea. Is there a ... |
I am trying to use Powermock and Mockito to mock a void static method to throw exception as below. But I met a problem. Unless I make the two invocations of ... |
I have the following code
@PrepareForTest({Mongo.class, XYMongo.class, DB.class})
public class XYMongoTest extends UnitTest{
String host = Play.configuration.getProperty("mongo.host");
int port = Integer.parseInt(Play.configuration.getProperty("mongo.port"));
String name = Play.configuration.getProperty("mongo.name");
@Test
public void testRetrieveMongoDBSuccessful() throws UnknownHostException, MongoException, Exception
{
...
|
My app has two classes, FireWatcher and AlarmBell. When a fire starts, the watcher should ring the bell, with a level. For small fires, ring the bell with a small alarm ... |
I'd like to use strict mocks, at least when developing for the first time some tests against old code, so any methods invoked on my mock will throw an exception if ... |
I use org.apache.commons.beanutils.MethodUtils (api link) on occasion. I generally avoid reflection, but alas this case called for it.
My problem comes to testing. I use Mockito ... |
I have a JUnit class with different methods to perform different tests.
I use Mockito to create a spy on real instance, and then override some method which is not relevant to ... |
I have the following situation:
class Worker {
public Integer somework(){
Integer k=0;
Helper h= new Helper();
...
|