|
| 1 | +package org.gitlab4j.api; |
| 2 | + |
| 3 | +import static org.gitlab4j.api.JsonUtils.compareJson; |
| 4 | +import static org.junit.jupiter.api.Assertions.assertNotNull; |
| 5 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
| 6 | +import static org.mockito.ArgumentMatchers.any; |
| 7 | +import static org.mockito.Mockito.when; |
| 8 | +import static org.mockito.MockitoAnnotations.openMocks; |
| 9 | + |
| 10 | +import java.io.IOException; |
| 11 | + |
| 12 | +import javax.ws.rs.core.MultivaluedMap; |
| 13 | + |
| 14 | +import org.gitlab4j.api.models.Commit; |
| 15 | +import org.junit.jupiter.api.BeforeEach; |
| 16 | +import org.junit.jupiter.api.Test; |
| 17 | +import org.mockito.ArgumentCaptor; |
| 18 | +import org.mockito.Captor; |
| 19 | +import org.mockito.Mock; |
| 20 | +import org.mockito.Mockito; |
| 21 | + |
| 22 | +public class TestRepositorySubmodulesApi implements Constants { |
| 23 | + |
| 24 | + @Mock private GitLabApi gitLabApi; |
| 25 | + @Mock private GitLabApiClient gitLabApiClient; |
| 26 | + @Captor private ArgumentCaptor<MultivaluedMap<String, String>> attributeCaptor; |
| 27 | + private MockResponse response; |
| 28 | + |
| 29 | + @BeforeEach |
| 30 | + public void setUp() throws Exception { |
| 31 | + openMocks(this); |
| 32 | + } |
| 33 | + |
| 34 | + @Test |
| 35 | + public void testUpdateExistingSubmoduleReference() throws Exception { |
| 36 | + init(); |
| 37 | + Commit result = new RepositorySubmodulesApi(gitLabApi).updateExistingSubmoduleReference(6L, "my-sub", "patch-1", "33e2ee8579fda5bc36accc9c6fbd0b4fefda9e30", "message"); |
| 38 | + assertNotNull(result); |
| 39 | + assertTrue(compareJson(result, "commit.json")); |
| 40 | + } |
| 41 | + |
| 42 | + private void init() throws Exception, IOException { |
| 43 | + response = new MockResponse(Commit.class, "commit.json", null); |
| 44 | + when(gitLabApi.getApiClient()).thenReturn(gitLabApiClient); |
| 45 | + when(gitLabApiClient.validateSecretToken(any())).thenReturn(true); |
| 46 | + when(gitLabApiClient.put(attributeCaptor.capture(), Mockito.<Object>any())).thenReturn(response); |
| 47 | + } |
| 48 | +} |
0 commit comments