-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
89da0ca
commit dc44f0c
Showing
1 changed file
with
101 additions
and
0 deletions.
There are no files selected for viewing
101 changes: 101 additions & 0 deletions
101
core/src/test/java/com/github/siroshun09/configapi/core/node/ValueNodeTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* | ||
* Copyright 2024 Siroshun09 | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.github.siroshun09.configapi.core.node; | ||
|
||
import org.junit.jupiter.api.Disabled; | ||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.concurrent.atomic.AtomicInteger; | ||
import java.util.concurrent.atomic.AtomicLong; | ||
import java.util.stream.Stream; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertInstanceOf; | ||
import static org.junit.jupiter.api.Assertions.assertSame; | ||
|
||
class ValueNodeTest extends AbstractNodeTest<ValueNode<?>> { | ||
|
||
// Test cases for ValueNodes are in ValueNodeTest#fromObjectTestCases | ||
@Override | ||
@Disabled | ||
void testNode(NodeTestCase<ValueNode<?>> testCase) { | ||
super.testNode(testCase); | ||
} | ||
|
||
@Override | ||
protected Stream<NodeTestCase<ValueNode<?>>> nodeTestCases() { | ||
return Stream.of(); | ||
} | ||
|
||
@Override | ||
void testFromObject(FromObjectTestCase<ValueNode<?>> testCase) { | ||
super.testFromObject(testCase); | ||
var node = Node.fromObject(testCase.object()); | ||
assertSame(node, Node.fromObject(node)); // ValueNode should be returned as-is from Node#fromObject | ||
} | ||
|
||
@Override | ||
protected ValueNode<?> cast(Node<?> node) { | ||
return (ValueNode<?>) node; | ||
} | ||
|
||
@Override | ||
protected Stream<FromObjectTestCase<ValueNode<?>>> fromObjectTestCases() { | ||
return Stream.of( | ||
fromObjectTest(true, node -> assertSame(BooleanValue.TRUE, node)), | ||
fromObjectTest(false, node -> assertSame(BooleanValue.FALSE, node)), | ||
fromObjectTest((byte) 1, node -> assertEquals((byte) 1, assertInstanceOf(ByteValue.class, node).value())), | ||
fromObjectTest('a', node -> assertEquals('a', assertInstanceOf(CharValue.class, node).value())), | ||
fromObjectTest(3.14, node -> assertEquals(3.14, assertInstanceOf(DoubleValue.class, node).value())), | ||
fromObjectTest(ExampleEnum.A, node -> assertEquals(ExampleEnum.A, assertInstanceOf(EnumValue.class, node).value())), | ||
fromObjectTest(3.14f, node -> assertEquals(3.14f, assertInstanceOf(FloatValue.class, node).value())), | ||
fromObjectTest(1, node -> assertEquals(1, assertInstanceOf(IntValue.class, node).value())), | ||
fromObjectTest(1L, node -> assertEquals(1L, assertInstanceOf(LongValue.class, node).value())), | ||
fromObjectTest((short) 1, node -> assertEquals((short) 1, assertInstanceOf(ShortValue.class, node).value())), | ||
fromObjectTest("a", node -> assertEquals("a", assertInstanceOf(StringValue.class, node).value())), | ||
|
||
// Additional number supports | ||
fromObjectTest(new AtomicInteger(1), node -> assertEquals(1, assertInstanceOf(IntValue.class, node).value())), | ||
fromObjectTest(new AtomicLong(1), node -> assertEquals(1L, assertInstanceOf(LongValue.class, node).value())) | ||
); | ||
} | ||
|
||
private enum ExampleEnum { | ||
A | ||
} | ||
|
||
@Nested | ||
class BooleanValueTest { | ||
@Test | ||
void testFromBoolean() { | ||
assertSame(BooleanValue.TRUE, BooleanValue.fromBoolean(Boolean.TRUE)); | ||
assertSame(BooleanValue.FALSE, BooleanValue.fromBoolean(Boolean.FALSE)); | ||
|
||
assertSame(BooleanValue.TRUE, BooleanValue.fromBoolean(true)); | ||
assertSame(BooleanValue.FALSE, BooleanValue.fromBoolean(false)); | ||
} | ||
} | ||
|
||
@Nested | ||
class NumberValueTest { | ||
@Test | ||
void testNullForFromNumber() { | ||
assertSame(NumberValue.ZERO, NumberValue.fromNumber(null)); | ||
} | ||
} | ||
} |