Skip to content

Commit da3768d

Browse files
Add unit tests (#782)
* test: add unit tests * test: strict tests
1 parent a727fec commit da3768d

6 files changed

Lines changed: 1039 additions & 0 deletions

File tree

.github/workflows/pull-request.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ jobs:
2222
check-workflows:
2323
uses: ./.github/workflows/check-workflows.yml
2424

25+
unit-test:
26+
needs: check-workflows
27+
uses: ./.github/workflows/unit-test.yml
28+
2529
build:
2630
needs: check-workflows
2731
strategy:

.github/workflows/push.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ jobs:
2121
check-workflows:
2222
uses: ./.github/workflows/check-workflows.yml
2323

24+
unit-test:
25+
needs: check-workflows
26+
uses: ./.github/workflows/unit-test.yml
27+
2428
build:
2529
needs: check-workflows
2630
strategy:

.github/workflows/unit-test.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: libcobj unit tests
2+
3+
on:
4+
workflow_call:
5+
6+
permissions:
7+
contents: read
8+
9+
jobs:
10+
unit-test:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout opensource COBOL 4J
14+
uses: actions/checkout@v6
15+
16+
- uses: actions/setup-java@v5
17+
with:
18+
distribution: 'temurin'
19+
java-version: '21'
20+
21+
- name: Setup Gradle
22+
uses: gradle/actions/setup-gradle@v5
23+
with:
24+
gradle-version: wrapper
25+
26+
- name: Run unit tests
27+
working-directory: libcobj
28+
run: ./gradlew test
Lines changed: 217 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
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

Comments
 (0)