-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mockenum doesn't throw what expected
- Loading branch information
tuyucheng
committed
Jan 22, 2025
1 parent
a59de0f
commit 66bac9a
Showing
3 changed files
with
24 additions
and
25 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,9 +2,8 @@ | |
|
||
public enum Direction { | ||
|
||
NORTH, | ||
EAST, | ||
SOUTH, | ||
WEST; | ||
|
||
} | ||
NORTH, | ||
EAST, | ||
SOUTH, | ||
WEST; | ||
} |
36 changes: 18 additions & 18 deletions
36
...ockito-3/src/test/java/cn/tuyucheng/taketoday/mockito/mockenum/DirectionUtilUnitTest.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 |
---|---|---|
@@ -1,30 +1,30 @@ | ||
package cn.tuyucheng.taketoday.mockito.mockenum; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.mockito.MockedStatic; | ||
import org.mockito.Mockito; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
class DirectionUtilUnitTest { | ||
|
||
@Test | ||
void givenMockedDirection_whenGetDescription_thenThrowException() { | ||
try (MockedStatic<Direction> enumMock = Mockito.mockStatic(Direction.class)) { | ||
final Direction unsupported = Mockito.mock(Direction.class); | ||
Mockito.doReturn(4) | ||
.when(unsupported) | ||
.ordinal(); | ||
@Test | ||
void givenMockedDirection_whenGetDescription_thenThrowException() { | ||
try (MockedStatic<Direction> directionMock = Mockito.mockStatic(Direction.class)) { | ||
final Direction unsupported = Mockito.mock(Direction.class); | ||
Mockito.doReturn(4) | ||
.when(unsupported) | ||
.ordinal(); | ||
|
||
enumMock.when(Direction::values) | ||
.thenReturn(new Direction[] { Direction.NORTH, Direction.EAST, Direction.SOUTH, Direction.WEST, unsupported }); | ||
directionMock.when(Direction::values) | ||
.thenReturn(new Direction[]{Direction.NORTH, Direction.EAST, Direction.SOUTH, Direction.WEST, unsupported}); | ||
|
||
assertThrows(IllegalArgumentException.class, () -> DirectionUtils.getDescription(unsupported)); | ||
} | ||
} | ||
assertThrows(IllegalArgumentException.class, () -> DirectionUtils.getDescription(unsupported)); | ||
} | ||
} | ||
|
||
@Test | ||
void givenUnknownDirection_whenGetDescription_thenThrowException() { | ||
assertThrows(IllegalArgumentException.class, () -> DirectionUtils.getDescription(Direction.UNKNOWN)); | ||
} | ||
@Test | ||
void givenUnknownDirection_whenGetDescription_thenThrowException() { | ||
assertThrows(IllegalArgumentException.class, () -> DirectionUtils.getDescription(Direction.UNKNOWN)); | ||
} | ||
} |