Skip to content

Commit 54a1068

Browse files
committed
Coverage
1 parent 06cfcdd commit 54a1068

File tree

2 files changed

+59
-5
lines changed

2 files changed

+59
-5
lines changed

src/main/java/org/mybatis/dynamic/sql/select/HavingDSL.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,10 @@
2020
import org.mybatis.dynamic.sql.util.Buildable;
2121

2222
public class HavingDSL extends AbstractHavingStarter<HavingDSL.StandaloneHavingFinisher> {
23-
private StandaloneHavingFinisher havingFinisher;
23+
private final StandaloneHavingFinisher havingFinisher = new StandaloneHavingFinisher();
2424

2525
@Override
2626
protected StandaloneHavingFinisher having() {
27-
if (havingFinisher == null) {
28-
havingFinisher = new StandaloneHavingFinisher();
29-
}
30-
3127
return havingFinisher;
3228
}
3329

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright 2016-2023 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.mybatis.dynamic.sql.select;
17+
18+
import static org.assertj.core.api.Assertions.assertThat;
19+
import static org.mybatis.dynamic.sql.SqlBuilder.*;
20+
21+
import java.sql.JDBCType;
22+
import java.util.Optional;
23+
import java.util.concurrent.atomic.AtomicInteger;
24+
25+
import org.junit.jupiter.api.Test;
26+
import org.mybatis.dynamic.sql.SqlColumn;
27+
import org.mybatis.dynamic.sql.SqlTable;
28+
import org.mybatis.dynamic.sql.render.RenderingStrategies;
29+
import org.mybatis.dynamic.sql.render.TableAliasCalculator;
30+
import org.mybatis.dynamic.sql.select.render.HavingRenderer;
31+
import org.mybatis.dynamic.sql.util.FragmentAndParameters;
32+
33+
class HavingModelTest {
34+
@Test
35+
void testNormalHaving() {
36+
SqlTable table = SqlTable.of("foo");
37+
SqlColumn<Integer> id = table.column("id", JDBCType.INTEGER);
38+
39+
HavingModel model = having(id, isLessThan(4))
40+
.or(id, isGreaterThan(14))
41+
.build();
42+
43+
Optional<FragmentAndParameters> havingClause = renderHavingModel(model);
44+
45+
assertThat(havingClause).hasValueSatisfying(hc ->
46+
assertThat(hc.fragment()).isEqualTo("having id < :p1 or id > :p2")
47+
);
48+
}
49+
50+
private Optional<FragmentAndParameters> renderHavingModel(HavingModel havingModel) {
51+
return HavingRenderer.withHavingModel(havingModel)
52+
.withRenderingStrategy(RenderingStrategies.SPRING_NAMED_PARAMETER)
53+
.withSequence(new AtomicInteger(1))
54+
.withTableAliasCalculator(TableAliasCalculator.empty())
55+
.build()
56+
.render();
57+
}
58+
}

0 commit comments

Comments
 (0)