Mockito is a mocking framework for Java and like all other mocking frameworks is used as a helper in creating mock-objects for the use of isolated unit tests. Its creator, Szczepan Faber, wanted to create a mocking framework that is simpler to use. It is inspired and was first built upon EasyMock ...
0
votes
1answer
17 views
Mocking a call on a public method of an abstract class without subclassing the abstract Class, using mockito prefererably
I am writing an unit testing using JUNIT + Mockito to test a method like :
public someObject methodUnderTest(){
SomeObject obj = SomeAbstractClass.someMethod();
if(obj!=null){
obj.someOtherMethod();
...
7
votes
1answer
59 views
@InjectMocks behaving differently with Java 6 and 7
With a very simple Mockito run JUnit test and class I am seeing different output when the test is run with Java 1.6.0_32 and Java 1.7.0_04 and want to understand why this is happening. I suspect there ...
2
votes
2answers
27 views
Mocking net.sf.ehcache.Cache (ehcache) with .put method stub (Mockito)
I'm developing a simple cache functionality with EhCache.
There is a generic base class that implements my cache interface (BECache):
public class EhCacheBase<K, V> implements BECache<K, ...
0
votes
0answers
18 views
how can I mock the Context using Mockito and Robolectric?
This is a snippet of my activity :
public class Search extends Activity
{
private String TAG = "SEARCH";
@Override
public void onCreate(Bundle savedInstanceState)
{
...
3
votes
3answers
57 views
How can I know if a method was invoked on the unit under test?
I'm writing a new class (Derived), in TDD, using mockito and I have the following case:
Class Base:
public abstract class Base<T>{
//.......
protected final T baseCreate(T entity){
...
2
votes
2answers
85 views
Weirdness Using Google Guava Collections2.transform
I am not entirely sure what title to put on this problem to get the right minds. This seems like a Java slight of hand but it's only occuring using the Guava Collections2.transform. The transformer is ...
1
vote
1answer
36 views
Maven: compiling and testing on different source levels
I am currently working on a project which will run on an embedded device. The device runs a Java ME JRE (comparable to Java 1.4).
Because of this maven is configured to compile for source & ...
2
votes
3answers
67 views
Java testing verifying constructor
I am trying to figure out a way to verify a class constructor in the following way (keep in mind this is a theoretical example)
public MyClass extends ItemContainer {
public MyClass(RoundItem a, ...
2
votes
2answers
49 views
Mockito NumberFormat mocking NullPointer in when() method
so I've got this piece of code that throws me a NullPointerException
NumberFormat formatterFake = mock(NumberFormat.class);
when(formatterFake.format(1)).thenReturn("1");
The problem is I get an ...
1
vote
3answers
61 views
Unit test which verifies only a few elements
There is an interface:
interface IEventListener
{
void onEvent(List <IEvent> events);
}
There is an event class:
class EventB
{
private final int id;
private final A a;
private final ...
2
votes
1answer
65 views
PowerMockito mock single static method and return object
I want to mock an static method m1 from an class which contains 2 static methods m1 and m2. And I want the method m1 to return an object.
I tried the followings
1)
...
1
vote
1answer
97 views
mock method with generic and extends in return type
Is it possible to mock (with mockito) method with signature Set<? extends Car> getCars() without supress warnings? i tried:
XXX cars = xxx;
when(owner.getCars()).thenReturn(cars);
but no ...
1
vote
3answers
67 views
Mocking private methods used in public method with PowerMock, Mockito, and TestNG
I want to write a unit test for a class I have. This class has a public method, and inside the public method there are calls to private methods in the same class. I want to mock the calls to those ...
4
votes
1answer
68 views
How to stub get/set of simple types
I am new to Mockito and I was wondering how I could stub a get/set pair.
For example
public interface Order {
public short getStatus();
public void setStatus(short status);
}
How can I ...
1
vote
1answer
48 views
Mockito: List Matchers with generics
In Mockito (1.9), how to match a List with generics without suffering the warning Type safety: The expression of type List needs unchecked conversion to conform to List<? extends Bar>? I tried :
...