|
| 1 | +/* |
| 2 | + * Copyright (C) 2021-2022 TOKYO SYSTEM HOUSE Co., Ltd. |
| 3 | + * |
| 4 | + * This library is free software; you can redistribute it and/or |
| 5 | + * modify it under the terms of the GNU Lesser General Public License |
| 6 | + * as published by the Free Software Foundation; either version 3.0, |
| 7 | + * or (at your option) any later version. |
| 8 | + * |
| 9 | + * This library 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 Lesser General Public License for more details. |
| 13 | + * |
| 14 | + * You should have received a copy of the GNU Lesser General Public |
| 15 | + * License along with this library; see the file COPYING.LIB. If |
| 16 | + * not, write to the Free Software Foundation, 51 Franklin Street, Fifth Floor |
| 17 | + * Boston, MA 02110-1301 USA |
| 18 | + */ |
| 19 | +package jp.osscons.opensourcecobol.libcobj.call; |
| 20 | + |
| 21 | +import static org.junit.jupiter.api.Assertions.*; |
| 22 | + |
| 23 | +import org.junit.jupiter.api.Test; |
| 24 | + |
| 25 | +class CobolCallStackListTest { |
| 26 | + |
| 27 | + @Test |
| 28 | + void testDefaultConstructor() { |
| 29 | + CobolCallStackList list = new CobolCallStackList(); |
| 30 | + assertNull(list.getParent()); |
| 31 | + assertNull(list.getChildren()); |
| 32 | + assertNull(list.getSister()); |
| 33 | + assertNull(list.getName()); |
| 34 | + } |
| 35 | + |
| 36 | + @Test |
| 37 | + void testConstructorWithName() { |
| 38 | + CobolCallStackList list = new CobolCallStackList("TEST-PROGRAM"); |
| 39 | + assertNull(list.getParent()); |
| 40 | + assertNull(list.getChildren()); |
| 41 | + assertNull(list.getSister()); |
| 42 | + assertEquals("TEST-PROGRAM", list.getName()); |
| 43 | + } |
| 44 | + |
| 45 | + @Test |
| 46 | + void testSetAndGetParent() { |
| 47 | + CobolCallStackList parent = new CobolCallStackList("PARENT"); |
| 48 | + CobolCallStackList child = new CobolCallStackList("CHILD"); |
| 49 | + |
| 50 | + child.setParent(parent); |
| 51 | + |
| 52 | + assertEquals(parent, child.getParent()); |
| 53 | + assertEquals("PARENT", child.getParent().getName()); |
| 54 | + } |
| 55 | + |
| 56 | + @Test |
| 57 | + void testSetAndGetChildren() { |
| 58 | + CobolCallStackList parent = new CobolCallStackList("PARENT"); |
| 59 | + CobolCallStackList child = new CobolCallStackList("CHILD"); |
| 60 | + |
| 61 | + parent.setChildren(child); |
| 62 | + |
| 63 | + assertEquals(child, parent.getChildren()); |
| 64 | + assertEquals("CHILD", parent.getChildren().getName()); |
| 65 | + } |
| 66 | + |
| 67 | + @Test |
| 68 | + void testSetAndGetSister() { |
| 69 | + CobolCallStackList first = new CobolCallStackList("FIRST"); |
| 70 | + CobolCallStackList second = new CobolCallStackList("SECOND"); |
| 71 | + |
| 72 | + first.setSister(second); |
| 73 | + |
| 74 | + assertEquals(second, first.getSister()); |
| 75 | + assertEquals("SECOND", first.getSister().getName()); |
| 76 | + } |
| 77 | + |
| 78 | + @Test |
| 79 | + void testHierarchicalStructure() { |
| 80 | + CobolCallStackList root = new CobolCallStackList("ROOT"); |
| 81 | + CobolCallStackList child1 = new CobolCallStackList("CHILD1"); |
| 82 | + CobolCallStackList child2 = new CobolCallStackList("CHILD2"); |
| 83 | + CobolCallStackList grandChild = new CobolCallStackList("GRANDCHILD"); |
| 84 | + |
| 85 | + root.setChildren(child1); |
| 86 | + child1.setParent(root); |
| 87 | + child1.setSister(child2); |
| 88 | + child2.setParent(root); |
| 89 | + child1.setChildren(grandChild); |
| 90 | + grandChild.setParent(child1); |
| 91 | + |
| 92 | + assertEquals("ROOT", root.getName()); |
| 93 | + assertEquals("CHILD1", root.getChildren().getName()); |
| 94 | + assertEquals("CHILD2", root.getChildren().getSister().getName()); |
| 95 | + assertEquals("GRANDCHILD", root.getChildren().getChildren().getName()); |
| 96 | + assertEquals(root, child1.getParent()); |
| 97 | + assertEquals(root, child2.getParent()); |
| 98 | + assertEquals(child1, grandChild.getParent()); |
| 99 | + } |
| 100 | + |
| 101 | + @Test |
| 102 | + void testSetParentToNull() { |
| 103 | + CobolCallStackList parent = new CobolCallStackList("PARENT"); |
| 104 | + CobolCallStackList child = new CobolCallStackList("CHILD"); |
| 105 | + |
| 106 | + child.setParent(parent); |
| 107 | + assertEquals(parent, child.getParent()); |
| 108 | + |
| 109 | + child.setParent(null); |
| 110 | + assertNull(child.getParent()); |
| 111 | + } |
| 112 | + |
| 113 | + @Test |
| 114 | + void testSetChildrenToNull() { |
| 115 | + CobolCallStackList parent = new CobolCallStackList("PARENT"); |
| 116 | + CobolCallStackList child = new CobolCallStackList("CHILD"); |
| 117 | + |
| 118 | + parent.setChildren(child); |
| 119 | + assertEquals(child, parent.getChildren()); |
| 120 | + |
| 121 | + parent.setChildren(null); |
| 122 | + assertNull(parent.getChildren()); |
| 123 | + } |
| 124 | + |
| 125 | + @Test |
| 126 | + void testSetSisterToNull() { |
| 127 | + CobolCallStackList first = new CobolCallStackList("FIRST"); |
| 128 | + CobolCallStackList second = new CobolCallStackList("SECOND"); |
| 129 | + |
| 130 | + first.setSister(second); |
| 131 | + assertEquals(second, first.getSister()); |
| 132 | + |
| 133 | + first.setSister(null); |
| 134 | + assertNull(first.getSister()); |
| 135 | + } |
| 136 | + |
| 137 | + @Test |
| 138 | + void testEmptyName() { |
| 139 | + CobolCallStackList list = new CobolCallStackList(""); |
| 140 | + assertEquals("", list.getName()); |
| 141 | + } |
| 142 | + |
| 143 | + @Test |
| 144 | + void testNullName() { |
| 145 | + CobolCallStackList list = new CobolCallStackList(null); |
| 146 | + assertNull(list.getName()); |
| 147 | + } |
| 148 | + |
| 149 | + @Test |
| 150 | + void testSisterChain() { |
| 151 | + CobolCallStackList first = new CobolCallStackList("FIRST"); |
| 152 | + CobolCallStackList second = new CobolCallStackList("SECOND"); |
| 153 | + CobolCallStackList third = new CobolCallStackList("THIRD"); |
| 154 | + |
| 155 | + first.setSister(second); |
| 156 | + second.setSister(third); |
| 157 | + |
| 158 | + assertEquals("SECOND", first.getSister().getName()); |
| 159 | + assertEquals("THIRD", first.getSister().getSister().getName()); |
| 160 | + assertNull(third.getSister()); |
| 161 | + } |
| 162 | + |
| 163 | + @Test |
| 164 | + void testComplexHierarchyWithMultipleSiblings() { |
| 165 | + CobolCallStackList root = new CobolCallStackList("ROOT"); |
| 166 | + CobolCallStackList child1 = new CobolCallStackList("CHILD1"); |
| 167 | + CobolCallStackList child2 = new CobolCallStackList("CHILD2"); |
| 168 | + CobolCallStackList child3 = new CobolCallStackList("CHILD3"); |
| 169 | + CobolCallStackList grandChild1 = new CobolCallStackList("GRANDCHILD1"); |
| 170 | + CobolCallStackList grandChild2 = new CobolCallStackList("GRANDCHILD2"); |
| 171 | + |
| 172 | + root.setChildren(child1); |
| 173 | + child1.setParent(root); |
| 174 | + child1.setSister(child2); |
| 175 | + child2.setParent(root); |
| 176 | + child2.setSister(child3); |
| 177 | + child3.setParent(root); |
| 178 | + |
| 179 | + child1.setChildren(grandChild1); |
| 180 | + grandChild1.setParent(child1); |
| 181 | + grandChild1.setSister(grandChild2); |
| 182 | + grandChild2.setParent(child1); |
| 183 | + |
| 184 | + assertEquals("CHILD1", root.getChildren().getName()); |
| 185 | + assertEquals("CHILD2", root.getChildren().getSister().getName()); |
| 186 | + assertEquals("CHILD3", root.getChildren().getSister().getSister().getName()); |
| 187 | + assertEquals("GRANDCHILD1", child1.getChildren().getName()); |
| 188 | + assertEquals("GRANDCHILD2", child1.getChildren().getSister().getName()); |
| 189 | + assertEquals(root, child1.getParent()); |
| 190 | + assertEquals(root, child2.getParent()); |
| 191 | + assertEquals(root, child3.getParent()); |
| 192 | + assertEquals(child1, grandChild1.getParent()); |
| 193 | + assertEquals(child1, grandChild2.getParent()); |
| 194 | + } |
| 195 | + |
| 196 | + @Test |
| 197 | + void testDeepNesting() { |
| 198 | + CobolCallStackList level1 = new CobolCallStackList("LEVEL1"); |
| 199 | + CobolCallStackList level2 = new CobolCallStackList("LEVEL2"); |
| 200 | + CobolCallStackList level3 = new CobolCallStackList("LEVEL3"); |
| 201 | + CobolCallStackList level4 = new CobolCallStackList("LEVEL4"); |
| 202 | + |
| 203 | + level1.setChildren(level2); |
| 204 | + level2.setParent(level1); |
| 205 | + level2.setChildren(level3); |
| 206 | + level3.setParent(level2); |
| 207 | + level3.setChildren(level4); |
| 208 | + level4.setParent(level3); |
| 209 | + |
| 210 | + assertEquals("LEVEL2", level1.getChildren().getName()); |
| 211 | + assertEquals("LEVEL3", level1.getChildren().getChildren().getName()); |
| 212 | + assertEquals("LEVEL4", level1.getChildren().getChildren().getChildren().getName()); |
| 213 | + assertEquals(level3, level4.getParent()); |
| 214 | + assertEquals(level2, level3.getParent()); |
| 215 | + assertEquals(level1, level2.getParent()); |
| 216 | + } |
| 217 | +} |
0 commit comments