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
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
.models
.configuration
.Annotation
;
15 import wtf
.metio
.yosql
.models
.configuration
.AnnotationMember
;
16 import wtf
.metio
.yosql
.testing
.configs
.AnnotationsConfigurations
;
18 @DisplayName("DefaultAnnotations")
19 class DefaultAnnotationsTest
{
22 @DisplayName("Default Configuration")
26 @DisplayName("can annotate classes")
27 void shouldAnnotateClasses() {
29 final var generator
= new DefaultAnnotations(AnnotationsConfigurations
.defaults());
32 final var annotations
= generator
.generatedClass();
35 Assertions
.assertEquals("""
36 @javax.annotation.processing.Generated(value = "YoSQL
", comments = "DO NOT MODIFY
- automatically generated by YoSQL
")""",
37 annotations
.iterator().next().toString());
41 @DisplayName("can annotate fields")
42 void shouldAnnotateFields() {
44 final var generator
= new DefaultAnnotations(AnnotationsConfigurations
.defaults());
47 final var annotations
= generator
.generatedField();
50 Assertions
.assertEquals("""
51 @javax.annotation.processing.Generated(value = "YoSQL
", comments = "DO NOT MODIFY
- automatically generated by YoSQL
")""",
52 annotations
.iterator().next().toString());
56 @DisplayName("can annotate methods")
57 void shouldAnnotateMethods() {
59 final var generator
= new DefaultAnnotations(AnnotationsConfigurations
.defaults());
62 final var annotations
= generator
.generatedMethod();
65 Assertions
.assertEquals("""
66 @javax.annotation.processing.Generated(value = "YoSQL
", comments = "DO NOT MODIFY
- automatically generated by YoSQL
")""",
67 annotations
.iterator().next().toString());
73 @DisplayName("Custom Configuration")
77 @DisplayName("can use javax.annotation.processing.Generated")
78 void shouldUseProcessingApi() {
80 final var generator
= new DefaultAnnotations(AnnotationsConfigurations
.defaults());
83 final var annotations
= generator
.generatedClass();
86 Assertions
.assertEquals("""
87 @javax.annotation.processing.Generated(value = "YoSQL
", comments = "DO NOT MODIFY
- automatically generated by YoSQL
")""",
88 annotations
.iterator().next().toString());
92 @DisplayName("can use javax.annotation.Generated")
93 void shouldUseAnnotationApi() {
95 final var generator
= new DefaultAnnotations(AnnotationsConfigurations
.generated());
98 final var annotations
= generator
.generatedClass();
101 Assertions
.assertEquals("""
102 @javax.annotation.Generated(value = "YoSQL
", comments = "DO NOT MODIFY
- automatically generated by YoSQL
")""",
103 annotations
.iterator().next().toString());
109 void asAnnotationSpec() {
110 final var annotation
= Annotation
.builder().setType("com.example.Annotation").build();
111 final var spec
= DefaultAnnotations
.asAnnotationSpec(annotation
);
112 Assertions
.assertEquals("""
113 @com.example.Annotation""", spec
.toString());
117 void asAnnotationSpecWithMember() {
118 final var annotation
= Annotation
.builder()
119 .setType("com.example.Annotation")
120 .addMembers(AnnotationMember
.builder().setKey("value").setValue("test").build())
122 final var spec
= DefaultAnnotations
.asAnnotationSpec(annotation
);
123 Assertions
.assertEquals("""
124 @com.example.Annotation("test
")""", spec
.toString());
128 void asAnnotationSpecWithMemberUsingCustomKey() {
129 final var annotation
= Annotation
.builder()
130 .setType("com.example.Annotation")
131 .addMembers(AnnotationMember
.builder().setKey("random").setValue("test").build())
133 final var spec
= DefaultAnnotations
.asAnnotationSpec(annotation
);
134 Assertions
.assertEquals("""
135 @com.example.Annotation(random = "test
")""", spec
.toString());
139 void asAnnotationSpecWithMembers() {
140 final var annotation
= Annotation
.builder()
141 .setType("com.example.Annotation")
142 .addMembers(AnnotationMember
.builder().setKey("value").setValue("test").build())
143 .addMembers(AnnotationMember
.builder().setKey("another").setValue("value").build())
145 final var spec
= DefaultAnnotations
.asAnnotationSpec(annotation
);
146 Assertions
.assertEquals("""
147 @com.example.Annotation(value = "test
", another = "value
")""", spec
.toString());
151 void asAnnotationSpecWithMemberUsingBoolType() {
152 final var annotation
= Annotation
.builder()
153 .setType("com.example.Annotation")
154 .addMembers(AnnotationMember
.builder()
160 final var spec
= DefaultAnnotations
.asAnnotationSpec(annotation
);
161 Assertions
.assertEquals("""
162 @com.example.Annotation(test = true)""", spec
.toString());
166 void asAnnotationSpecWithMemberUsingIntType() {
167 final var annotation
= Annotation
.builder()
168 .setType("com.example.Annotation")
169 .addMembers(AnnotationMember
.builder()
175 final var spec
= DefaultAnnotations
.asAnnotationSpec(annotation
);
176 Assertions
.assertEquals("""
177 @com.example.Annotation(test = 123)""", spec
.toString());
181 void asAnnotationSpecWithMemberUsingLongType() {
182 final var annotation
= Annotation
.builder()
183 .setType("com.example.Annotation")
184 .addMembers(AnnotationMember
.builder()
190 final var spec
= DefaultAnnotations
.asAnnotationSpec(annotation
);
191 Assertions
.assertEquals("""
192 @com.example.Annotation(test = 456789)""", spec
.toString());
196 void asAnnotationSpecWithMemberUsingShortType() {
197 final var annotation
= Annotation
.builder()
198 .setType("com.example.Annotation")
199 .addMembers(AnnotationMember
.builder()
205 final var spec
= DefaultAnnotations
.asAnnotationSpec(annotation
);
206 Assertions
.assertEquals("""
207 @com.example.Annotation(test = 123)""", spec
.toString());
211 void asAnnotationSpecWithMemberUsingByteType() {
212 final var annotation
= Annotation
.builder()
213 .setType("com.example.Annotation")
214 .addMembers(AnnotationMember
.builder()
220 final var spec
= DefaultAnnotations
.asAnnotationSpec(annotation
);
221 Assertions
.assertEquals("""
222 @com.example.Annotation(test = 123)""", spec
.toString());
226 void asAnnotationSpecWithMemberUsingFloatType() {
227 final var annotation
= Annotation
.builder()
228 .setType("com.example.Annotation")
229 .addMembers(AnnotationMember
.builder()
235 final var spec
= DefaultAnnotations
.asAnnotationSpec(annotation
);
236 Assertions
.assertEquals("""
237 @com.example.Annotation(test = 3.14)""", spec
.toString());
241 void asAnnotationSpecWithMemberUsingDoubleType() {
242 final var annotation
= Annotation
.builder()
243 .setType("com.example.Annotation")
244 .addMembers(AnnotationMember
.builder()
250 final var spec
= DefaultAnnotations
.asAnnotationSpec(annotation
);
251 Assertions
.assertEquals("""
252 @com.example.Annotation(test = 3.14)""", spec
.toString());
256 void asAnnotationSpecWithMemberUsingCharType() {
257 final var annotation
= Annotation
.builder()
258 .setType("com.example.Annotation")
259 .addMembers(AnnotationMember
.builder()
265 final var spec
= DefaultAnnotations
.asAnnotationSpec(annotation
);
266 Assertions
.assertEquals("""
267 @com.example.Annotation(test = 'a')""", spec
.toString());