View Javadoc
1   /*
2    * SPDX-FileCopyrightText: Copyright (c) 2013-2025 Yegor Bugayenko
3    * SPDX-License-Identifier: MIT
4    */
5   package com.jcabi.github.mock;
6   
7   import com.jcabi.github.Check;
8   import com.jcabi.github.Pull;
9   import java.io.IOException;
10  import org.hamcrest.MatcherAssert;
11  import org.hamcrest.Matchers;
12  import org.junit.jupiter.api.BeforeEach;
13  import org.junit.jupiter.api.Test;
14  
15  /**
16   * Test case for {@link MkChecks}.
17   * @since 1.6.1
18   */
19  final class MkChecksTest {
20  
21      /**
22       * Pull request.
23       */
24      private transient Pull pull;
25  
26      /**
27       * Set up.
28       * @throws IOException If some problem with I/O.
29       */
30      @BeforeEach
31      void setUp() throws IOException {
32          this.pull = new MkGitHub()
33              .randomRepo()
34              .pulls()
35              .create("Test PR", "abcdef8", "abcdef9");
36      }
37  
38      /**
39       * MkChecks can return empty checks by default.
40       * @throws IOException If some problem with I/O.
41       */
42      @Test
43      void returnsEmptyChecksByDefault() throws IOException {
44          MatcherAssert.assertThat(
45              "Collection is not empty",
46              ((MkChecks) this.pull.checks()).all(),
47              Matchers.empty()
48          );
49      }
50  
51      /**
52       * MkChecks can create a check.
53       * @throws IOException If some problem with I/O.
54       */
55      @Test
56      void createsCheck() throws IOException {
57          final MkChecks checks = (MkChecks) this.pull.checks();
58          final Check check = checks.create(
59              Check.Status.COMPLETED,
60              Check.Conclusion.SUCCESS
61          );
62          MatcherAssert.assertThat(
63              "Collection size is incorrect",
64              checks.all(),
65              Matchers.hasSize(1)
66          );
67          final Check next = checks.all().iterator().next();
68          MatcherAssert.assertThat(
69              "Values are not equal",
70              check,
71              Matchers.equalTo(next)
72          );
73          MatcherAssert.assertThat(
74              "Values are not equal",
75              next.successful(),
76              Matchers.is(true)
77          );
78      }
79  }