Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Andrey Kozel
committed
Jan 26, 2022
1 parent
d86cb6b
commit 0e0e577
Showing
5 changed files
with
117 additions
and
44 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
87 changes: 87 additions & 0 deletions
87
src/test/java/org/mockito/internal/stubbing/answers/InvocationInfoExceptionTest.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,87 @@ | ||
/* | ||
* Copyright (c) 2022 Mockito contributors | ||
* This program is made available under the terms of the MIT License. | ||
*/ | ||
package org.mockito.internal.stubbing.answers; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.Parameterized; | ||
import org.mockito.internal.invocation.InvocationBuilder; | ||
import org.mockito.invocation.Invocation; | ||
|
||
import java.nio.charset.CharacterCodingException; | ||
import java.util.Arrays; | ||
import java.util.Collection; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
@RunWith(Parameterized.class) | ||
public class InvocationInfoExceptionTest { | ||
|
||
private final String methodName; | ||
|
||
public InvocationInfoExceptionTest(final String methodName) { | ||
this.methodName = methodName; | ||
} | ||
|
||
@Parameterized.Parameters | ||
public static Collection<Object[]> data() { | ||
return Arrays.asList( | ||
new Object[][] { | ||
{"throwException"}, | ||
{"parentThrowsException"}, | ||
{"grandParentThrowsException"}, | ||
{"interfaceThrowsException"}, | ||
{"grandInterfaceThrowsException"}, | ||
}); | ||
} | ||
|
||
@Test | ||
public void should_know_valid_throwables() throws Exception { | ||
// when | ||
Invocation invocation = | ||
new InvocationBuilder() | ||
.method(methodName) | ||
.mockClass(CurrentClass.class) | ||
.toInvocation(); | ||
InvocationInfo info = new InvocationInfo(invocation); | ||
|
||
// then | ||
assertThat(info.isValidException(new Exception())).isFalse(); | ||
assertThat(info.isValidException(new CharacterCodingException())).isTrue(); | ||
} | ||
|
||
private abstract static class GrandParent { | ||
public abstract void grandParentThrowsException() throws CharacterCodingException; | ||
} | ||
|
||
private abstract static class Parent extends GrandParent { | ||
public abstract void parentThrowsException() throws CharacterCodingException; | ||
} | ||
|
||
private interface GrandInterface { | ||
void grandInterfaceThrowsException() throws CharacterCodingException; | ||
} | ||
|
||
private interface Interface extends GrandInterface { | ||
void interfaceThrowsException() throws CharacterCodingException; | ||
} | ||
|
||
private abstract static class CurrentClass extends Parent implements Interface { | ||
|
||
public void throwException() throws CharacterCodingException {} | ||
|
||
@Override | ||
public void grandParentThrowsException() {} | ||
|
||
@Override | ||
public void parentThrowsException() {} | ||
|
||
@Override | ||
public void grandInterfaceThrowsException() {} | ||
|
||
@Override | ||
public void interfaceThrowsException() {} | ||
} | ||
} |
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