|
| 1 | +/* |
| 2 | + * Copyright (C) 2024 njt |
| 3 | + * |
| 4 | + * This program is free software: you can redistribute it and/or modify |
| 5 | + * it under the terms of the GNU General Public License as published by |
| 6 | + * the Free Software Foundation, either version 3 of the License, or |
| 7 | + * (at your option) any later version. |
| 8 | + * |
| 9 | + * This program is distributed in the hope that it will be useful, |
| 10 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | + * GNU General Public License for more details. |
| 13 | + * |
| 14 | + * You should have received a copy of the GNU General Public License |
| 15 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | + */ |
| 17 | +package uk.co.spudsoft.query.exec; |
| 18 | + |
| 19 | +import static org.hamcrest.MatcherAssert.assertThat; |
| 20 | +import static org.hamcrest.Matchers.startsWith; |
| 21 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 22 | +import org.junit.jupiter.api.Test; |
| 23 | +import org.stringtemplate.v4.misc.ErrorType; |
| 24 | +import org.stringtemplate.v4.misc.STMessage; |
| 25 | + |
| 26 | + |
| 27 | +/** |
| 28 | + * |
| 29 | + * @author njt |
| 30 | + */ |
| 31 | +public class StringTemplateListenerTest { |
| 32 | + |
| 33 | + @Test |
| 34 | + public void testCompileError() { |
| 35 | + StringTemplateListener listener = new StringTemplateListener(); |
| 36 | + listener.compileTimeError(new STMessage(ErrorType.NO_SUCH_OPTION, null, new IllegalArgumentException("test"))); |
| 37 | + assertEquals(1, listener.getErrors().size()); |
| 38 | + assertEquals(StringTemplateListener.ErrorType.compile, listener.getErrors().get(0).type); |
| 39 | + assertThat(listener.getErrors().get(0).message, startsWith("no such option: null")); |
| 40 | + } |
| 41 | + |
| 42 | + @Test |
| 43 | + public void testInternalError() { |
| 44 | + StringTemplateListener listener = new StringTemplateListener(); |
| 45 | + listener.internalError(new STMessage(ErrorType.NO_SUCH_OPTION, null, new IllegalArgumentException("test"))); |
| 46 | + assertEquals(1, listener.getErrors().size()); |
| 47 | + assertEquals(StringTemplateListener.ErrorType.internal, listener.getErrors().get(0).type); |
| 48 | + assertThat(listener.getErrors().get(0).message, startsWith("no such option: null")); |
| 49 | + } |
| 50 | + |
| 51 | + @Test |
| 52 | + public void testIoError() { |
| 53 | + StringTemplateListener listener = new StringTemplateListener(); |
| 54 | + listener.IOError(new STMessage(ErrorType.NO_SUCH_OPTION, null, new IllegalArgumentException("test"))); |
| 55 | + assertEquals(1, listener.getErrors().size()); |
| 56 | + assertEquals(StringTemplateListener.ErrorType.io, listener.getErrors().get(0).type); |
| 57 | + assertThat(listener.getErrors().get(0).message, startsWith("no such option: null")); |
| 58 | + } |
| 59 | + |
| 60 | + @Test |
| 61 | + public void testRunTimeError() { |
| 62 | + StringTemplateListener listener = new StringTemplateListener(); |
| 63 | + listener.runTimeError(new STMessage(ErrorType.NO_SUCH_OPTION, null, new IllegalArgumentException("test"))); |
| 64 | + assertEquals(1, listener.getErrors().size()); |
| 65 | + assertEquals(StringTemplateListener.ErrorType.runTime, listener.getErrors().get(0).type); |
| 66 | + assertThat(listener.getErrors().get(0).message, startsWith("no such option: null")); |
| 67 | + } |
| 68 | + |
| 69 | +} |
0 commit comments