Skip to content

Commit 3f9dc06

Browse files
committed
test: tests for BoolUtil
1 parent 4702b3a commit 3f9dc06

File tree

2 files changed

+137
-2
lines changed

2 files changed

+137
-2
lines changed

devkit-utils/src/main/java/com/onixbyte/devkit/utils/BoolUtil.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@
4747
*/
4848
public final class BoolUtil {
4949

50-
private final static Logger log = LoggerFactory.getLogger(BoolUtil.class);
51-
5250
/**
5351
* Logical and calculation.
5452
*
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
/*
2+
* Copyright (C) 2024-2025 OnixByte.
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+
* http://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+
*
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package com.onixbyte.devkit.utils;
19+
20+
import org.junit.jupiter.api.Test;
21+
22+
import java.util.function.BooleanSupplier;
23+
24+
import static org.junit.jupiter.api.Assertions.assertFalse;
25+
import static org.junit.jupiter.api.Assertions.assertTrue;
26+
27+
public class BoolUtilTest {
28+
29+
// Tests for and(Boolean... values)
30+
31+
@Test
32+
void and_AllTrueValues_ReturnsTrue() {
33+
assertTrue(BoolUtil.and(true, true, true));
34+
}
35+
36+
@Test
37+
void and_SomeFalseValues_ReturnsFalse() {
38+
assertFalse(BoolUtil.and(true, false, true));
39+
}
40+
41+
@Test
42+
void and_AllFalseValues_ReturnsFalse() {
43+
assertFalse(BoolUtil.and(false, false));
44+
}
45+
46+
@Test
47+
void and_WithNullValues_IgnoresNulls() {
48+
assertTrue(BoolUtil.and(true, null, true));
49+
assertFalse(BoolUtil.and(true, null, false));
50+
}
51+
52+
@Test
53+
void and_AllNullValues_ReturnsTrue() {
54+
// Stream after filtering null is empty, allMatch on empty returns true
55+
assertTrue(BoolUtil.and((Boolean) null, null));
56+
}
57+
58+
// Tests for and(BooleanSupplier... valueSuppliers)
59+
60+
@Test
61+
void and_AllSuppliersTrue_ReturnsTrue() {
62+
BooleanSupplier trueSupplier = () -> true;
63+
BooleanSupplier falseSupplier = () -> false;
64+
65+
assertTrue(BoolUtil.and(trueSupplier, trueSupplier));
66+
assertFalse(BoolUtil.and(trueSupplier, falseSupplier));
67+
}
68+
69+
@Test
70+
void and_WithNullSuppliers_IgnoresNull() {
71+
BooleanSupplier trueSupplier = () -> true;
72+
73+
assertTrue(BoolUtil.and(trueSupplier, null, trueSupplier));
74+
assertFalse(BoolUtil.and(trueSupplier, null, () -> false));
75+
}
76+
77+
@Test
78+
void and_AllNullSuppliers_ReturnsTrue() {
79+
assertTrue(BoolUtil.and((BooleanSupplier) null, null));
80+
}
81+
82+
83+
// Tests for or(Boolean... values)
84+
85+
@Test
86+
void or_AllTrueValues_ReturnsTrue() {
87+
assertTrue(BoolUtil.or(true, true, true));
88+
}
89+
90+
@Test
91+
void or_SomeTrueValues_ReturnsTrue() {
92+
assertTrue(BoolUtil.or(false, true, false));
93+
}
94+
95+
@Test
96+
void or_AllFalseValues_ReturnsFalse() {
97+
assertFalse(BoolUtil.or(false, false));
98+
}
99+
100+
@Test
101+
void or_WithNullValues_IgnoresNull() {
102+
assertTrue(BoolUtil.or(false, null, true));
103+
assertFalse(BoolUtil.or(false, null, false));
104+
}
105+
106+
@Test
107+
void or_AllNullValues_ReturnsFalse() {
108+
// Stream after filtering null is empty, anyMatch on empty returns false
109+
assertFalse(BoolUtil.or((Boolean) null, null));
110+
}
111+
112+
// Tests for or(BooleanSupplier... valueSuppliers)
113+
114+
@Test
115+
void or_AllSuppliersTrue_ReturnsTrue() {
116+
BooleanSupplier trueSupplier = () -> true;
117+
BooleanSupplier falseSupplier = () -> false;
118+
119+
assertTrue(BoolUtil.or(trueSupplier, trueSupplier));
120+
assertTrue(BoolUtil.or(falseSupplier, trueSupplier));
121+
assertFalse(BoolUtil.or(falseSupplier, falseSupplier));
122+
}
123+
124+
@Test
125+
void or_WithNullSuppliers_IgnoresNull() {
126+
BooleanSupplier trueSupplier = () -> true;
127+
BooleanSupplier falseSupplier = () -> false;
128+
129+
assertTrue(BoolUtil.or(falseSupplier, null, trueSupplier));
130+
assertFalse(BoolUtil.or(falseSupplier, null, falseSupplier));
131+
}
132+
133+
@Test
134+
void or_AllNullSuppliers_ReturnsFalse() {
135+
assertFalse(BoolUtil.or((BooleanSupplier) null, null));
136+
}
137+
}

0 commit comments

Comments
 (0)