1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.ibatis.reflection.property;
17
18 import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
19 import static org.junit.jupiter.api.Assertions.*;
20
21 import org.junit.jupiter.api.Test;
22
23
24
25
26
27
28 class PropertyTokenizerTest {
29
30 @Test
31 void shouldParsePropertySuccessfully() {
32 String fullname = "id";
33 PropertyTokenizer tokenizer = new PropertyTokenizer(fullname);
34
35 assertEquals("id", tokenizer.getIndexedName());
36 assertEquals("id", tokenizer.getName());
37
38 assertNull(tokenizer.getChildren());
39 assertNull(tokenizer.getIndex());
40 assertFalse(tokenizer.hasNext());
41 assertNull(tokenizer.getIndex());
42
43 assertThatExceptionOfType(UnsupportedOperationException.class).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).isThrownBy(tokenizer::remove)
60 .withMessage("Remove is not supported, as it has no meaning in the context of properties.");
61 }
62
63 @Test
64 void shouldParsePropertyWhichContainsIndexSuccessfully() {
65 String fullname = "array[0]";
66 PropertyTokenizer tokenizer = new PropertyTokenizer(fullname);
67
68 assertEquals("array[0]", tokenizer.getIndexedName());
69 assertEquals("array", tokenizer.getName());
70 assertEquals("0", tokenizer.getIndex());
71
72 assertFalse(tokenizer.hasNext());
73 assertNull(tokenizer.getChildren());
74
75 assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(tokenizer::remove)
76 .withMessage("Remove is not supported, as it has no meaning in the context of properties.");
77 }
78 }