helenwangtiger / mockito Goto Github PK
View Code? Open in Web Editor NEWAutomatically exported from code.google.com/p/mockito
Automatically exported from code.google.com/p/mockito
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:
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
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:
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
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
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
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:
Upload to Central repository according to the
http://maven.apache.org/guides/mini/guide-central-repository-upload.html
Original issue reported on code.google.com by [email protected]
on 19 Feb 2008 at 12:43
testing if notifications are sent to mockito-dev mailing list
Original issue reported on code.google.com by [email protected]
on 16 Mar 2008 at 3:14
Reported here: http://groups.google.com/group/mockito/t/3945fe1eca2954e7
Original issue reported on code.google.com by [email protected]
on 12 Oct 2008 at 8:23
IDEs sometimes don't resolve @Mock annotation as painlessly as they should.
@Mock annotation should be made a top-level class instead of an inner class.
Original issue reported on code.google.com by [email protected]
on 18 Sep 2008 at 9:56
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
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
add junit runners that automaticaly initialize mocks annotated with @Mock
Original issue reported on code.google.com by [email protected]
on 18 Sep 2008 at 10:17
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:
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
testing if notifications are sent to mockito-dev mailing list #2
Original issue reported on code.google.com by [email protected]
on 16 Mar 2008 at 3:21
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
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:
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
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:
I used to extend Mockito in Tyburn, so that I could have my own custom
matchers. I finally got round to upgrading and can't do that any more! Any
reason why Mockito's constructor is private?
Original issue reported on code.google.com by [email protected]
on 25 Jul 2008 at 1:03
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:
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:
Reported here: http://groups.google.com/group/mockito/t/d95e1b82d574a36f
Couldn't reproduce it along with instructions - see mockito-bug-1.zip
attachment.
Original issue reported on code.google.com by [email protected]
on 26 Sep 2008 at 9:05
Attachments:
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
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
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
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:
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
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
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
Upload to Central repository according to the
http://maven.apache.org/guides/mini/guide-central-repository-upload.html
Original issue reported on code.google.com by [email protected]
on 19 Feb 2008 at 12:43
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.