|
| 1 | +/* |
| 2 | + * Copyright 2009-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.apache.ibatis.reflection.property; |
| 17 | + |
| 18 | +import org.junit.jupiter.api.Test; |
| 19 | + |
| 20 | +import static org.assertj.core.api.Assertions.*; |
| 21 | +import static org.junit.jupiter.api.Assertions.*; |
| 22 | + |
| 23 | +/** |
| 24 | + * @author <a href="[email protected]">mawen12</a> |
| 25 | + * @see PropertyTokenizer |
| 26 | + */ |
| 27 | +class PropertyTokenizerTest { |
| 28 | + |
| 29 | + @Test |
| 30 | + void shouldParsePropertySuccessfully() { |
| 31 | + String fullname = "id"; |
| 32 | + PropertyTokenizer tokenizer = new PropertyTokenizer(fullname); |
| 33 | + |
| 34 | + assertEquals("id", tokenizer.getIndexedName()); |
| 35 | + assertEquals("id", tokenizer.getName()); |
| 36 | + |
| 37 | + assertNull(tokenizer.getChildren()); |
| 38 | + assertNull(tokenizer.getIndex()); |
| 39 | + assertFalse(tokenizer.hasNext()); |
| 40 | + assertNull(tokenizer.getIndex()); |
| 41 | + |
| 42 | + assertThatExceptionOfType(UnsupportedOperationException.class) |
| 43 | + .isThrownBy(tokenizer::remove) |
| 44 | + .withMessage("Remove is not supported, as it has no meaning in the context of properties."); |
| 45 | + } |
| 46 | + |
| 47 | + @Test |
| 48 | + void shouldParsePropertyWhichContainsDelimSuccessfully() { |
| 49 | + String fullname = "person.id"; |
| 50 | + PropertyTokenizer tokenizer = new PropertyTokenizer(fullname); |
| 51 | + |
| 52 | + assertEquals("person", tokenizer.getIndexedName()); |
| 53 | + assertEquals("person", tokenizer.getName()); |
| 54 | + assertTrue(tokenizer.hasNext()); |
| 55 | + assertEquals("id", tokenizer.getChildren()); |
| 56 | + |
| 57 | + assertNull(tokenizer.getIndex()); |
| 58 | + |
| 59 | + assertThatExceptionOfType(UnsupportedOperationException.class) |
| 60 | + .isThrownBy(tokenizer::remove) |
| 61 | + .withMessage("Remove is not supported, as it has no meaning in the context of properties."); |
| 62 | + } |
| 63 | + |
| 64 | + @Test |
| 65 | + void shouldParsePropertyWhichContainsIndexSuccessfully() { |
| 66 | + String fullname = "array[0]"; |
| 67 | + PropertyTokenizer tokenizer = new PropertyTokenizer(fullname); |
| 68 | + |
| 69 | + assertEquals("array[0]", tokenizer.getIndexedName()); |
| 70 | + assertEquals("array", tokenizer.getName()); |
| 71 | + assertEquals("0", tokenizer.getIndex()); |
| 72 | + |
| 73 | + assertFalse(tokenizer.hasNext()); |
| 74 | + assertNull(tokenizer.getChildren()); |
| 75 | + |
| 76 | + assertThatExceptionOfType(UnsupportedOperationException.class) |
| 77 | + .isThrownBy(tokenizer::remove) |
| 78 | + .withMessage("Remove is not supported, as it has no meaning in the context of properties."); |
| 79 | + } |
| 80 | +} |
0 commit comments