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.google.common.base.Optional;
8   import com.jcabi.github.Event;
9   import com.jcabi.github.Label;
10  import com.jcabi.github.Repo;
11  import com.jcabi.github.Repos;
12  import java.io.IOException;
13  import org.hamcrest.MatcherAssert;
14  import org.hamcrest.Matchers;
15  import org.junit.jupiter.api.Test;
16  
17  /**
18   * Test case for {@link MkEvent}.
19   * @since 0.1
20   */
21  final class MkEventTest {
22      @Test
23      void canGetCreatedAt() throws IOException {
24          final MkStorage storage = new MkStorage.InFile();
25          final String user = "test_user";
26          final Repo repo = new MkGitHub(storage, user).randomRepo();
27          final MkIssueEvents events = (MkIssueEvents) repo.issueEvents();
28          final int eventnum = events.create(
29              "test_type",
30              1,
31              user,
32              Optional.of("test_label")
33          ).number();
34          MatcherAssert.assertThat(
35              "Value is null",
36              new MkEvent(
37                  storage,
38                  user,
39                  repo.coordinates(),
40                  eventnum
41              )
42                  .json().getString("created_at"),
43              Matchers.notNullValue()
44          );
45      }
46  
47      @Test
48      void canGetPresentLabel() throws IOException {
49          final MkStorage storage = new MkStorage.InFile();
50          final String user = "ken";
51          final Repo repo = new MkGitHub(storage, user).repos().create(
52              new Repos.RepoCreate("foo", false)
53          );
54          final MkIssueEvents events = (MkIssueEvents) repo.issueEvents();
55          final String label = "problem";
56          final int num = events.create(
57              Event.LABELED,
58              1,
59              user,
60              Optional.of(label)
61          ).number();
62          MatcherAssert.assertThat(
63              "Values are not equal",
64              new Event.Smart(
65                  new MkEvent(
66                      storage,
67                      user,
68                      repo.coordinates(),
69                      num
70                  )
71              ).label().get().name(),
72              Matchers.equalTo(label)
73          );
74      }
75  
76      @Test
77      void canGetAbsentLabel() throws IOException {
78          final MkStorage storage = new MkStorage.InFile();
79          final String user = "barbie";
80          final Repo repo = new MkGitHub(storage, user).repos().create(
81              new Repos.RepoCreate("bar", false)
82          );
83          final int num = ((MkIssueEvents) repo.issueEvents()).create(
84              Event.LABELED,
85              1,
86              user,
87              Optional.absent()
88          ).number();
89          MatcherAssert.assertThat(
90              "Values are not equal",
91              new Event.Smart(
92                  new MkEvent(
93                      storage,
94                      user,
95                      repo.coordinates(),
96                      num
97                  )
98              ).label(),
99              Matchers.equalTo(Optional.<Label>absent())
100         );
101     }
102 }