View Javadoc
1   /*
2    * SPDX-FileCopyrightText: Copyright (c) 2012-2026 Yegor Bugayenko
3    * SPDX-License-Identifier: MIT
4    */
5   package com.jcabi.dynamo.retry;
6   
7   import com.jcabi.dynamo.Credentials;
8   import com.jcabi.dynamo.Dosage;
9   import com.jcabi.dynamo.Valve;
10  import java.util.Collection;
11  import java.util.Collections;
12  import java.util.Map;
13  import org.hamcrest.MatcherAssert;
14  import org.hamcrest.Matchers;
15  import org.junit.jupiter.api.Test;
16  import software.amazon.awssdk.services.dynamodb.model.Condition;
17  
18  /**
19   * Test case for {@link ReValve}.
20   * @since 0.9
21   */
22  final class ReValveTest {
23  
24      @Test
25      void delegatesFetchAndWrapsInReDosage() throws Exception {
26          MatcherAssert.assertThat(
27              "does not wrap fetch result in ReDosage",
28              new ReValve(
29                  new Valve() {
30                      @Override
31                      public Dosage fetch(
32                          final Credentials credentials,
33                          final String table,
34                          final Map<String, Condition> conditions,
35                          final Collection<String> keys) {
36                          return new Dosage.Empty();
37                      }
38  
39                      @Override
40                      public int count(
41                          final Credentials credentials,
42                          final String table,
43                          final Map<String, Condition> conditions) {
44                          return 0;
45                      }
46                  }
47              ).fetch(
48                  Credentials.TEST,
49                  "t\u00e9st",
50                  Collections.emptyMap(),
51                  Collections.emptyList()
52              ),
53              Matchers.instanceOf(ReDosage.class)
54          );
55      }
56  
57      @Test
58      void delegatesCountToOrigin() throws Exception {
59          MatcherAssert.assertThat(
60              "does not delegate count to origin valve",
61              new ReValve(
62                  new Valve() {
63                      @Override
64                      public Dosage fetch(
65                          final Credentials credentials,
66                          final String table,
67                          final Map<String, Condition> conditions,
68                          final Collection<String> keys) {
69                          return new Dosage.Empty();
70                      }
71  
72                      @Override
73                      public int count(
74                          final Credentials credentials,
75                          final String table,
76                          final Map<String, Condition> conditions) {
77                          return 42;
78                      }
79                  }
80              ).count(
81                  Credentials.TEST,
82                  "t\u00e9st",
83                  Collections.emptyMap()
84              ),
85              Matchers.equalTo(42)
86          );
87      }
88  }