View Javadoc
1   /*
2    * SPDX-FileCopyrightText: Copyright (c) 2013-2025 Yegor Bugayenko
3    * SPDX-License-Identifier: MIT
4    */
5   package com.jcabi.github;
6   
7   import com.jcabi.http.Request;
8   import com.jcabi.http.mock.MkAnswer;
9   import com.jcabi.http.mock.MkContainer;
10  import com.jcabi.http.mock.MkGrizzlyContainer;
11  import com.jcabi.http.request.ApacheRequest;
12  import java.io.IOException;
13  import java.net.HttpURLConnection;
14  import org.hamcrest.MatcherAssert;
15  import org.hamcrest.Matchers;
16  import org.junit.jupiter.api.Test;
17  import org.junit.jupiter.api.extension.ExtendWith;
18  import org.mockito.Mockito;
19  
20  /**
21   * Test case for {@link RtMilestones}.
22   * @since 0.1
23   */
24  @ExtendWith(RandomPort.class)
25  final class RtMilestonesTest {
26  
27      /**
28       * The rule for skipping test if there's BindException.
29       * @checkstyle VisibilityModifierCheck (3 lines)
30       */
31      @Test
32      void deleteMilestone() throws IOException {
33          try (
34              MkContainer container = new MkGrizzlyContainer().next(
35                  new MkAnswer.Simple(HttpURLConnection.HTTP_NO_CONTENT, "")
36              ).start(RandomPort.port())
37          ) {
38              final RtMilestones milestones = new RtMilestones(
39                  new ApacheRequest(container.home()),
40                  RtMilestonesTest.repo()
41              );
42              milestones.remove(1);
43              MatcherAssert.assertThat(
44                  "Values are not equal",
45                  container.take().method(),
46                  Matchers.equalTo(Request.DELETE)
47              );
48              container.stop();
49          }
50      }
51  
52      /**
53       * Create and return repo to test.
54       * @return Repo
55       */
56      private static Repo repo() {
57          final Repo repo = Mockito.mock(Repo.class);
58          Mockito.doReturn(new Coordinates.Simple("mark", "test"))
59              .when(repo).coordinates();
60          return repo;
61      }
62  }