1
2
3
4
5 package com.jcabi.github;
6
7 import jakarta.json.Json;
8 import java.io.IOException;
9 import org.hamcrest.MatcherAssert;
10 import org.hamcrest.Matchers;
11 import org.junit.jupiter.api.Assertions;
12 import org.junit.jupiter.api.Test;
13 import org.mockito.Mockito;
14
15
16
17
18
19 final class ExistenceTest {
20
21 @Test
22 void jsonExists() throws IOException {
23 final JsonReadable object = Mockito.mock(JsonReadable.class);
24 Mockito.when(object.json()).thenReturn(
25 Json.createObjectBuilder().build()
26 );
27 MatcherAssert.assertThat(
28 "Values are not equal",
29 new Existence(object).check(),
30 Matchers.is(Boolean.TRUE)
31 );
32 }
33
34 @Test
35 void jsonDoesNotExist() throws IOException {
36 final JsonReadable object = Mockito.mock(JsonReadable.class);
37 Mockito.doThrow(new AssertionError()).when(object).json();
38 MatcherAssert.assertThat(
39 "Values are not equal",
40 new Existence(object).check(),
41 Matchers.is(Boolean.FALSE)
42 );
43 }
44
45 @Test
46 void rethrowsIoException() throws IOException {
47 final JsonReadable object = Mockito.mock(JsonReadable.class);
48 Mockito.doThrow(new IOException()).when(object).json();
49 Assertions.assertThrows(
50 IOException.class,
51 () -> new Existence(object).check(),
52 "Should rethrow IOException"
53 );
54 }
55
56 }