1+ package org.utbot.examples.collections
2+
3+ import org.junit.jupiter.api.Disabled
4+ import org.junit.jupiter.api.Test
5+ import org.utbot.examples.UtValueTestCaseChecker
6+ import org.utbot.examples.eq
7+ import org.utbot.examples.isException
8+ import org.utbot.framework.codegen.CodeGeneration
9+ import org.utbot.framework.plugin.api.CodegenLanguage
10+
11+ class QueueUsagesTest : UtValueTestCaseChecker (
12+ testClass = QueueUsages : :class,
13+ testCodeGeneration = true ,
14+ languagePipelines = listOf(
15+ CodeGenerationLanguageLastStage (CodegenLanguage .JAVA ),
16+ CodeGenerationLanguageLastStage (CodegenLanguage .KOTLIN , CodeGeneration )
17+ )
18+ ) {
19+ @Test
20+ fun testCreateArrayDeque () {
21+ checkWithException(
22+ QueueUsages ::createArrayDeque,
23+ eq(3 ),
24+ { init , next, r -> init == null && next == null && r.isException<NullPointerException >() },
25+ { init , next, r -> init != null && next == null && r.isException<NullPointerException >() },
26+ { init , next, r -> init != null && next != null && r.getOrNull() == 2 },
27+ )
28+ }
29+
30+ @Test
31+ fun testCreateLinkedList () {
32+ checkWithException(
33+ QueueUsages ::createLinkedList,
34+ eq(1 ),
35+ { _, _, r -> r.getOrNull()!! == 2 },
36+ )
37+ }
38+
39+ @Test
40+ fun testCreateLinkedBlockingDeque () {
41+ checkWithException(
42+ QueueUsages ::createLinkedBlockingDeque,
43+ eq(3 ),
44+ { init , next, r -> init == null && next == null && r.isException<NullPointerException >() },
45+ { init , next, r -> init != null && next == null && r.isException<NullPointerException >() },
46+ { init , next, r -> init != null && next != null && r.getOrNull() == 2 },
47+ )
48+ }
49+
50+ @Test
51+ fun testContainsQueue () {
52+ checkWithException(
53+ QueueUsages ::containsQueue,
54+ eq(3 ),
55+ { q, _, r -> q == null && r.isException<NullPointerException >() },
56+ { q, x, r -> x in q && r.getOrNull() == 1 },
57+ { q, x, r -> x !in q && r.getOrNull() == 0 },
58+ )
59+ }
60+
61+ @Test
62+ fun testAddQueue () {
63+ checkWithException(
64+ QueueUsages ::addQueue,
65+ eq(3 ),
66+ { q, _, r -> q == null && r.isException<NullPointerException >() },
67+ { q, x, r -> q != null && x in r.getOrNull()!! },
68+ { q, x, r -> q != null && x == null && r.isException<NullPointerException >() }, )
69+ }
70+
71+ @Test
72+ fun testAddAllQueue () {
73+ checkWithException(
74+ QueueUsages ::addAllQueue,
75+ eq(3 ),
76+ { q, _, r -> q == null && r.isException<NullPointerException >() },
77+ { q, x, r -> q != null && x != null && x in r.getOrNull()!! },
78+ { q, x, r -> q != null && x == null && r.isException<NullPointerException >() },
79+ )
80+ }
81+
82+ @Test
83+ fun testCastQueueToDeque () {
84+ check(
85+ QueueUsages ::castQueueToDeque,
86+ eq(2 ),
87+ { q, r -> q !is java.util.Deque <* > && r == null },
88+ { q, r -> q is java.util.Deque <* > && r is java.util.Deque <* > },
89+ )
90+ }
91+
92+ @Test
93+ fun testCheckSubtypesOfQueue () {
94+ check(
95+ QueueUsages ::checkSubtypesOfQueue,
96+ eq(4 ),
97+ { q, r -> q == null && r == 0 },
98+ { q, r -> q is java.util.LinkedList <* > && r == 1 },
99+ { q, r -> q is java.util.ArrayDeque <* > && r == 2 },
100+ { q, r -> q !is java.util.LinkedList <* > && q !is java.util.ArrayDeque && r == 3 }
101+ )
102+ }
103+
104+ @Test
105+ @Disabled(" TODO: Related to https://github.com/UnitTestBot/UTBotJava/issues/820" )
106+ fun testCheckSubtypesOfQueueWithUsage () {
107+ check(
108+ QueueUsages ::checkSubtypesOfQueueWithUsage,
109+ eq(4 ),
110+ { q, r -> q == null && r == 0 },
111+ { q, r -> q is java.util.LinkedList <* > && r == 1 },
112+ { q, r -> q is java.util.ArrayDeque <* > && r == 2 },
113+ { q, r -> q !is java.util.LinkedList <* > && q !is java.util.ArrayDeque && r == 3 } // this is uncovered
114+ )
115+ }
116+
117+ @Test
118+ fun testAddConcurrentLinkedQueue () {
119+ checkWithException(
120+ QueueUsages ::addConcurrentLinkedQueue,
121+ eq(3 ),
122+ { q, _, r -> q == null && r.isException<NullPointerException >() },
123+ { q, x, r -> q != null && x != null && x in r.getOrNull()!! },
124+ { q, x, r -> q != null && x == null && r.isException<NullPointerException >() },
125+ )
126+ }
127+ }
0 commit comments