Closed GoogleCodeExporter closed 9 years ago
A more general workaround is to cast the return value of the mocked method, as
in...
when((Object)mock.get("a string")).thenReturn("another string")
This appears to avoid the cast-of-death.
Original comment by poisonp...@gmail.com
on 20 Jul 2009 at 10:12
Damn, I didn't see this issue. I tried your example with latest version of
Mockito
and it works. I think I'm going to close it...
Let me know if there are any other issues.
Original comment by szcze...@gmail.com
on 20 Oct 2009 at 7:35
I'm still getting the same error with Mockito 1.8.0. Here's my test procedure:
Windows XP SP3, jdk 1.6.0_15-b03
1. Download the zip attached to this ticket. Unzip it. Run cmd and cd to the
unzipped
directory.
2. Run mvn test. One test fails.
testGetUsingSmartNulls(mockito.erasurebug.FailsUsingSmartNullsTest)
3. Update the pom to mockito-all 1.8.0.
4. Run mvn test again. Still, the same test fails.
Original comment by poisonp...@gmail.com
on 22 Oct 2009 at 2:19
Original comment by szcze...@gmail.com
on 22 Oct 2009 at 2:43
will try it. Thanks for reporting!
Original comment by szcze...@gmail.com
on 22 Oct 2009 at 2:44
I tried the zip and it 'mvn test' fails indeed but 'mvn clean test' works fine
with
version 1.7+
Are you sure this issue still persists?
Original comment by szcze...@gmail.com
on 28 Oct 2009 at 10:08
Closing this one as it seems to be resolved
Original comment by szcze...@gmail.com
on 5 Nov 2009 at 10:40
Original comment by szcze...@gmail.com
on 11 Nov 2009 at 1:33
Original comment by szcze...@gmail.com
on 11 Nov 2009 at 2:36
Hi... I see this with 1.8.5 but only when the .class files are compiled by
eclipse. When I compile using 'javac' I do NOT see the problem. I have no idea
whether this is an eclipse issue or a mockito issue. It is, however, very sad.
# OS (Fedora Core 12)
uname -a
Linux linux-dev71.sdsp.mc.xerox.com 2.6.32.26-175.fc12.x86_64 #1 SMP Wed Dec 1
21:39:34 UTC 2010 x86_64 x86_64 x86_64 GNU/Linux
# eclipse (32 bit, Helios)
# java (32 bit version)
$ java -version
java version "1.6.0_24"
Java(TM) SE Runtime Environment (build 1.6.0_24-b07)
Java HotSpot(TM) Server VM (build 19.1-b02, mixed mode)
I built the attached test app with the following libraries:
Hamcrest: hamcrest-all-1.3.0RC2.jar
Mockito: mockito-all-1.8.5.jar
JUnit:
eclipse-1.3.2.20110301-1815/plugins/org.junit_4.8.1.v4_8_1_v20100427-1100/junit.
jar
Original comment by j...@pentastich.org
on 2 May 2011 at 5:51
Attachments:
The test file I uploaded on comment 10 came in as zero bytes, for some reason.
Here's another try.
-- Jim
Original comment by j...@pentastich.org
on 2 May 2011 at 11:22
Attachments:
Here are the class files generated by eclipse.
Also, here's the eclipse version info and some info about the project settings.
Eclipse IDE for Java Developers
Version: Helios Service Release 2
Build id: 20110218-0911
The project was created with the default settings:
JavaSE-1.6
Compiler compliance level: 1.6
Generated .class files compatibility: 1.6
Source compatibility: 1.6
Original comment by j...@pentastich.org
on 9 May 2011 at 3:27
Attachments:
This happens to me as well on eclipse with Mockito 1.9.
List<String> mock = mock(List.class, Mockito.RETURN_SMART_NULLS);
when(mock.get(0)).thenReturn("two");
The second line throws a class cast exception. I'm using eclipse indigo (3.7).
Original comment by ayac...@gmail.com
on 16 May 2012 at 7:02
Original issue reported on code.google.com by
poisonp...@gmail.com
on 20 Jul 2009 at 10:03Attachments: