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
.files
;
10 import org
.junit
.jupiter
.api
.BeforeEach
;
11 import org
.junit
.jupiter
.api
.DisplayName
;
12 import org
.junit
.jupiter
.api
.Test
;
13 import wtf
.metio
.yosql
.codegen
.logging
.LoggingObjectMother
;
14 import wtf
.metio
.yosql
.codegen
.orchestration
.ExecutionErrors
;
15 import wtf
.metio
.yosql
.codegen
.orchestration
.OrchestrationObjectMother
;
16 import wtf
.metio
.yosql
.models
.configuration
.SqlStatementType
;
17 import wtf
.metio
.yosql
.models
.immutables
.SqlConfiguration
;
18 import wtf
.metio
.yosql
.testing
.configs
.RepositoriesConfigurations
;
20 import java
.nio
.file
.Paths
;
22 import static org
.junit
.jupiter
.api
.Assertions
.assertFalse
;
23 import static org
.junit
.jupiter
.api
.Assertions
.assertTrue
;
25 @DisplayName("DefaultMethodNameValidator")
26 class DefaultMethodNameValidatorTest
{
28 private DefaultMethodNameValidator validator
;
29 private ExecutionErrors errors
;
33 errors
= OrchestrationObjectMother
.executionErrors();
34 validator
= new DefaultMethodNameValidator(RepositoriesConfigurations
.validatingMethodNames(), errors
, LoggingObjectMother
.messages());
38 void detectInvalidReadPrefix() {
39 final var configuration
= SqlConfiguration
.usingDefaults()
40 .setType(SqlStatementType
.READING
)
41 .setName("updateSomeData")
43 final var source
= Paths
.get("some.sql");
44 validator
.validateNames(configuration
, source
);
45 assertTrue(errors
.hasErrors());
49 void detectInvalidWritePrefix() {
50 final var configuration
= SqlConfiguration
.usingDefaults()
51 .setType(SqlStatementType
.WRITING
)
52 .setName("findSomeData")
54 final var source
= Paths
.get("some.sql");
55 validator
.validateNames(configuration
, source
);
56 assertTrue(errors
.hasErrors());
60 void detectInvalidCallPrefix() {
61 final var configuration
= SqlConfiguration
.usingDefaults()
62 .setType(SqlStatementType
.CALLING
)
63 .setName("findSomeData")
65 final var source
= Paths
.get("some.sql");
66 validator
.validateNames(configuration
, source
);
67 assertTrue(errors
.hasErrors());
71 void acceptValidReadPrefix() {
72 final var configuration
= SqlConfiguration
.usingDefaults()
73 .setType(SqlStatementType
.READING
)
74 .setName("findSomeData")
76 final var source
= Paths
.get("some.sql");
77 validator
.validateNames(configuration
, source
);
78 assertFalse(errors
.hasErrors());
82 void acceptValidWritePrefix() {
83 final var configuration
= SqlConfiguration
.usingDefaults()
84 .setType(SqlStatementType
.WRITING
)
85 .setName("writeSomeData")
87 final var source
= Paths
.get("some.sql");
88 validator
.validateNames(configuration
, source
);
89 assertFalse(errors
.hasErrors());
93 void acceptValidCallPrefix() {
94 final var configuration
= SqlConfiguration
.usingDefaults()
95 .setType(SqlStatementType
.CALLING
)
96 .setName("callSomeProcedure")
98 final var source
= Paths
.get("some.sql");
99 validator
.validateNames(configuration
, source
);
100 assertFalse(errors
.hasErrors());