Skip to content

Commit 6f483d8

Browse files
committed
Coverage for deprecated methods
1 parent 22d2aab commit 6f483d8

File tree

2 files changed

+142
-1
lines changed

2 files changed

+142
-1
lines changed
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
/*
2+
* Copyright 2016-2024 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;
17+
18+
import static org.assertj.core.api.Assertions.assertThat;
19+
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
20+
21+
import java.util.List;
22+
23+
import org.junit.jupiter.api.Test;
24+
import org.mybatis.dynamic.sql.common.OrderByModel;
25+
import org.mybatis.dynamic.sql.common.OrderByRenderer;
26+
import org.mybatis.dynamic.sql.configuration.StatementConfiguration;
27+
import org.mybatis.dynamic.sql.exception.DynamicSqlException;
28+
import org.mybatis.dynamic.sql.render.RenderingContext;
29+
import org.mybatis.dynamic.sql.render.RenderingStrategies;
30+
import org.mybatis.dynamic.sql.render.TableAliasCalculator;
31+
import org.mybatis.dynamic.sql.util.FragmentAndParameters;
32+
import org.mybatis.dynamic.sql.util.Messages;
33+
34+
class DeprecatedSortMethodsTest {
35+
36+
@Test
37+
void bothMethodsExist() {
38+
SortSpecification ss = new SortSpecification() {
39+
@Override
40+
public SortSpecification descending() {
41+
return this;
42+
}
43+
44+
@Override
45+
public String orderByName() {
46+
return "id";
47+
}
48+
49+
@Override
50+
public boolean isDescending() {
51+
return true;
52+
}
53+
};
54+
55+
OrderByModel model = OrderByModel.of(List.of(ss));
56+
57+
RenderingContext renderingContext = RenderingContext
58+
.withRenderingStrategy(RenderingStrategies.MYBATIS3)
59+
.withTableAliasCalculator(TableAliasCalculator.empty())
60+
.withStatementConfiguration(new StatementConfiguration())
61+
.build();
62+
OrderByRenderer renderer = new OrderByRenderer(renderingContext);
63+
FragmentAndParameters fp = renderer.render(model);
64+
assertThat(fp.fragment()).isEqualTo("order by id DESC");
65+
}
66+
67+
@Test
68+
void orderByNameMethodMissing() {
69+
SortSpecification ss = new SortSpecification() {
70+
@Override
71+
public SortSpecification descending() {
72+
return this;
73+
}
74+
75+
@Override
76+
public boolean isDescending() {
77+
return true;
78+
}
79+
};
80+
81+
OrderByModel model = OrderByModel.of(List.of(ss));
82+
83+
RenderingContext renderingContext = RenderingContext
84+
.withRenderingStrategy(RenderingStrategies.MYBATIS3)
85+
.withTableAliasCalculator(TableAliasCalculator.empty())
86+
.withStatementConfiguration(new StatementConfiguration())
87+
.build();
88+
OrderByRenderer renderer = new OrderByRenderer(renderingContext);
89+
assertThatExceptionOfType(DynamicSqlException.class)
90+
.isThrownBy(() -> renderer.render(model))
91+
.withMessage(Messages.getString("ERROR.44"));
92+
}
93+
94+
@Test
95+
void isDescendingMethodMissing() {
96+
SortSpecification ss = new SortSpecification() {
97+
@Override
98+
public SortSpecification descending() {
99+
return this;
100+
}
101+
102+
@Override
103+
public String orderByName() {
104+
return "id";
105+
}
106+
};
107+
108+
OrderByModel model = OrderByModel.of(List.of(ss));
109+
110+
RenderingContext renderingContext = RenderingContext
111+
.withRenderingStrategy(RenderingStrategies.MYBATIS3)
112+
.withTableAliasCalculator(TableAliasCalculator.empty())
113+
.withStatementConfiguration(new StatementConfiguration())
114+
.build();
115+
OrderByRenderer renderer = new OrderByRenderer(renderingContext);
116+
assertThatExceptionOfType(DynamicSqlException.class)
117+
.isThrownBy(() -> renderer.render(model))
118+
.withMessage(Messages.getString("ERROR.44"));
119+
}
120+
121+
@Test
122+
void bothMethodsMissing() {
123+
SortSpecification ss = new SortSpecification() {
124+
@Override
125+
public SortSpecification descending() {
126+
return this;
127+
}
128+
};
129+
130+
OrderByModel model = OrderByModel.of(List.of(ss));
131+
132+
RenderingContext renderingContext = RenderingContext
133+
.withRenderingStrategy(RenderingStrategies.MYBATIS3)
134+
.withTableAliasCalculator(TableAliasCalculator.empty())
135+
.withStatementConfiguration(new StatementConfiguration())
136+
.build();
137+
OrderByRenderer renderer = new OrderByRenderer(renderingContext);
138+
assertThatExceptionOfType(DynamicSqlException.class)
139+
.isThrownBy(() -> renderer.render(model))
140+
.withMessage(Messages.getString("ERROR.44"));
141+
}
142+
}

src/test/java/org/mybatis/dynamic/sql/InvalidSQLTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import static org.mybatis.dynamic.sql.SqlBuilder.update;
2323
import static org.mybatis.dynamic.sql.SqlBuilder.value;
2424

25-
import java.util.ArrayList;
2625
import java.util.Collections;
2726
import java.util.List;
2827
import java.util.MissingResourceException;

0 commit comments

Comments
 (0)