Skip to content

Commit 2a681dc

Browse files
committed
Coverage
1 parent 2e42ae3 commit 2a681dc

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

src/test/java/examples/animal/data/AnimalDataTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1825,6 +1825,25 @@ void testAvg() {
18251825
}
18261826
}
18271827

1828+
@Test
1829+
void testDeprecatedAvg() {
1830+
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
1831+
GeneralMapper mapper = sqlSession.getMapper(GeneralMapper.class);
1832+
1833+
SelectStatementProvider selectStatement = select(DeprecatedAverage.of(brainWeight).as("average"))
1834+
.from(animalData, "a")
1835+
.build()
1836+
.render(RenderingStrategies.MYBATIS3);
1837+
1838+
Double average = mapper.selectOneDouble(selectStatement);
1839+
1840+
assertAll(
1841+
() -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select avg(a.brain_weight) as average from AnimalData a"),
1842+
() -> assertThat(average).isEqualTo(1852.69, within(.01))
1843+
);
1844+
}
1845+
}
1846+
18281847
@Test
18291848
void testSum() {
18301849
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright 2016-2020 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+
* http://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 examples.animal.data;
17+
18+
import org.mybatis.dynamic.sql.BasicColumn;
19+
import org.mybatis.dynamic.sql.select.aggregate.AbstractAggregate;
20+
21+
public class DeprecatedAverage extends AbstractAggregate<DeprecatedAverage> {
22+
private DeprecatedAverage(BasicColumn column) {
23+
super(column);
24+
}
25+
26+
@Override
27+
protected String render(String columnName) {
28+
return "avg(" + columnName + ")"; //$NON-NLS-1$ //$NON-NLS-2$
29+
}
30+
31+
@Override
32+
protected DeprecatedAverage copy() {
33+
return new DeprecatedAverage(column);
34+
}
35+
36+
public static DeprecatedAverage of(BasicColumn column) {
37+
return new DeprecatedAverage(column);
38+
}
39+
}

0 commit comments

Comments
 (0)