Git Product home page Git Product logo

mockito's People

Contributors

andrerigon avatar bric3 avatar dgageot avatar eamelink avatar hmlnarik avatar iczechowski avatar josepaumard avatar lucascs avatar meddahj avatar mileszk avatar mockitoguy avatar szpak avatar

Watchers

 avatar

mockito's Issues

spy() trows StringIndexOutOfBoundsException when called on an anonymous inner class

As per subject :)


This is the trace:

java.lang.StringIndexOutOfBoundsException: String index out of range: 1
    at java.lang.String.substring(String.java:1765)
    at org.mockito.internal.util.MockUtil.toInstanceName(MockUtil.java:33)
    at org.mockito.internal.util.MockUtil.createMock(MockUtil.java:22)
    at org.mockito.Mockito.spy(Mockito.java:500)
    at com.acme.secretproject.TestRetry.testRetrySuccess(TestRetry.java:21)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.jav
a:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at junit.framework.TestCase.runTest(TestCase.java:164)
    at junit.framework.TestCase.runBare(TestCase.java:130)
    at junit.framework.TestResult$1.protect(TestResult.java:106)
    at junit.framework.TestResult.runProtected(TestResult.java:124)
    at junit.framework.TestResult.run(TestResult.java:109)
    at junit.framework.TestCase.run(TestCase.java:120)
    at
org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestR
eference.java:130)
    at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner
.java:460)
    at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner
.java:673)
    at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java
:386)
    at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.jav
a:196)


This is how to reproduce, I instantiate an anonymous implementation of the
interface java.util.concurrent.Callable, the Class.getSimpleName() returns
an empty string... and makes mockito to break :

   public void testRetrySuccess() throws Exception  {
        final Object expected = new Object(); 
        Callable<Object> successLogic = new Callable<Object>() {
            public Object call() throws Exception {
                return expected;
            }
        };

        Callable<Object> spy = spy(successLogic);
        ...
   }

Thanks guys! Fantastic framework.

Original issue reported on code.google.com by [email protected] on 7 Nov 2008 at 2:44

Checking the method calls ordering in multi-thread environment.

What steps will reproduce the problem?
Just run the test in attach.

What version of the product are you using? On what operating system?
Mockito 1.6

I have mocked my listener which is used in multi-threaded environment with
Mockito. I have a list of threads which are calling methods on the
listener. I need to check the order of methods calls on the listener, i.e.
that order is, for instance method1(), method2(), method3() regardless of
which thread exactly did the call. My tests always fail because as I see in
debug ThreadLocal is used to assign SequenceNumber to invocations, i.e.
invocation of method1() can have SequenceNumber =1 as well as invocation of
method2() can have SequenceNumber =1. So I lost one of the invocations with
SequenceNumber =1. 


Original issue reported on code.google.com by [email protected] on 31 Oct 2008 at 4:12

Attachments:

Running into problems with the static MOCKING_PROGRESS

See attached test!

To give you some context as to why I was doing this, I'm trying to put a
viewport in front of the Game of Life, so that I can scroll around. The
viewport provides an anonymous implementation of the game to the observer,
tweaked by a particular offset. I was using mockito to create both the
initial grid that sets up the viewport, and the expected grid that should
appear on the GUI.

I know that I can assign the stub to a local variable. Any chance of at
least getting an error message that tells me not to set up stubs while I'm
verifying something else? Preferably Mockito would not use a static
MOCKING_PROGRESS, and would let me create stubs while verifying. But there
may be some issues I'm not aware of.

The "WantedButNotInvoked" exception that I got... on a stubbing set-up...
made me briefly wonder if Mockito had gone completely insane, or I had a
really old and broken version or something.

Original issue reported on code.google.com by [email protected] on 2 Dec 2008 at 5:55

Attachments:

Can't mock toString()

public class ToStringTest {

    @Test
    public void shouldBeAbleToMockToString() {
        ThingAsAString thing = Mockito.mock(ThingAsAString.class);
        Mockito.stub(thing.toString()).toReturn("Wibble");

        assertEquals("Wibble", thing.toString());
    }

    private static interface ThingAsAString {
        public String toString();
    }
}

(Found by Tom and Candace at TWU)

Original issue reported on code.google.com by [email protected] on 13 Mar 2008 at 4:13

NPE on verification when multiple threads used

I am getting a null pointer in my verify step. I get it from something
like verify(mock, times(2).myMethod()

main test thread:
 init mocks
 stub what is needed
 kick of two threads

in the two threads
 execute myMethod()

back in main thread
 wait for the threads to day
 verify myMethod()

Stack trace:

java.lang.NullPointerException
       at
org.mockito.internal.invocation.Invocation.isToString(Invocation.java:
181)
       at org.mockito.internal.verification.RegisteredInvocations
$RemoveToString.isOut(RegisteredInvocations.java:33)
       at org.mockito.internal.verification.RegisteredInvocations
$RemoveToString.isOut(RegisteredInvocations.java:31)
       at org.mockito.internal.util.ListUtil.filter(ListUtil.java:15)
       at
org.mockito.internal.verification.RegisteredInvocations.getVerifiableInvocations
(RegisteredInvocations.java:
28)
       at
org.mockito.internal.verification.VerifyingRecorder.getRegisteredInvocations(Ver
ifyingRecorder.java:
35)
       at
org.mockito.internal.verification.VerifyingRecorder.verify(VerifyingRecorder.jav
a:
47)
       at org.mockito.internal.MockHandler.intercept(MockHandler.java:73)
       at
org.mockito.internal.creation.MethodInterceptorFilter.intercept(MethodIntercepto
rFilter.java:
45)
       at com.sonicsw.esb.service.common.ramps.IDataSink$$EnhancerByCGLIB$
$413fdc72.createSinkConnection(<generated>)
       at RampTest.testUnblock(RampTest.java:326)

Original issue reported on code.google.com by [email protected] on 25 Jun 2008 at 1:09

Mockito affect hsqldb internal

What steps will reproduce the problem?
1. Initialize in-memory hsqldb
2. Stub some interface
3. Check internal state of hsqldb after ... mock(Some.class);

What is the expected output? What do you see instead?

Specifically I'm insert 3 rows in HSQLDB
Expected 3 rows after mocking some interface 

What version of the product are you using? On what operating system?
Linux, Mockito 1.6

Please provide any additional information below.
When I check database before stubbing - all right.
but just after mocking interface (not tied with HSQLDB) - I got 1 row instead.

some code:

        pTranslation.addTranslatedPhrase("module1", "cat", "cat");
        pTranslation.addTranslatedPhrase("module1", "dog", "dog");
        pTranslation.addTranslatedPhrase("module2", "rat", "rat");

        List<Phrase> dictionaryData = new ArrayList<Phrase>();
        dictionaryData.add(new Phrase("module1", "cat"));
        dictionaryData.add(new Phrase("module1", "elephant"));
        dictionaryData.add(new Phrase("module1", "rat"));

        // at this moment check pass (3 rows)
        Dictionary mockedDictionary = mock(Dictionary.class);
        // now got 1 row



Original issue reported on code.google.com by [email protected] on 26 Dec 2008 at 6:39

remove dependency to cglib/objenesis

Evaluate java.lang.instrument API to create mocks (proxies). As JMockit
does it (http://jmockit.dev.java.net).

That can potentially remove heavy dependencies to objenesis and cglib.

Related to issue #11

Original issue reported on code.google.com by [email protected] on 9 May 2008 at 3:39

Please add mockito-all.jar to the public maven repository

Mockito is great, but I haven't found it in any public maven repository.

I've installed it into the local repository using the following script
without problems:

1        #!/bin/sh
2   
3   groupId=org.mockito
4   artifactId=mockito-all
5   version=1.2
6   packaging=jar
7   file=$artifactId-$version.$packaging
8   
9   # TODO: add file existance checking
10  rm $file
11  
12  wget http://mockito.googlecode.com/files/$file
13  
14  mvn install:install-file -Dfile=$file -Dversion=$version
-DartifactId=$artifactId -Dpackaging=$packaging -DgroupId=$groupId
15  rm $file


What is the expected output? What do you see instead?

It will be cool to have the ability to add the following entry to pom.xml
and don't install the file to the local repository manually

<dependency>
  <groupId>org.mockito</groupId>
  <artifactId>mockito-all</artifactId>
  <version>1.2</version>
</dependency>


What version of the product are you using? On what operating system?

mockito-all-1.2.jar


Please provide any additional information below.

I've also found that installing the mockito-all-1.2.jar to the local
repository using artifactory (http://www.jfrog.org/sites/artifactory/1.2/)
has some troubles, cause it parse META-INF and grabs the groupId and
artifactId from objenesis

Original issue reported on code.google.com by [email protected] on 7 Mar 2008 at 6:46

tests are not isolated under verification

What steps will reproduce the problem?
1. check out sesia source code
2. replace test with code below
3. uncomment line 65
4. run test

You can probably trim the test down to remove all dependencies on sesia and
skip step 1.

What is the expected output? What do you see instead?
I'd expect a green test, but I get an exception (see stacktrace below). It
seems that the verifyNoMoreInteractions call is having effect on the newly
created mock in the setup for the next test. Hmmmm.

I did some experimenting and made these observations:
- if I create the mocks once (inline) and not @Before, the results are
exactly the same
- if I reorder the tests the results are different
- originally I found the problem when I did verify(fileSource.receive());
instead of verify(fileSource).receive();

What version of the product are you using? On what operating system?
1.6.0, Mac OSX 10.5 (from here:
http://www.springsource.com/repository/app/bundle/version/detail?name=com.spring
source.org.mockito&version=1.6.0&searchType=bundlesByName&searchQuery=mockito)

Please provide any additional information below.

The testclass code:
/*
 * Copyright 2002-2008 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.springframework.integration.ftp;

import static org.mockito.Mockito.*;
import static org.junit.Assert.*;

import java.io.File;

import org.junit.Before;
import org.junit.Test;
import org.springframework.integration.core.Message;
import org.springframework.integration.file.FileListFilter;
import org.springframework.integration.file.FileReadingMessageSource;

;

/**
 * @author Iwein Fuld
 */
@SuppressWarnings("unchecked")
public class FtpFileSourceTests {

    private FtpInboundSynchronizer ftpSynchronizer;

    private FileReadingMessageSource fileSource;

    private Message<File> messageMock;

    private FtpFileSource ftpSource;

    private Object[] allMocks;

    @Before
    public void setup() {
        ftpSynchronizer = mock(FtpInboundSynchronizer.class);
        fileSource = mock(FileReadingMessageSource.class);
        messageMock = mock(Message.class);
        ftpSource = new FtpFileSource(fileSource, ftpSynchronizer);
        allMocks = new Object[] { ftpSynchronizer, fileSource, messageMock };
    }

    @Test
    public void retrieveSingleFile() throws Exception {
        when(fileSource.receive()).thenReturn(messageMock);
        fileSource.onSend(messageMock);
        Message<File> received = ftpSource.receive();
        fileSource.onSend(received);
        verify(fileSource).receive();
        //verifyNoMoreInteractions(allMocks);
    }

    @Test
    public void onFailure() throws Exception {
        when(fileSource.receive()).thenReturn(messageMock);
        Exception exception = new Exception("just a test");
        fileSource.onFailure(messageMock, exception);
        Message<File> received = ftpSource.receive();
        ftpSource.onFailure(received, exception);
        assertEquals(received, ftpSource.receive());
        verify(fileSource, times(2)).receive();
    }

}

stacktrace:
org.mockito.exceptions.verification.NoInteractionsWanted: 
No interactions wanted
    at
org.springframework.integration.ftp.FtpFileSourceTests.retrieveSingleFile(FtpFil
eSourceTests.java:65)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.jav
a:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.junit.internal.runners.TestMethod.invoke(TestMethod.java:59)
    at org.junit.internal.runners.MethodRoadie.runTestMethod(MethodRoadie.java:98)
    at org.junit.internal.runners.MethodRoadie$2.run(MethodRoadie.java:79)
    at
org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadi
e.java:87)
Caused by: org.mockito.exceptions.cause.UndesiredInvocation: 
Undesired invocation:
fileReadingMessageSource.setFilter(
    org.springframework.integration.file.CompositeFileListFilter@19f16e6e
);
    at
org.springframework.integration.ftp.FtpFileSource.<init>(FtpFileSource.java:55)
    at
org.springframework.integration.ftp.FtpFileSourceTests.setup(FtpFileSourceTests.
java:54)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.jav
a:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.junit.internal.runners.MethodRoadie.runBefores(MethodRoadie.java:122)
    at
org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadi
e.java:86)
    at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:77)
    at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:42)
    at
org.junit.internal.runners.JUnit4ClassRunner.invokeTestMethod(JUnit4ClassRunner.
java:88)
    at
org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:5
1)
    at
org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)
    at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
    at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
    at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
    at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReferen
ce.java:45)
    at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner
.java:460)
    at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner
.java:673)
    at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java
:386)
    at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.jav
a:196)

link to code under test:
https://fisheye.springframework.org/browse/se-sia/trunk/org.springframework.inte
gration.ftp/src/main/java/org/springframework/integration/ftp/FtpFileSource.java
?r=24


Original issue reported on code.google.com by [email protected] on 30 Dec 2008 at 12:23

bean is not returned. a null value is returned instead

What steps will reproduce the problem?
1. invoke a method which returns a bean
2.
3.

What is the expected output? What do you see instead?
a mock bean should return

What version of the product are you using? On what operating system?
1.2 mockito

Please provide any additional information below.
stub(mock.somemethod("arg1", arg2, 0, 1, list1, list2)).toReturn(mockBean);

Original issue reported on code.google.com by [email protected] on 16 Dec 2008 at 6:52

custom agument matcher called to match wrong method call

I had a custom argument matcher defined to verify a call to function X.
The custom argument matcher's match function was called when looking for an
argument matcher for function Y.

I am using Mockito 1.2

--

What steps will reproduce the problem?
2. setup a test that calls two functions, one taking a string parameter, 
the other taking a domain object
3. create a custom matcher that matches the domain object
4. verify the 2nd call only:

verify(view, atLeastOnce()).addProperty( argThat(new customDomainMatcher()) ); 

5.  the custom domain matcher will be called to validate the string
parameter, even though the verify is on the other function call


What is the expected output? What do you see instead?

The custom matcher should be called only on the particular function being
verified.

It is actually called for other functions too.

I think this is because in InvocationMatcher.java:

overloadedButSameArgs calculation calls the customer matcher defined for
method function X even though wantedMethodName and currentMethodName differ

In my case, a string is being passed by the call calculating
overloadedButSameArgs which can't be converted to the domain object and
fails.  It shouldn't be called in the first place, becuase if
methodNameEquals if false, nothing else should happen?

Solution:
return false immediately in InvocationMatcher.isSimilarTo if wanted and
current names differ.

The attached implementation of InvocationMatcher.isSimilarTo works for me.











What version of the product are you using? On what operating system?


Please provide any additional information below.


Original issue reported on code.google.com by [email protected] on 13 Mar 2008 at 6:02

Attachments:

Can't stub spied object

I can not stub method for spying object. There is thrown
NullPointerException if I use anyString() as an argument of the method and
inside the method the argument is used.

Example:
I have following class:

11: public class Main {
12: 
13:     public String sayHello(String name) {
14:         int len = name.length();
15:         return "Hello "+name+" ["+len+"]";
16:     }
17:
18: }

and test for such class:

13: @Test
14: public void testSayHello() {
15:     Main main = new Main();
16:     Main spy = spy(main);
17:     stub(spy.sayHello(anyString())).toReturn("Hello!");
18:     System.out.println(spy.sayHello("Chris"));      
19:     verify(spy).sayHello("Chris");      
20: }

Now when I run the test I get:
java.lang.NullPointerException
    at Main.sayHello(Main.java:11)
    at Main$$FastClassByCGLIB$$2479d9.invoke(<generated>)
    at org.mockito.cglib.proxy.MethodProxy.invoke(MethodProxy.java:191)
    at org.mockito.internal.MockHandler.intercept(MockHandler.java:92)
    at
org.mockito.internal.creation.MethodInterceptorFilter.intercept(MethodIntercepto
rFilter.java:45)
    at Main$$EnhancerByCGLIB$$7d3682ac.sayHello(<generated>)
    at MainTest.testSayHello(MainTest.java:17)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at
org.junit.internal.runners.TestMethodRunner.executeMethodBody(TestMethodRunner.j
ava:99)
    at
org.junit.internal.runners.TestMethodRunner.runUnprotected(TestMethodRunner.java
:81)
    at
org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunne
r.java:34)
    at
org.junit.internal.runners.TestMethodRunner.runMethod(TestMethodRunner.java:75)
    at org.junit.internal.runners.TestMethodRunner.run(TestMethodRunner.java:45)
    at
org.junit.internal.runners.TestClassMethodsRunner.invokeTestMethod(TestClassMeth
odsRunner.java:66)
    at
org.junit.internal.runners.TestClassMethodsRunner.run(TestClassMethodsRunner.jav
a:35)
    at
org.junit.internal.runners.TestClassRunner$1.runUnprotected(TestClassRunner.java
:42)
    at
org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunne
r.java:34)
    at org.junit.internal.runners.TestClassRunner.run(TestClassRunner.java:52)
    at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReferen
ce.java:45)
    at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner
.java:460)
    at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner
.java:673)
    at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java
:386)
    at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.jav
a:196)

I use:
mockito: 1.5
java: 1.6
OS: Windows XP

regards
yaSiu

Original issue reported on code.google.com by [email protected] on 2 Oct 2008 at 1:40

Verfication of varArgs call yields NPE

What steps will reproduce the problem?
Try to run the following test case:

package com.gu.r2.perftest.cifurlmapper;

import org.junit.Test;
import org.mockito.Mockito;

public class MockitoTest {

    @Test
    public void shouldWork() {
        MyClass myClass = Mockito.mock(MyClass.class);
        myClass.varArgs("");        
        Mockito.verify(myClass).varArgs((String[]) Mockito.anyObject());

    }       
    public class MyClass {      
        public void varArgs(String... args) {

        }       
    }

}


What is the expected output? What do you see instead?
A passing testcase. An NPE:
java.lang.NullPointerException
    at java.lang.reflect.Array.getLength(Native Method)
    at
org.mockito.internal.matchers.ArrayEquals.createObjectArray(ArrayEquals.java:77)
    at
org.mockito.internal.invocation.Invocation.expandVarArgs(Invocation.java:57)
    at org.mockito.internal.invocation.Invocation.<init>(Invocation.java:46)
    at org.mockito.internal.MockHandler.intercept(MockHandler.java:65)
    at
org.mockito.internal.creation.MethodInterceptorFilter.intercept(MethodIntercepto
rFilter.java:49)
    at
com.gu.r2.perftest.cifurlmapper.MockitoTest$MyClass$$EnhancerByCGLIB$$237bdab6.v
arArgs(<generated>)
    at com.gu.r2.perftest.cifurlmapper.MockitoTest.shouldWork(MockitoTest.java:12)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.jav
a:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.junit.internal.runners.TestMethod.invoke(TestMethod.java:59)
    at org.junit.internal.runners.MethodRoadie.runTestMethod(MethodRoadie.java:98)
    at org.junit.internal.runners.MethodRoadie$2.run(MethodRoadie.java:79)
    at
org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadi
e.java:87)
    at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:77)
    at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:42)
    at
org.junit.internal.runners.JUnit4ClassRunner.invokeTestMethod(JUnit4ClassRunner.
java:88)
    at
org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:5
1)
    at
org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)
    at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
    at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
    at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
    at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReferen
ce.java:38)
    at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner
.java:460)
    at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner
.java:673)
    at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java
:386)
    at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.jav
a:196)



What version of the product are you using? On what operating system?
1.2

Please provide any additional information below.
When changing the signature to varArgs(String[] args) it works fine.

Best,
Felix

Original issue reported on code.google.com by [email protected] on 15 May 2008 at 5:47

make spy working with Anonymous classes

What steps will reproduce the problem?

Creating a spy() mock in my @Before.

What is the expected output? What do you see instead?

I expected a spy-mock, but instead got this exception in my @Before:
--------------------------------------------------------------------
java.lang.StringIndexOutOfBoundsException: String index out of range: 1
        at java.lang.String.substring(String.java:1765)
        at org.mockito.internal.util.MockUtil.toInstanceName
(MockUtil.java:33)
        at org.mockito.internal.util.MockUtil.createMock(MockUtil.java:22)
        at org.mockito.Mockito.spy(Mockito.java:500)
        at net.karmazilla.nanocache.GenericCacheTest.setUp
(GenericCacheTest.java:43)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke
(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke
(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall
(FrameworkMethod.java:44)



What version of the product are you using? On what operating system?
mockito-all 1.5.

$ uname -a
Linux Unwire-0227 2.6.24-19-generic #1 SMP Wed Aug 20 17:53:40 UTC 2008 
x86_64 GNU/Linux
$ java -version
java version "1.6.0_0"
OpenJDK  Runtime Environment (build 1.6.0_0-b11)
OpenJDK 64-Bit Server VM (build 1.6.0_0-b11, mixed mode)


Original issue reported on code.google.com by [email protected] on 14 Oct 2008 at 11:52

ArrayEquals throws exception

What steps will reproduce the problem?
1. Run the JUnit test in attachment

What is the expected output? What do you see instead?
Expected is the following exception :
org.mockito.exceptions.verification.ArgumentsAreDifferent

Instead the following exception is thrown :
java.lang.IllegalArgumentException: Something went really wrong. Arguments
passed to ArrayEquals have to be an array or null!

What version of the product are you using? On what operating system?
Mockito 1.4/Mockito 1.5 on Windows XP

Please provide any additional information below.
See attachment.

Original issue reported on code.google.com by [email protected] on 5 Sep 2008 at 9:46

Attachments:

Arguments are saved by a reference

What steps will reproduce the problem?

See the attachment.

What is the expected output? What do you see instead?

Test should pass, while it fails.

Please use labels and text to provide additional information.

Didn't look at the source code, but it looks like Mockito saves arguments
by a reference. The problem is when argument's attribute is changed after
method invocation, so "equals" doesn't work as expected. Just look at the
attachment, it is pretty much self-explaining.

Original issue reported on code.google.com by [email protected] on 7 Aug 2008 at 4:14

Attachments:

Maven artifacts

It would be nice to have a all the artifacts in the Maven repository and
not only the
code(http://repo2.maven.org/maven2/org/mockito/mockito-all/1.6/mockito-all-1.6-s
ources.jar
&
http://repo2.maven.org/maven2/org/mockito/mockito-all/1.6/mockito-all-1.6-javado
cs.jar.)

Thanks.

Original issue reported on code.google.com by [email protected] on 6 Dec 2008 at 3:21

Method calls not recorded by Mockito.mock

It would be great if the instance returned by mock() and spy() remembers
method calls from another method call (both methods are of the same instance).

---------------------------
The following test case demonstrate the idea:

  private static class A {
    void m1() {
      m2(1);
    }

    void m2(int n) {
    }
  }

  public void testMock() {
    A a1 = mock(A.class);
    a1.m1();
    a1.m2(2);

    verify(a1).m1();
    verify(a1).m2(eq(1)); // fail
  }

  public void testSpy() {
    A a2 = spy(new A());
    a2.m1();
    a2.m2(2);

    verify(a2).m1();
    verify(a2).m2(eq(1)); // fail
  }

Original issue reported on code.google.com by [email protected] on 6 Nov 2008 at 9:42

Junit no output

What steps will reproduce the problem?
1. on running the testcase no output is generated neither does it comes up 
with any exception or error
2.
3.

What is the expected output? What do you see instead?
package org.custommonkey.xmlunit;
public class selftest {
public static void  main(String args[]) throws Exception {
String name="compare";
test_Diff test2 = new test_Diff(name);

try{
test2.testRepeatedElementNamesWithNamespacedAttributeQualification();
}
catch (Exception e) {
            e.printStackTrace();
        } 
}
} 

i have a class test_Diff extends TestCase which has a method:............

public void testRepeatedElementNamesWithNamespacedAttributeQualification() 
throws Exception {
        Diff diff = buildDiff("<root xmlns:a=\"http://a.com\" 
xmlns:b=\"http://b.com\">"
                              + "<node id=\"1\" a:val=\"a\" 
b:val=\"b\"/><node id=\"2\" a:val=\"a2\" b:val=\"b2\"/></root>",
                              "<root xmlns:c=\"http://a.com\" 
xmlns:d=\"http://b.com\">"
                              + "<node id=\"2\" c:val=\"a2\" d:val=\"b2
\"/><node id=\"1\" c:val=\"a\" d:val=\"b\"/></root>");
        diff.overrideElementQualifier(new ElementNameAndAttributeQualifier
());
        diff.overrideDifferenceListener(new ExpectedDifferenceListener(
                                                                       new 
int[] {DifferenceConstants.NAMESPACE_PREFIX_ID, 
DifferenceConstants.CHILD_NODELIST_SEQUENCE_ID}));
        assertFalse("should not be identical: " + diff.toString(), 
diff.identical());
        assertTrue("should be similar: " + diff.toString(), diff.similar
());
    }


............................
 the expected output is :
"Should not be identical"
"Should be similar"
........................
In command line :


C:\sushant\xmlunit-1.2-src\xmlunit-1.2
\tests\java\org\custommonkey\xmlunit>java org.custommonkey.xmlunit.selftest
                                        //HERE I EXPECT THE OUTPUT***
C:\sushant\xmlunit-1.2-src\xmlunit-1.2
\tests\java\org\custommonkey\xmlunit>path
PATH="C:\sushant\jsdk-1_6\bin"

C:\sushant\xmlunit-1.2-src\xmlunit-1.2
\tests\java\org\custommonkey\xmlunit>echo
%CLASSPATH%
.;C:\sushant\jsdk-1_6\MyLib\junit-4.5.jar ;C:\sushant\jsdk-1_6
\MyLib\xmlunit-1.2
.jar

C:\sushant\xmlunit-1.2-src\xmlunit-1.2\tests\java\org\custommonkey\xmlunit>

What version of the product are you using? On what operating system?
jdk6, junit4.5, xmlunit1.2

Please provide any additional information below.

i am aware that in junit4 junit.framework is deprecated but xmlunit API 
has been built to be compatible with methods of junit3.8. i am aware that 
junit4 still supports methods of junit3.x. so that might not be the reason.

any ideas tips is welcome. 
thank u

Original issue reported on code.google.com by [email protected] on 17 Jan 2009 at 11:59

mock.toString() should print mock name

copy-pasted from the mailing list:

Is there any reason why when a mock is named, that the name is not or
cannot be included the mock's toString()? It would be very helpful in
the debugger to see the mock's name as part of value that the debugger
view displays.

Original issue reported on code.google.com by [email protected] on 18 Jan 2009 at 7:17

spied object's methods not being overided

What steps will reproduce the problem?
1.
Created class to test:
package testSomething;

public class TestSomething {
    public String testSomething() {
        return somethingElse("hello");
    }

    public String somethingElse(String greeting) {
        return greeting;
    }
}
2. Created test to test...
package testSomething;

import static org.junit.Assert.*;
import static org.mockito.Mockito.*;

import org.junit.Test;

public class TestSomethingTest {
    @Test
    public void shouldReturnTrue() {
        TestSomething testInstance = spy(new TestSomething());      
        when(testInstance.somethingElse(eq("hello"))).thenReturn("world");

        assertEquals("world", testInstance.testSomething());
    }
}
3. Run and watch fail 

What is the expected output? What do you see instead?
org.junit.ComparisonFailure: expected:<[world]> but was:<[hello]>
    ...
testSomething.TestSomethingTest.shouldReturnTrue(TestSomethingTest.java:14)
    ...

What version of the product are you using? On what operating system?
WindowsXP with Java 1.6, JUnit 4.5 and Mockito 1.6

Please provide any additional information below.
Have tried without eq(...) and doReturn syntax but still no go.

Original issue reported on code.google.com by [email protected] on 9 Jan 2009 at 3:40

Attachments:

PATCH : Performance Enhancement for MockHandler : Search matchers once instead of twice

Hello - the attached patch is a performance-enhancement for MockHandler,
reducing execution time from 105 seconds to 82 seconds for a particular set
of tests I'm currently working on.

MockHandler currently calls these 2 methods in quick succession when
providing the stubbed result for an invocation:

mockitoStubber.hasResultFor(invocation)
mockitoStubber.getResultFor(invocation)

Unfortunately this involves duplication of work, because both methods call
findMatch(invocation), which in turn will search *all* of the stubbed
invocations against this mock instance. The search is performed twice, when
it only needs to be performed once.

Reasonably, of course, there will usually only be a few stubbed invocations
against the mock object, and the matchers will be simple, so the search
will be fast, and the repetition doesn't matter. Unfortunately, I'm using
Mockito in a way in which it was probably not intended to be used, and so I
have around 8000 stubbed invocations against my mock (these are generated
using a log file produced by a Fortran program I'm attempting to port - see
http://sharesource.org/project/sasa/), and some moderately complicated
matchers, so executing the search twice rather than once becomes a
significant factor on test duration - the netbeans profiler put the cost of
each search at 35% of my test runtime, so I'd be happy to claim that back!

I'm hoping to reduce the insane number of stubbed invocations against my
mocks, but in the meantime this performance enhancement may be useful to
others.

Szczepan, forgive me for abusing your wonderful Mockito!

best regards,

Roberto


Original issue reported on code.google.com by [email protected] on 17 Aug 2008 at 11:04

Attachments:

Verify without method call causes errors in other tests.

What steps will reproduce the problem?
Run the test. 

What is the expected output? What do you see instead?
testVerify2 should not fail, but it does.

What version of the product are you using? On what operating system?
Using Windows Vista, Java 5, Junit 4 and mockito-all-1.5.jar

Please provide any additional information below.
When calling verify without providing the method to verify, no errors occur
in the test calling verify, but errors occur in later tests that try to use
Mockito.

Original issue reported on code.google.com by [email protected] on 5 Nov 2008 at 7:33

Attachments:

Please include source in final zip artifact

..or distribute a separate zip/jar of source, that would be fine too.  I'm
gonna add your project to ivy roundup (
http://code.google.com/p/ivyroundup/ ), and ivy users always appreciate source!

Thanks!

Original issue reported on code.google.com by [email protected] on 10 Dec 2008 at 4:32

ASM and CGLIB conflicts when used with Hibernate

What steps will reproduce the problem?
1. Maven2 project with Hibernate
2. Open in Eclipse (maybe other IDE's too)

What is the expected output? What do you see instead?

When running TestNG tests from Eclipse (using the plugin), received missing
class errors from cglib and asm calls.

What version of the product are you using? On what operating system?

1.1 + 1.2

Please provide any additional information below.

I think the error is just a conflict with the old (1.5.3) version of asm
pulled in by Hibernate. I solved this by excluding the Hibernate
dependencies and adding them explicitly, and then using the
mockito-core.jar (added to a local maven repository).

Note: I may have the wrong ASM/CGLIB version below, but it seems to be
working at the moment.

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate</artifactId>
    <version>3.2.2.ga</version>
    <exclusions>
        <exclusion>
            <groupId>asm</groupId>
            <artifactId>asm</artifactId>
        </exclusion>
        <exclusion>
            <groupId>asm</groupId>
            <artifactId>asm-attrs</artifactId>
        </exclusion>
        <exclusion>
            <groupId>cglib</groupId>
            <artifactId>cglib</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>asm</groupId>
    <artifactId>asm</artifactId>
    <version>2.2.3</version>
</dependency>
<dependency>
    <groupId>cglib</groupId>
    <artifactId>cglib-nodep</artifactId>
    <version>2.1_3</version>
</dependency>

Original issue reported on code.google.com by [email protected] on 11 Mar 2008 at 10:36

Replacement for anyObject ?

Hi,

First thank you for your beautiful mocking framework ! I use it in some
projects and i am very happy of the syntax and the ideas behind it. It
simplifies testing a lot :)

When using anyObject, my unit tests are like this:

verify(listener1, times(3)).onMessage(Mockito.<JMSMessageImpl>anyObject());

I find this syntax quite hugly ;) Is there an alternative, or could it be
possible to do something like these instead ?

verify(listener1, times(3)).onMessage(anyObject(JMSMessageImpl.class));
verify(listener1, times(3)).onMessage(any(JMSMessageImpl.class));
verify(listener1, times(3)).onMessage(anyInstanceOf(JMSMessageImpl.class));

Thanks !

Also, just FYI, i am working (nearly finished) on a project at
http://code.google.com/p/mycila/, amongst others, which aims at integrating
all testing-mocking,ioc frameworks to faciliate their use. This is much
more relevant for jmock, easymock, ... to add @Mock annotations and put
mocks in spring or guice ioc directly by adding @Bean or @Bind. So i also
integrated yours - quite a simple step actually ;)

Original issue reported on code.google.com by [email protected] on 11 Dec 2008 at 2:18

Varargs stubbing produces incorrect behavior

The following test fails .

public class VarArgsTest {

    interface MyClass {
        public String doSomething(String string, String... varargs);
    }

    @Test
    public void shouldWork() {
        MyClass myClass = mock(MyClass.class);
        when(myClass.doSomething("hello", null)).thenReturn("hello");
        when(myClass.doSomething("goodbye", null)).thenReturn("goodbye");

        String result = myClass.doSomething("hello", null);
        assertEquals("hello", result);
    }

What is the expected output? What do you see instead?
the expected output is "hello" but instead returns "goodbye"

What version of the product are you using? On what operating system?
v1.6 Windows XP 32 bit

Please provide any additional information below.


Original issue reported on code.google.com by [email protected] on 3 Nov 2008 at 10:53

how to stub a void method such that no exception is thrown on calling the main method in some other class

What steps will reproduce the problem?
1. test method xyz() of class A from class ATEST
2. stub a void method which is called within xyz()  
3.


What is the expected output? What do you see instead?
just return and do nothing

What version of the product are you using? On what operating system?

1.2
Please provide any additional information below.
stubVoid(mock).toThrow(new
NullPointerException()).on().getsomelist(resultslist);

Original issue reported on code.google.com by [email protected] on 17 Dec 2008 at 7:14

allow stubbing with callbacks

Proposed interface:

stub(mock.getStuff())
    .toAnswer(new Answer() {
        Object answer(Invocation invocation) throws Throwable {
            Object[] params = invocation.getParameters();
            return "foo";
        }  
    });

stubVoid(mock)
    .toAnswer(myAnswer)
    .on().someMethod();

Original issue reported on code.google.com by [email protected] on 25 Jun 2008 at 6:40

Wanted but not invoked exception in setup when running tests as a suite.

What steps will reproduce the problem?
1. see attached file. tests pass when run individually but fail when run as
a suite.

What is the expected output? What do you see instead?
expected output is two successful tests, actual output is:
first test: LuceneSearcherTest passes
second test: FeaturePagedResultTest fails on setup with exception:

org.mockito.exceptions.verification.WantedButNotInvoked: 
Wanted but not invoked:
query.setFirstResult(<any>);
    at
mockitobroketest.FeaturePagedResultTest.setup(FeaturePagedResultTest.java:18)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.junit.internal.runners.MethodRoadie.runBefores(MethodRoadie.java:122)
    at
org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadi
e.java:86)
    at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:77)
    at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:42)
    at
org.junit.internal.runners.JUnit4ClassRunner.invokeTestMethod(JUnit4ClassRunner.
java:88)
    at
org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:5
1)
    at
org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)
    at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
    at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
    at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
    at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReferen
ce.java:45)
    at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner
.java:460)
    at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner
.java:673)
    at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java
:386)
    at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.jav
a:196)




What version of the product are you using? On what operating system?
lucene 2.3.0
hibernate 3.2.6ga
mockito-all-1.6

Please provide any additional information below.


Original issue reported on code.google.com by [email protected] on 26 Nov 2008 at 11:58

Attachments:

New spying feature

New spying feature: creates a spy from a genuine object. Spy delegates to
real implementation but allows stubbing and verification. Similar to
partial mocking (known from other frameworks).

Proposed interface:

Foo foo = new Foo();

Foo spy = Mockito.spy(foo);
//also: @Spy annotation

//optional stubbing
Mockito.stub(spy.getStuff()).toReturn("hello");

//optional verification
Mockito.verify(spy).doStuff();

//calling methods on spy invokes the real implementation 
//unless the method is stubbed

spy.someMethod();
spy.getStuff();

Original issue reported on code.google.com by [email protected] on 25 Jun 2008 at 1:24

Mockito does not work in eclipse plugins

What steps will reproduce the problem?
1. Unzip Eclipse project (attachment)
2. Run MockitoTest as JUnit Test
3. Run MockitoTest as JUnit Plugin Test 

What is the expected output? What do you see instead?
When trying to mock an eclipse interface, an exception is thrown. Mocking
Java classes or classes from the same plugin, (or an buddy plugin) works.

What version of the product are you using? On what operating system?
mockito 1.3, Eclipse Target 3.3.1

Please provide any additional information below.
Seems to be some class loading problems. jmock had these problems in some
old version too. EasyMock works out of the box for eclipse plugins.

Original issue reported on code.google.com by [email protected] on 25 Apr 2008 at 3:47

Attachments:

when arguments are different the exception now allows using the comparison window

When assertEquals fails then most IDEs offer a feature of comparing the
expected and actual in a pop-up window. Mockito uses this functionality.
When verification fails due to different arguments then you would be able
to see the detailed comparison in a pop-up window. To bring up the pop-up
you can click on little icon near the Failure Trace or double click on
exception message in the Failure Trace.

Original issue reported on code.google.com by [email protected] on 18 Sep 2008 at 10:08

verify throws an IllegalArgumentException for overloaded method where array argument is incorrect

Mocking Outputstream to verify we write first a single byte, followed by an 
array of bytes.

Only interested in the verifying the write(byte[]) call.  When verified 
with the matching argument, test passes.  When verified with a byte array 
that does not match, an IllegalArgument is thrown:

java.lang.IllegalArgumentException: Something went really wrong. Arguments 
passed to ArrayEquals have to be an array or null!
    at 
org.mockito.internal.matchers.ArrayEquals.matches(ArrayEquals.java:50)
    at 
org.mockito.internal.invocation.InvocationMatcher.argumentsMatch(Invocation
Matcher.java:77)
    at 
org.mockito.internal.invocation.InvocationMatcher.hasSimilarMethod(Invocati
onMatcher.java:96)
    at 
org.mockito.internal.invocation.InvocationsFinder.findSimilarInvocation(Inv
ocationsFinder.java:67)
    at 
org.mockito.internal.verification.MissingInvocationVerifier.verify(MissingI
nvocationVerifier.java:37)
...


Original issue reported on code.google.com by [email protected] on 13 Oct 2008 at 11:53

Attachments:

Can't tell the difference between one mock and another

My mocks just toString() to "Mock for <class>".

Can I optionally construct them with a name, so I get, say

"Mock <name> for <class>"

so that I can tell the difference between two mocks for the same class, please?

(This is of course only applicable if I'm not mocking toString()... )

Original issue reported on code.google.com by [email protected] on 13 Mar 2008 at 4:32

InOrder.verify() displays the actual invocation on error when arguments are different

Mocking Outputstream to verify we write first a single byte, followed by an 
array of bytes.

Intentionally 'breaking' the tests by verifying the single byte as the 
incorrect character.

When we use inOrder to verify and have an incorrect value set, the actual 
invocation is not shown.  Without inOrder, does show.

With inOrder:

org.mockito.exceptions.verification.WantedButNotInvoked: 
Wanted but not invoked:
outputStream.write(3);
    at WriterTest.testWriteInOrder(WriterTest.java:29)

Without inOrder:

org.mockito.exceptions.verification.ArgumentsAreDifferent: 
Argument(s) are different! Wanted:
outputStream.write(3);
    at WriterTest.testWrite(WriterTest.java:36)
Caused by: org.mockito.exceptions.cause.ActualArgumentsAreDifferent: 
Actual invocation has different arguments:
outputStream.write(4);
    at WriterTest.write(WriterTest.java:16)
    at WriterTest.testWrite(WriterTest.java:35)



Original issue reported on code.google.com by [email protected] on 13 Oct 2008 at 8:31

Attachments:

Custom method invocations

I ran into this problem... can you help?

The listeners to one class are generated from another (I could use a
listener factory, but...)

I'd like to get a custom invocation to allow me to grab hold of the
listeners. Any way of doing that?

Here's an example of what I want, hope it explains a bit better...

  @Test
  public void wibbleSubjectCollectorShouldMaintainListOfSubjects() {
    Subject subject1 = Mockito.mock(Subject.class);
    Subject subject2 = Mockito.mock(Subject.class);


Mockito.stubVoid(subject1).to(catchTheListenerSoICanPretendToRespondToIt).on().s
etObserver(any(Observer.class));
  }

  public static class WibbleSubjectCollector {
    private Set<Subject> subjectsWithWibble = new HashSet<Subject>();

    public WibbleSubjectCollector(Subject... subjects) {
      for (final Subject subject : subjects) {
        subject.setObserver(new Observer() {
          public void changed(String message) {
            if (message.equals("Wibble")) {
              subjectsWithWibble.add(subject);
            } else {
              subjectsWithWibble.remove(subject);
            }
          }
        });
      }
    }
  }

  public static interface Observer {
    public void changed(String message);
  }

  public static class Subject {
    private Observer observer;
    private String message = "";

    public void changeMe(String message){
      this.message = message;
      observer.changed(message);
    }

    public void setObserver(Observer observer) {
      this.observer = observer;
    }
  }

Original issue reported on code.google.com by [email protected] on 13 Mar 2008 at 4:29

ConcurrentModificationExcception in verify(...) in multithreaded environment

What steps will reproduce the problem?

Can't easily reproduce, but encounter multiple times (from time to time, 
as usually with synchronization problems).

What is the expected output? What do you see instead?

ConcurrentModificationException is thrown:
java.util.ConcurrentModificationException
at java.util.LinkedList$ListItr.checkForComodification(LinkedList.java:761)
at java.util.LinkedList$ListItr.next(LinkedList.java:696)
at org.mockito.internal.util.ListUtil.filter(ListUtil.java:14)
at org.mockito.internal.verification.RegisteredInvocations.getAll
(RegisteredInvocations.java:29)
at org.mockito.internal.MockHandler.intercept(MockHandler.java:71)
at org.mockito.internal.creation.MethodInterceptorFilter.intercept
(MethodInterceptorFilter.java:45)
at 
cern.pm.core.srv.session.AnalysisSessionScheduler$$EnhancerByCGLIB$$784759c
1.newPmDataAvailable()
at 
cern.pm.core.srv.session.impl.AnalysisSessionStateImplTest.testDataCollecti
onFinished2(AnalysisSessionStateImplTest.java:144)

What version of the product are you using? On what operating system?

Mockito 1.6, Windows XP

Please provide any additional information below.

The code template which produces the exception looks like this:

InterfaceToMock interfaceToMock = mock(InterfaceToMock.class);
classUndertest.setInterfaceToMock (interfaceToMock );
classUndertest.doSomething();   //asynchronous call of interfaceToMock
Thread.sleep(500);
verify(interfaceToMock, times(1)).methodCalled();   //exception!

Original issue reported on code.google.com by [email protected] on 10 Nov 2008 at 10:37

problems installing mockito-all-1.2 to local maven repository

Extracted from http://code.google.com/p/mockito/issues/detail?id=2 (issue #2):

I've also found that installing the mockito-all-1.2.jar to the local
repository using artifactory (http://www.jfrog.org/sites/artifactory/1.2/)
has some troubles, cause it parse META-INF and grabs the groupId and
artifactId from objenesis.

Jar generation task may create some rubbish META-INF due to the fact that
it expands objenesis/cglib into signle jar.

Original issue reported on code.google.com by [email protected] on 16 Mar 2008 at 1:35

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.