1
2
3
4
5 package com.jcabi.dynamo;
6
7 import java.io.IOException;
8 import java.util.Collections;
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 import software.amazon.awssdk.services.dynamodb.model.Condition;
15
16
17
18
19
20 final class AwsFrameTest {
21
22 @Test
23 void returnsAssociatedTable() {
24 final AwsTable table = Mockito.mock(AwsTable.class);
25 MatcherAssert.assertThat(
26 "did not return associated table",
27 new AwsFrame(
28 Mockito.mock(Credentials.class), table, "t\u00e4bl"
29 ).table(),
30 Matchers.equalTo(table)
31 );
32 }
33
34 @Test
35 void createsFrameWithStringCondition() {
36 MatcherAssert.assertThat(
37 "did not create frame with string condition",
38 new AwsFrame(
39 Mockito.mock(Credentials.class),
40 Mockito.mock(AwsTable.class),
41 "str\u00efng-tbl"
42 ).where("n\u00e4me", "v\u00e4lue"),
43 Matchers.instanceOf(Frame.class)
44 );
45 }
46
47 @Test
48 void createsFrameWithCondition() {
49 MatcherAssert.assertThat(
50 "did not create frame with condition",
51 new AwsFrame(
52 Mockito.mock(Credentials.class),
53 Mockito.mock(AwsTable.class),
54 "c\u00f6nd-tbl"
55 ).where("n\u00e4me", Condition.builder().build()),
56 Matchers.instanceOf(Frame.class)
57 );
58 }
59
60 @Test
61 void createsFrameWithMapOfConditions() {
62 MatcherAssert.assertThat(
63 "did not create frame with map of conditions",
64 new AwsFrame(
65 Mockito.mock(Credentials.class),
66 Mockito.mock(AwsTable.class),
67 "m\u00e4p-tbl"
68 ).where(
69 Collections.singletonMap(
70 "\u00e4ttr", Condition.builder().build()
71 )
72 ),
73 Matchers.instanceOf(Frame.class)
74 );
75 }
76
77 @Test
78 void changesValveViaThrough() {
79 MatcherAssert.assertThat(
80 "did not create frame with different valve",
81 new AwsFrame(
82 Mockito.mock(Credentials.class),
83 Mockito.mock(AwsTable.class),
84 "fl\u00f6w-tbl"
85 ).through(Mockito.mock(Valve.class)),
86 Matchers.instanceOf(Frame.class)
87 );
88 }
89
90 @Test
91 void delegatesSizeToValve() throws IOException {
92 final Valve valve = Mockito.mock(Valve.class);
93 final int expected = 42;
94 Mockito.doReturn(expected).when(valve)
95 .count(Mockito.any(), Mockito.anyString(), Mockito.any());
96 MatcherAssert.assertThat(
97 "did not delegate size to valve",
98 new AwsFrame(
99 Mockito.mock(Credentials.class),
100 Mockito.mock(AwsTable.class),
101 "s\u00efze-tbl", new Conditions(), valve
102 ).size(),
103 Matchers.equalTo(expected)
104 );
105 }
106
107 @Test
108 void wrapsExceptionOnSize() {
109 Assertions.assertThrows(
110 IllegalStateException.class,
111 () -> {
112 final Valve valve = Mockito.mock(Valve.class);
113 Mockito.doThrow(new IOException("b\u00f6om"))
114 .when(valve).count(
115 Mockito.any(),
116 Mockito.anyString(),
117 Mockito.any()
118 );
119 new AwsFrame(
120 Mockito.mock(Credentials.class),
121 Mockito.mock(AwsTable.class),
122 "wr\u00e4p-tbl", new Conditions(), valve
123 ).size();
124 }
125 );
126 }
127
128 }