File tree Expand file tree Collapse file tree 2 files changed +42
-0
lines changed
src/test/java/io/mincongh/mockito/init Expand file tree Collapse file tree 2 files changed +42
-0
lines changed Original file line number Diff line number Diff line change 3333 <artifactId >mockito-junit-jupiter</artifactId >
3434 <scope >test</scope >
3535 </dependency >
36+ <dependency >
37+ <groupId >org.assertj</groupId >
38+ <artifactId >assertj-core</artifactId >
39+ </dependency >
3640 </dependencies >
3741
3842</project >
Original file line number Diff line number Diff line change 1+ package io .mincongh .mockito .init ;
2+
3+ import static org .assertj .core .api .Assertions .assertThat ;
4+ import static org .mockito .Mockito .mock ;
5+ import static org .mockito .Mockito .when ;
6+
7+ import java .util .Map ;
8+ import java .util .Optional ;
9+ import org .junit .jupiter .api .Test ;
10+ import org .junit .jupiter .api .extension .ExtendWith ;
11+ import org .mockito .junit .jupiter .MockitoExtension ;
12+
13+ @ ExtendWith (MockitoExtension .class )
14+ public class ArgumentMatchTest {
15+ static class UserRegistry {
16+ private final Map <String , String > users ;
17+
18+ public UserRegistry (Map <String , String > users ) {
19+ this .users = users ;
20+ }
21+
22+ Optional <String > getUser (String userId ) {
23+ return Optional .ofNullable (users .get (userId ));
24+ }
25+ }
26+
27+ @ Test
28+ void getUser () {
29+ var registry = mock (UserRegistry .class );
30+ when (registry .getUser ("user1" )).thenReturn (Optional .of ("User One" ));
31+ when (registry .getUser ("user2" )).thenReturn (Optional .of ("User Two" ));
32+ when (registry .getUser ("user3" )).thenReturn (Optional .empty ());
33+
34+ assertThat (registry .getUser ("user1" )).hasValue ("User One" );
35+ assertThat (registry .getUser ("user2" )).hasValue ("User Two" );
36+ assertThat (registry .getUser ("user3" )).isEmpty ();
37+ }
38+ }
You can’t perform that action at this time.
0 commit comments