|
| 1 | +/** |
| 2 | + * Copyright 2016-2019 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 org.mybatis.dynamic.sql.util; |
| 17 | + |
| 18 | +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; |
| 19 | + |
| 20 | +import org.junit.jupiter.api.Test; |
| 21 | +import org.mybatis.dynamic.sql.SqlBuilder; |
| 22 | +import org.mybatis.dynamic.sql.SqlColumn; |
| 23 | +import org.mybatis.dynamic.sql.SqlTable; |
| 24 | + |
| 25 | +public class ColumnMappingVisitorTest { |
| 26 | + |
| 27 | + @Test |
| 28 | + public void testThatUnimplementedMethod1ThrowExceptions() { |
| 29 | + TestTable table = new TestTable(); |
| 30 | + TestVisitor tv = new TestVisitor(); |
| 31 | + ColumnToColumnMapping mapping = ColumnToColumnMapping.of(table.id, table.description); |
| 32 | + |
| 33 | + assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> tv.visit(mapping)); |
| 34 | + } |
| 35 | + |
| 36 | + @Test |
| 37 | + public void testThatUnimplementedMethod2ThrowExceptions() { |
| 38 | + TestTable table = new TestTable(); |
| 39 | + TestVisitor tv = new TestVisitor(); |
| 40 | + ValueMapping<Integer> mapping = ValueMapping.of(table.id, () -> 3); |
| 41 | + |
| 42 | + assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> tv.visit(mapping)); |
| 43 | + } |
| 44 | + |
| 45 | + @Test |
| 46 | + public void testThatUnimplementedMethod3ThrowExceptions() { |
| 47 | + TestTable table = new TestTable(); |
| 48 | + TestVisitor tv = new TestVisitor(); |
| 49 | + SelectMapping mapping = SelectMapping.of(table.id, SqlBuilder.select(table.id).from(table)); |
| 50 | + |
| 51 | + assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> tv.visit(mapping)); |
| 52 | + } |
| 53 | + |
| 54 | + @Test |
| 55 | + public void testThatUnimplementedMethod4ThrowExceptions() { |
| 56 | + TestTable table = new TestTable(); |
| 57 | + TestVisitor tv = new TestVisitor(); |
| 58 | + PropertyMapping mapping = PropertyMapping.of(table.id, "id"); |
| 59 | + |
| 60 | + assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> tv.visit(mapping)); |
| 61 | + } |
| 62 | + |
| 63 | + private static class TestTable extends SqlTable { |
| 64 | + public SqlColumn<Integer> id; |
| 65 | + public SqlColumn<String> description; |
| 66 | + |
| 67 | + public TestTable() { |
| 68 | + super("Test"); |
| 69 | + |
| 70 | + id = column("id"); |
| 71 | + description = column("description"); |
| 72 | + } |
| 73 | + } |
| 74 | + |
| 75 | + private static class TestVisitor implements ColumnMappingVisitor<String> { |
| 76 | + @Override |
| 77 | + public String visit(NullMapping mapping) { |
| 78 | + return "Null Mapping"; |
| 79 | + } |
| 80 | + |
| 81 | + @Override |
| 82 | + public String visit(ConstantMapping mapping) { |
| 83 | + return "Constant Mapping"; |
| 84 | + } |
| 85 | + |
| 86 | + @Override |
| 87 | + public String visit(StringConstantMapping mapping) { |
| 88 | + return "String Constant Mapping"; |
| 89 | + } |
| 90 | + } |
| 91 | +} |
0 commit comments