fix #123 allow to specify extra annotations on repositories/methods
[yosql.git] / yosql-codegen / src / test / java / wtf / metio / yosql / codegen / blocks / DefaultVariablesTest.java
blob7f4aa6b6cbe6229383c48d3d7fe71329b5925bcd
1 /*
2 * This file is part of yosql. It is subject to the license terms in the LICENSE file found in the top-level
3 * directory of this distribution and at https://creativecommons.org/publicdomain/zero/1.0/. No part of yosql,
4 * including this file, may be copied, modified, propagated, or distributed except according to the terms contained
5 * in the LICENSE file.
6 */
8 package wtf.metio.yosql.codegen.blocks;
10 import org.junit.jupiter.api.Assertions;
11 import org.junit.jupiter.api.DisplayName;
12 import org.junit.jupiter.api.Nested;
13 import org.junit.jupiter.api.Test;
14 import wtf.metio.yosql.testing.configs.JavaConfigurations;
16 @DisplayName("DefaultVariables")
17 class DefaultVariablesTest {
19 @Nested
20 @DisplayName("using default configuration")
21 class JavaDefaultsTest {
23 @Test
24 @DisplayName("creates variables")
25 void shouldCreateVariable() {
26 // given
27 final var variables = new DefaultVariables(JavaConfigurations.defaults());
29 // when
30 final var variable = variables.inline(String.class, "test");
32 // then
33 Assertions.assertEquals("""
34 final java.lang.String test""", variable.toString());
37 @Test
38 @DisplayName("creates variables with initializer")
39 void shouldCreateVariableWithInitializer() {
40 // given
41 final var variables = new DefaultVariables(JavaConfigurations.defaults());
43 // when
44 final var variable = variables.inline(String.class, "test", CodeBlocks.code("$S", "hello world"));
46 // then
47 Assertions.assertEquals("""
48 final var test = "hello world" """, variable.toString());
51 @Test
52 @DisplayName("creates variable statements")
53 void shouldCreateVariableStatement() {
54 // given
55 final var variables = new DefaultVariables(JavaConfigurations.defaults());
57 // when
58 final var variable = variables.statement(String.class, "test", CodeBlocks.code("$S", "hello world"));
60 // then
61 Assertions.assertEquals("""
62 final var test = "hello world";
63 """, variable.toString());
68 @Nested
69 @DisplayName("using Java 8 configuration")
70 class Java8Test {
72 @Test
73 @DisplayName("creates variables")
74 void shouldCreateVariable() {
75 // given
76 final var variables = new DefaultVariables(JavaConfigurations.java8());
78 // when
79 final var variable = variables.inline(String.class, "test");
81 // then
82 Assertions.assertEquals("""
83 final java.lang.String test""", variable.toString());
86 @Test
87 @DisplayName("creates variables with initializer")
88 void shouldCreateVariableWithInitializer() {
89 // given
90 final var variables = new DefaultVariables(JavaConfigurations.java8());
92 // when
93 final var variable = variables.inline(String.class, "test", CodeBlocks.code("$S", "hello world"));
95 // then
96 Assertions.assertEquals("""
97 final java.lang.String test = "hello world" """, variable.toString());
100 @Test
101 @DisplayName("creates variable statements")
102 void shouldCreateVariableStatement() {
103 // given
104 final var variables = new DefaultVariables(JavaConfigurations.java8());
106 // when
107 final var variable = variables.statement(String.class, "test", CodeBlocks.code("$S", "hello world"));
109 // then
110 Assertions.assertEquals("""
111 final java.lang.String test = "hello world";
112 """, variable.toString());
117 @Nested
118 @DisplayName("using Java 9 configuration")
119 class Java9Test {
121 @Test
122 @DisplayName("creates variables")
123 void shouldCreateVariable() {
124 // given
125 final var variables = new DefaultVariables(JavaConfigurations.java9());
127 // when
128 final var variable = variables.inline(String.class, "test");
130 // then
131 Assertions.assertEquals("""
132 final java.lang.String test""", variable.toString());
135 @Test
136 @DisplayName("creates variables with initializer")
137 void shouldCreateVariableWithInitializer() {
138 // given
139 final var variables = new DefaultVariables(JavaConfigurations.java9());
141 // when
142 final var variable = variables.inline(String.class, "test", CodeBlocks.code("$S", "hello world"));
144 // then
145 Assertions.assertEquals("""
146 final java.lang.String test = "hello world" """, variable.toString());
149 @Test
150 @DisplayName("creates variable statements")
151 void shouldCreateVariableStatement() {
152 // given
153 final var variables = new DefaultVariables(JavaConfigurations.java9());
155 // when
156 final var variable = variables.statement(String.class, "test", CodeBlocks.code("$S", "hello world"));
158 // then
159 Assertions.assertEquals("""
160 final java.lang.String test = "hello world";
161 """, variable.toString());
166 @Nested
167 @DisplayName("using Java 11 configuration")
168 class Java11Test {
170 @Test
171 @DisplayName("creates variables")
172 void shouldCreateVariable() {
173 // given
174 final var variables = new DefaultVariables(JavaConfigurations.java11());
176 // when
177 final var variable = variables.inline(String.class, "test");
179 // then
180 Assertions.assertEquals("""
181 final java.lang.String test""", variable.toString());
184 @Test
185 @DisplayName("creates variables with initializer")
186 void shouldCreateVariableWithInitializer() {
187 // given
188 final var variables = new DefaultVariables(JavaConfigurations.java11());
190 // when
191 final var variable = variables.inline(String.class, "test", CodeBlocks.code("$S", "hello world"));
193 // then
194 Assertions.assertEquals("""
195 final var test = "hello world" """, variable.toString());
198 @Test
199 @DisplayName("creates variable statements")
200 void shouldCreateVariableStatement() {
201 // given
202 final var variables = new DefaultVariables(JavaConfigurations.java11());
204 // when
205 final var variable = variables.statement(String.class, "test", CodeBlocks.code("$S", "hello world"));
207 // then
208 Assertions.assertEquals("""
209 final var test = "hello world";
210 """, variable.toString());
215 @Nested
216 @DisplayName("using Java 14 configuration")
217 class Java14Test {
219 @Test
220 @DisplayName("creates variables")
221 void shouldCreateVariable() {
222 // given
223 final var variables = new DefaultVariables(JavaConfigurations.java14());
225 // when
226 final var variable = variables.inline(String.class, "test");
228 // then
229 Assertions.assertEquals("""
230 final java.lang.String test""", variable.toString());
233 @Test
234 @DisplayName("creates variables with initializer")
235 void shouldCreateVariableWithInitializer() {
236 // given
237 final var variables = new DefaultVariables(JavaConfigurations.java14());
239 // when
240 final var variable = variables.inline(String.class, "test", CodeBlocks.code("$S", "hello world"));
242 // then
243 Assertions.assertEquals("""
244 final var test = "hello world" """, variable.toString());
247 @Test
248 @DisplayName("creates variable statements")
249 void shouldCreateVariableStatement() {
250 // given
251 final var variables = new DefaultVariables(JavaConfigurations.java14());
253 // when
254 final var variable = variables.statement(String.class, "test", CodeBlocks.code("$S", "hello world"));
256 // then
257 Assertions.assertEquals("""
258 final var test = "hello world";
259 """, variable.toString());
264 @Nested
265 @DisplayName("using Java 16 configuration")
266 class Java16Test {
268 @Test
269 @DisplayName("creates variables")
270 void shouldCreateVariable() {
271 // given
272 final var variables = new DefaultVariables(JavaConfigurations.java16());
274 // when
275 final var variable = variables.inline(String.class, "test");
277 // then
278 Assertions.assertEquals("""
279 final java.lang.String test""", variable.toString());
282 @Test
283 @DisplayName("creates variables with initializer")
284 void shouldCreateVariableWithInitializer() {
285 // given
286 final var variables = new DefaultVariables(JavaConfigurations.java16());
288 // when
289 final var variable = variables.inline(String.class, "test", CodeBlocks.code("$S", "hello world"));
291 // then
292 Assertions.assertEquals("""
293 final var test = "hello world" """, variable.toString());
296 @Test
297 @DisplayName("creates variable statements")
298 void shouldCreateVariableStatement() {
299 // given
300 final var variables = new DefaultVariables(JavaConfigurations.java16());
302 // when
303 final var variable = variables.statement(String.class, "test", CodeBlocks.code("$S", "hello world"));
305 // then
306 Assertions.assertEquals("""
307 final var test = "hello world";
308 """, variable.toString());