|
18 | 18 | import static org.assertj.core.api.Assertions.*;
|
19 | 19 | import static org.mockito.Mockito.*;
|
20 | 20 |
|
21 |
| -import org.junit.Ignore; |
22 | 21 | import org.junit.jupiter.api.Test;
|
23 | 22 | import org.junit.jupiter.api.extension.ExtendWith;
|
24 | 23 | import org.mockito.Mock;
|
25 | 24 | import org.mockito.junit.jupiter.MockitoExtension;
|
26 | 25 |
|
27 | 26 | import org.springframework.r2dbc.core.DatabaseClient;
|
28 | 27 | import org.springframework.r2dbc.core.PreparedOperation;
|
| 28 | +import org.springframework.r2dbc.core.binding.BindTarget; |
29 | 29 |
|
30 | 30 | /**
|
31 | 31 | * Unit tests for {@link PreparedOperationBindableQuery}.
|
|
34 | 34 | * @author Marl Paluch
|
35 | 35 | */
|
36 | 36 | @ExtendWith(MockitoExtension.class)
|
37 |
| -@Ignore |
38 | 37 | class PreparedOperationBindableQueryUnitTests {
|
39 | 38 |
|
40 | 39 | @Mock PreparedOperation<?> preparedOperation;
|
41 | 40 |
|
42 |
| - @Test // gh-282 |
| 41 | + @Test // gh-282, gh-587 |
43 | 42 | void bindsQueryParameterValues() {
|
44 | 43 |
|
45 |
| - DatabaseClient.GenericExecuteSpec bindSpecMock = mock(DatabaseClient.GenericExecuteSpec.class); |
| 44 | + DatabaseClient.GenericExecuteSpec bindSpecMock = mock(DatabaseClient.GenericExecuteSpec.class, RETURNS_SELF); |
| 45 | + |
| 46 | + doAnswer(it -> { |
| 47 | + |
| 48 | + BindTarget target = it.getArgument(0); |
| 49 | + |
| 50 | + target.bind(0, "hello"); |
| 51 | + target.bind("foo", "world"); |
| 52 | + target.bindNull(1, String.class); |
| 53 | + target.bindNull("bar", Integer.class); |
| 54 | + |
| 55 | + return null; |
| 56 | + }).when(preparedOperation).bindTo(any()); |
46 | 57 |
|
47 | 58 | PreparedOperationBindableQuery query = new PreparedOperationBindableQuery(preparedOperation);
|
48 |
| - query.bind(bindSpecMock); |
| 59 | + DatabaseClient.GenericExecuteSpec bind = query.bind(bindSpecMock); |
| 60 | + |
49 | 61 | verify(preparedOperation, times(1)).bindTo(any());
|
| 62 | + verify(bindSpecMock).bind(0, "hello"); |
| 63 | + verify(bindSpecMock).bind("foo", "world"); |
| 64 | + verify(bindSpecMock).bindNull(1, String.class); |
| 65 | + verify(bindSpecMock).bindNull("bar", Integer.class); |
50 | 66 | }
|
51 | 67 |
|
52 | 68 | @Test // gh-282
|
|
0 commit comments