forked from mockito/mockito
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes mockito#457 ClassCastExceptions can't occur any more cause the …
…parameter type is dynamically checked.
- Loading branch information
Christian Schwarz
committed
Jun 24, 2016
1 parent
3fe0fd7
commit 1f15555
Showing
10 changed files
with
161 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
src/test/java/org/mockitousage/bugs/CompareMatcherTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package org.mockitousage.bugs; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.mockito.AdditionalMatchers.leq; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
import org.junit.Test; | ||
import org.mockito.Mockito; | ||
import org.mockitousage.IMethods; | ||
|
||
public class CompareMatcherTest { | ||
private static final Object NOT_COMPARABLE = new Object(); | ||
|
||
/** | ||
* Should not throw an {@link NullPointerException} | ||
* @see Bug-ID https://github.com/mockito/mockito/issues/457 | ||
*/ | ||
@Test | ||
public void compareNullArgument() { | ||
final IMethods mock = mock(IMethods.class); | ||
|
||
when(mock.forInteger(leq(5))).thenReturn(""); | ||
|
||
assertThat(mock.forInteger(null)).isNull();//a default value must be returned | ||
} | ||
|
||
/** | ||
* Should not throw an {@link ClassCastException} | ||
*/ | ||
@Test | ||
public void compareToNonCompareable() { | ||
final IMethods mock = mock(IMethods.class); | ||
|
||
when(mock.forObject(leq(5))).thenReturn(""); | ||
|
||
assertThat(mock.forObject(NOT_COMPARABLE)).isNull();//a default value must be returned | ||
} | ||
|
||
/** | ||
* Should not throw an {@link ClassCastException} | ||
*/ | ||
@Test | ||
public void compareToNull() { | ||
final IMethods mock = mock(IMethods.class); | ||
|
||
when(mock.forInteger(leq((Integer)null))).thenReturn(""); | ||
|
||
assertThat(mock.forInteger(null)).isNull();//a default value must be returned | ||
} | ||
|
||
/** | ||
* Should not throw an {@link ClassCastException} | ||
*/ | ||
@Test | ||
public void compareToStringVsInt() { | ||
final IMethods mock = mock(IMethods.class); | ||
|
||
when(mock.forObject(Mockito.startsWith("Hello"))).thenReturn("x"); | ||
|
||
assertThat(mock.forObject(123)).isNull();//a default value must be returned | ||
} | ||
|
||
} |