From 6c875276ca9f8322339de45fe0bda2f6b00ba6dc Mon Sep 17 00:00:00 2001 From: Edward Slavich Date: Sun, 6 Jul 2025 12:05:29 -0800 Subject: [PATCH 1/2] Test coverage for scalar node types (except NUMBER) --- .../org/asdfformat/asdf/node/AsdfNode.java | 6 + .../asdf/node/impl/AsdfNodeBase.java | 5 + .../asdf/node/impl/BooleanAsdfNode.java | 4 +- .../asdfformat/asdf/node/impl/NodeUtils.java | 16 +- .../asdf/node/impl/NumberAsdfNode.java | 8 +- .../asdf/node/impl/TimestampAsdfNode.java | 4 +- .../asdf/node/BooleanAsdfNodeTest.java | 244 ++++++++++++++++++ .../asdf/node/NullAsdfNodeTest.java | 166 ++++++++++++ .../asdf/node/StringAsdfNodeTest.java | 208 +++++++++++++++ .../asdf/node/TimestampAsdfNodeTest.java | 216 ++++++++++++++++ 10 files changed, 866 insertions(+), 11 deletions(-) create mode 100644 asdf-core/src/test/java/org/asdfformat/asdf/node/BooleanAsdfNodeTest.java create mode 100644 asdf-core/src/test/java/org/asdfformat/asdf/node/NullAsdfNodeTest.java create mode 100644 asdf-core/src/test/java/org/asdfformat/asdf/node/StringAsdfNodeTest.java create mode 100644 asdf-core/src/test/java/org/asdfformat/asdf/node/TimestampAsdfNodeTest.java diff --git a/asdf-core/src/main/java/org/asdfformat/asdf/node/AsdfNode.java b/asdf-core/src/main/java/org/asdfformat/asdf/node/AsdfNode.java index 9980103..eec05df 100644 --- a/asdf-core/src/main/java/org/asdfformat/asdf/node/AsdfNode.java +++ b/asdf-core/src/main/java/org/asdfformat/asdf/node/AsdfNode.java @@ -70,6 +70,12 @@ public interface AsdfNode extends Iterable { */ boolean isString(); + /** + * Is this a TIMESTAMP type node? + * @return true if TIMESTAMP + */ + boolean isTimestamp(); + /** * Does this MAPPING node contain the specified String key? * @param key mapping key diff --git a/asdf-core/src/main/java/org/asdfformat/asdf/node/impl/AsdfNodeBase.java b/asdf-core/src/main/java/org/asdfformat/asdf/node/impl/AsdfNodeBase.java index 4939a61..dbfaa1c 100644 --- a/asdf-core/src/main/java/org/asdfformat/asdf/node/impl/AsdfNodeBase.java +++ b/asdf-core/src/main/java/org/asdfformat/asdf/node/impl/AsdfNodeBase.java @@ -49,6 +49,11 @@ public boolean isString() { return getNodeType() == AsdfNodeType.STRING; } + @Override + public boolean isTimestamp() { + return getNodeType() == AsdfNodeType.TIMESTAMP; + } + @Override public boolean containsKey(final String key) { return containsKey(StringAsdfNode.of(key)); diff --git a/asdf-core/src/main/java/org/asdfformat/asdf/node/impl/BooleanAsdfNode.java b/asdf-core/src/main/java/org/asdfformat/asdf/node/impl/BooleanAsdfNode.java index c87a09d..6048c0d 100644 --- a/asdf-core/src/main/java/org/asdfformat/asdf/node/impl/BooleanAsdfNode.java +++ b/asdf-core/src/main/java/org/asdfformat/asdf/node/impl/BooleanAsdfNode.java @@ -71,14 +71,14 @@ public boolean equals(final Object other) { @Override public int hashCode() { - return Objects.hash(tag, value); + return Objects.hash(tag, asBoolean()); } @Override public String toString() { final List fields = new ArrayList<>(); - if (!tag.equals(Tag.STR.getValue())) { + if (!tag.equals(Tag.BOOL.getValue())) { fields.add("tag"); fields.add(tag); } diff --git a/asdf-core/src/main/java/org/asdfformat/asdf/node/impl/NodeUtils.java b/asdf-core/src/main/java/org/asdfformat/asdf/node/impl/NodeUtils.java index ba109b8..2f09611 100644 --- a/asdf-core/src/main/java/org/asdfformat/asdf/node/impl/NodeUtils.java +++ b/asdf-core/src/main/java/org/asdfformat/asdf/node/impl/NodeUtils.java @@ -42,13 +42,17 @@ public static String nodeToString(final AsdfNode node, final List fields stringBuilder.append(node.getClass().getSimpleName()); stringBuilder.append("("); - for (int i = 0; i < fields.size(); i+= 2) { - stringBuilder.append(fields.get(i)); - stringBuilder.append("="); - stringBuilder.append(fields.get(i + 1)); - stringBuilder.append(", "); + + if (fields.size() > 0) { + for (int i = 0; i < fields.size(); i += 2) { + stringBuilder.append(fields.get(i)); + stringBuilder.append("="); + stringBuilder.append(fields.get(i + 1)); + stringBuilder.append(", "); + } + stringBuilder.setLength(stringBuilder.length() - 2); } - stringBuilder.setLength(stringBuilder.length() - 2); + stringBuilder.append(")"); return stringBuilder.toString(); diff --git a/asdf-core/src/main/java/org/asdfformat/asdf/node/impl/NumberAsdfNode.java b/asdf-core/src/main/java/org/asdfformat/asdf/node/impl/NumberAsdfNode.java index 8a18269..2b688bc 100644 --- a/asdf-core/src/main/java/org/asdfformat/asdf/node/impl/NumberAsdfNode.java +++ b/asdf-core/src/main/java/org/asdfformat/asdf/node/impl/NumberAsdfNode.java @@ -43,7 +43,13 @@ public static NumberAsdfNode of(final ScalarNode scalarNode, final Number value) } public static NumberAsdfNode of(final Number value) { - return new NumberAsdfNode(Tag.INT.getValue(), value.toString(), value); + if (value instanceof Byte || value instanceof Short || value instanceof Integer || value instanceof BigInteger) { + return new NumberAsdfNode(Tag.INT.getValue(), value.toString(), value); + } else if (value instanceof Float || value instanceof Double || value instanceof BigDecimal) { + return new NumberAsdfNode(Tag.FLOAT.getValue(), value.toString(), value); + } else { + throw new IllegalArgumentException("Unexpected Number subclass: " + value.getClass().getName()); + } } private final String tag; diff --git a/asdf-core/src/main/java/org/asdfformat/asdf/node/impl/TimestampAsdfNode.java b/asdf-core/src/main/java/org/asdfformat/asdf/node/impl/TimestampAsdfNode.java index ad80fdd..2c672a5 100644 --- a/asdf-core/src/main/java/org/asdfformat/asdf/node/impl/TimestampAsdfNode.java +++ b/asdf-core/src/main/java/org/asdfformat/asdf/node/impl/TimestampAsdfNode.java @@ -28,7 +28,7 @@ public TimestampAsdfNode(final String tag, final Instant value) { @Override public AsdfNodeType getNodeType() { - return AsdfNodeType.STRING; + return AsdfNodeType.TIMESTAMP; } @Override @@ -62,7 +62,7 @@ public int hashCode() { public String toString() { final List fields = new ArrayList<>(); - if (!tag.equals(Tag.STR.getValue())) { + if (!tag.equals(Tag.TIMESTAMP.getValue())) { fields.add("tag"); fields.add(tag); } diff --git a/asdf-core/src/test/java/org/asdfformat/asdf/node/BooleanAsdfNodeTest.java b/asdf-core/src/test/java/org/asdfformat/asdf/node/BooleanAsdfNodeTest.java new file mode 100644 index 0000000..a018b32 --- /dev/null +++ b/asdf-core/src/test/java/org/asdfformat/asdf/node/BooleanAsdfNodeTest.java @@ -0,0 +1,244 @@ +package org.asdfformat.asdf.node; + +import org.asdfformat.asdf.node.impl.BooleanAsdfNode; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; +import org.yaml.snakeyaml.DumperOptions; +import org.yaml.snakeyaml.nodes.ScalarNode; +import org.yaml.snakeyaml.nodes.Tag; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class BooleanAsdfNodeTest { + @Nested + class ConstructionFromBoolean { + private BooleanAsdfNode trueNode; + private BooleanAsdfNode falseNode; + + @BeforeEach + void beforeEach() { + trueNode = BooleanAsdfNode.of(true); + falseNode = BooleanAsdfNode.of(false); + } + + @Test + void testTrue() { + assertTrue(trueNode.asBoolean()); + assertEquals(Tag.BOOL.getValue(), trueNode.getTag()); + } + + @Test + void testFalse() { + assertFalse(falseNode.asBoolean()); + assertEquals(Tag.BOOL.getValue(), falseNode.getTag()); + } + + @Test + void testEqualsAndHashCode() { + assertNotEquals(trueNode, falseNode); + assertNotEquals(trueNode.hashCode(), falseNode.hashCode()); + + assertEquals(BooleanAsdfNode.of(true), trueNode); + assertEquals(BooleanAsdfNode.of(true).hashCode(), trueNode.hashCode()); + + assertEquals(BooleanAsdfNode.of(false), falseNode); + assertEquals(BooleanAsdfNode.of(false).hashCode(), falseNode.hashCode()); + + assertNotEquals(trueNode, true); + assertNotEquals(trueNode, null); + assertEquals(trueNode, trueNode); + } + + @Test + void testToString() { + assertEquals("BooleanAsdfNode(value=true)", trueNode.toString()); + assertEquals("BooleanAsdfNode(value=false)", falseNode.toString()); + } + } + + @Nested + class ConstructionFromSnakeYamlNode { + @ParameterizedTest + @ValueSource(strings = {"yes", "true", "on"}) + void testTrueValue(final String value) { + final ScalarNode snakeYamlNode = new ScalarNode(Tag.BOOL, value, null, null, DumperOptions.ScalarStyle.LITERAL); + final BooleanAsdfNode asdfNode = BooleanAsdfNode.of(snakeYamlNode); + + assertTrue(asdfNode.asBoolean()); + assertEquals(snakeYamlNode.getTag().getValue(), asdfNode.getTag()); + + assertEquals(BooleanAsdfNode.of(true), asdfNode); + assertEquals(BooleanAsdfNode.of(true).hashCode(), asdfNode.hashCode()); + + assertEquals(String.format("BooleanAsdfNode(value=%s)", value), asdfNode.toString()); + } + + @ParameterizedTest + @ValueSource(strings = {"no", "false", "off"}) + void testFalseValue(final String value) { + final ScalarNode snakeYamlNode = new ScalarNode(Tag.BOOL, value, null, null, DumperOptions.ScalarStyle.LITERAL); + final BooleanAsdfNode asdfNode = BooleanAsdfNode.of(snakeYamlNode); + + assertFalse(asdfNode.asBoolean()); + assertEquals(snakeYamlNode.getTag().getValue(), asdfNode.getTag()); + + assertEquals(BooleanAsdfNode.of(false), asdfNode); + assertEquals(BooleanAsdfNode.of(false).hashCode(), asdfNode.hashCode()); + + assertEquals(String.format("BooleanAsdfNode(value=%s)", value), asdfNode.toString()); + } + + @Test + void testBogusValue() { + final ScalarNode snakeYamlNode = new ScalarNode(Tag.BOOL, "maybe", null, null, DumperOptions.ScalarStyle.LITERAL); + final BooleanAsdfNode asdfNode = BooleanAsdfNode.of(snakeYamlNode); + + assertThrows(RuntimeException.class, asdfNode::asBoolean); + } + + @Test + void testCustomTag() { + final Tag customTag = new Tag("foo"); + final ScalarNode snakeYamlNode = new ScalarNode(customTag, "true", null, null, DumperOptions.ScalarStyle.LITERAL); + final BooleanAsdfNode asdfNode = BooleanAsdfNode.of(snakeYamlNode); + + assertTrue(asdfNode.asBoolean()); + assertEquals(customTag.getValue(), asdfNode.getTag()); + + assertNotEquals(BooleanAsdfNode.of(true), asdfNode); + assertNotEquals(BooleanAsdfNode.of(true).hashCode(), asdfNode.hashCode()); + + assertEquals("BooleanAsdfNode(tag=foo, value=true)", asdfNode.toString()); + } + } + + @Test + void testNodeType() { + assertEquals(AsdfNodeType.BOOLEAN, BooleanAsdfNode.of(true).getNodeType()); + } + + @Test + void testBaseMethods() { + final BooleanAsdfNode node = BooleanAsdfNode.of(true); + + assertTrue(node.isBoolean()); + assertFalse(node.isMapping()); + assertFalse(node.isNdArray()); + assertFalse(node.isNull()); + assertFalse(node.isNumber()); + assertFalse(node.isSequence()); + assertFalse(node.isString()); + assertFalse(node.isTimestamp()); + + assertFalse(node.containsKey("foo")); + assertFalse(node.containsKey(1L)); + assertFalse(node.containsKey(false)); + assertFalse(node.containsKey(node)); + + assertEquals(0, node.size()); + + assertFalse(node.iterator().hasNext()); + + assertThrows(IllegalStateException.class, () -> node.get("foo")); + assertThrows(IllegalStateException.class, () -> node.get(1L)); + assertThrows(IllegalStateException.class, () -> node.get(false)); + assertThrows(IllegalStateException.class, () -> node.get(node)); + + assertThrows(IllegalStateException.class, () -> node.getBigDecimal("foo")); + assertThrows(IllegalStateException.class, () -> node.getBigDecimal(1L)); + assertThrows(IllegalStateException.class, () -> node.getBigDecimal(false)); + assertThrows(IllegalStateException.class, () -> node.getBigDecimal(node)); + + assertThrows(IllegalStateException.class, () -> node.getBigInteger("foo")); + assertThrows(IllegalStateException.class, () -> node.getBigInteger(1L)); + assertThrows(IllegalStateException.class, () -> node.getBigInteger(false)); + assertThrows(IllegalStateException.class, () -> node.getBigInteger(node)); + + assertThrows(IllegalStateException.class, () -> node.getBoolean("foo")); + assertThrows(IllegalStateException.class, () -> node.getBoolean(1L)); + assertThrows(IllegalStateException.class, () -> node.getBoolean(false)); + assertThrows(IllegalStateException.class, () -> node.getBoolean(node)); + + assertThrows(IllegalStateException.class, () -> node.getByte("foo")); + assertThrows(IllegalStateException.class, () -> node.getByte(1L)); + assertThrows(IllegalStateException.class, () -> node.getByte(false)); + assertThrows(IllegalStateException.class, () -> node.getByte(node)); + + assertThrows(IllegalStateException.class, () -> node.getDouble("foo")); + assertThrows(IllegalStateException.class, () -> node.getDouble(1L)); + assertThrows(IllegalStateException.class, () -> node.getDouble(false)); + assertThrows(IllegalStateException.class, () -> node.getDouble(node)); + + assertThrows(IllegalStateException.class, () -> node.getFloat("foo")); + assertThrows(IllegalStateException.class, () -> node.getFloat(1L)); + assertThrows(IllegalStateException.class, () -> node.getFloat(false)); + assertThrows(IllegalStateException.class, () -> node.getFloat(node)); + + assertThrows(IllegalStateException.class, () -> node.getInstant("foo")); + assertThrows(IllegalStateException.class, () -> node.getInstant(1L)); + assertThrows(IllegalStateException.class, () -> node.getInstant(false)); + assertThrows(IllegalStateException.class, () -> node.getInstant(node)); + + assertThrows(IllegalStateException.class, () -> node.getInt("foo")); + assertThrows(IllegalStateException.class, () -> node.getInt(1L)); + assertThrows(IllegalStateException.class, () -> node.getInt(false)); + assertThrows(IllegalStateException.class, () -> node.getInt(node)); + + assertThrows(IllegalStateException.class, () -> node.getList("foo", String.class)); + assertThrows(IllegalStateException.class, () -> node.getList(1L, String.class)); + assertThrows(IllegalStateException.class, () -> node.getList(false, String.class)); + assertThrows(IllegalStateException.class, () -> node.getList(node, String.class)); + + assertThrows(IllegalStateException.class, () -> node.getLong("foo")); + assertThrows(IllegalStateException.class, () -> node.getLong(1L)); + assertThrows(IllegalStateException.class, () -> node.getLong(false)); + assertThrows(IllegalStateException.class, () -> node.getLong(node)); + + assertThrows(IllegalStateException.class, () -> node.getNumber("foo")); + assertThrows(IllegalStateException.class, () -> node.getNumber(1L)); + assertThrows(IllegalStateException.class, () -> node.getNumber(false)); + assertThrows(IllegalStateException.class, () -> node.getNumber(node)); + + assertThrows(IllegalStateException.class, () -> node.getMap("foo", String.class, String.class)); + assertThrows(IllegalStateException.class, () -> node.getMap(1L, String.class, String.class)); + assertThrows(IllegalStateException.class, () -> node.getMap(false, String.class, String.class)); + assertThrows(IllegalStateException.class, () -> node.getMap(node, String.class, String.class)); + + assertThrows(IllegalStateException.class, () -> node.getNdArray("foo")); + assertThrows(IllegalStateException.class, () -> node.getNdArray(1L)); + assertThrows(IllegalStateException.class, () -> node.getNdArray(false)); + assertThrows(IllegalStateException.class, () -> node.getNdArray(node)); + + assertThrows(IllegalStateException.class, () -> node.getShort("foo")); + assertThrows(IllegalStateException.class, () -> node.getShort(1L)); + assertThrows(IllegalStateException.class, () -> node.getShort(false)); + assertThrows(IllegalStateException.class, () -> node.getShort(node)); + + assertThrows(IllegalStateException.class, () -> node.getString("foo")); + assertThrows(IllegalStateException.class, () -> node.getString(1L)); + assertThrows(IllegalStateException.class, () -> node.getString(false)); + assertThrows(IllegalStateException.class, () -> node.getString(node)); + + assertThrows(IllegalStateException.class, node::asBigDecimal); + assertThrows(IllegalStateException.class, node::asBigInteger); + assertThrows(IllegalStateException.class, node::asByte); + assertThrows(IllegalStateException.class, node::asDouble); + assertThrows(IllegalStateException.class, node::asFloat); + assertThrows(IllegalStateException.class, node::asInstant); + assertThrows(IllegalStateException.class, node::asInt); + assertThrows(IllegalStateException.class, () -> node.asList(String.class)); + assertThrows(IllegalStateException.class, node::asLong); + assertThrows(IllegalStateException.class, () -> node.asMap(String.class, String.class)); + assertThrows(IllegalStateException.class, node::asNdArray); + assertThrows(IllegalStateException.class, node::asNumber); + assertThrows(IllegalStateException.class, node::asShort); + assertThrows(IllegalStateException.class, node::asString); + } +} diff --git a/asdf-core/src/test/java/org/asdfformat/asdf/node/NullAsdfNodeTest.java b/asdf-core/src/test/java/org/asdfformat/asdf/node/NullAsdfNodeTest.java new file mode 100644 index 0000000..fb5a13a --- /dev/null +++ b/asdf-core/src/test/java/org/asdfformat/asdf/node/NullAsdfNodeTest.java @@ -0,0 +1,166 @@ +package org.asdfformat.asdf.node; + +import org.asdfformat.asdf.node.impl.NullAsdfNode; +import org.junit.jupiter.api.Test; +import org.yaml.snakeyaml.DumperOptions; +import org.yaml.snakeyaml.nodes.Node; +import org.yaml.snakeyaml.nodes.ScalarNode; +import org.yaml.snakeyaml.nodes.Tag; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class NullAsdfNodeTest { + @Test + void testBasic() { + final Node snakeYamlNode = new ScalarNode(Tag.NULL, "", null, null, DumperOptions.ScalarStyle.LITERAL); + final NullAsdfNode asdfNode = NullAsdfNode.of(snakeYamlNode); + + assertEquals(snakeYamlNode.getTag().getValue(), asdfNode.getTag()); + + assertEquals(NullAsdfNode.of(snakeYamlNode), asdfNode); + + assertEquals("NullAsdfNode()", asdfNode.toString()); + } + + @Test + void testCustomTag() { + final Tag customTag = new Tag("custom"); + final ScalarNode snakeYamlNode = new ScalarNode(customTag, "", null, null, DumperOptions.ScalarStyle.LITERAL); + final NullAsdfNode asdfNode = NullAsdfNode.of(snakeYamlNode); + + assertEquals(customTag.getValue(), asdfNode.getTag()); + + assertEquals(NullAsdfNode.of(snakeYamlNode), asdfNode); + assertNotEquals(NullAsdfNode.of(new ScalarNode(Tag.NULL, "", null, null, DumperOptions.ScalarStyle.LITERAL)), asdfNode); + + assertEquals("NullAsdfNode(tag=custom)", asdfNode.toString()); + } + + @Test + void testNodeType() { + assertEquals(AsdfNodeType.NULL, NullAsdfNode.of(new ScalarNode(Tag.NULL, "", null, null, DumperOptions.ScalarStyle.LITERAL)).getNodeType()); + } + + @Test + void testBaseMethods() { + final NullAsdfNode node = NullAsdfNode.of(new ScalarNode(Tag.NULL, "", null, null, DumperOptions.ScalarStyle.LITERAL)); + + assertFalse(node.isBoolean()); + assertFalse(node.isMapping()); + assertFalse(node.isNdArray()); + assertTrue(node.isNull()); + assertFalse(node.isNumber()); + assertFalse(node.isSequence()); + assertFalse(node.isString()); + assertFalse(node.isTimestamp()); + + assertFalse(node.containsKey("foo")); + assertFalse(node.containsKey(1L)); + assertFalse(node.containsKey(false)); + assertFalse(node.containsKey(node)); + + assertEquals(0, node.size()); + + assertFalse(node.iterator().hasNext()); + + assertThrows(IllegalStateException.class, () -> node.get("foo")); + assertThrows(IllegalStateException.class, () -> node.get(1L)); + assertThrows(IllegalStateException.class, () -> node.get(false)); + assertThrows(IllegalStateException.class, () -> node.get(node)); + + assertThrows(IllegalStateException.class, () -> node.getBigDecimal("foo")); + assertThrows(IllegalStateException.class, () -> node.getBigDecimal(1L)); + assertThrows(IllegalStateException.class, () -> node.getBigDecimal(false)); + assertThrows(IllegalStateException.class, () -> node.getBigDecimal(node)); + + assertThrows(IllegalStateException.class, () -> node.getBigInteger("foo")); + assertThrows(IllegalStateException.class, () -> node.getBigInteger(1L)); + assertThrows(IllegalStateException.class, () -> node.getBigInteger(false)); + assertThrows(IllegalStateException.class, () -> node.getBigInteger(node)); + + assertThrows(IllegalStateException.class, () -> node.getBoolean("foo")); + assertThrows(IllegalStateException.class, () -> node.getBoolean(1L)); + assertThrows(IllegalStateException.class, () -> node.getBoolean(false)); + assertThrows(IllegalStateException.class, () -> node.getBoolean(node)); + + assertThrows(IllegalStateException.class, () -> node.getByte("foo")); + assertThrows(IllegalStateException.class, () -> node.getByte(1L)); + assertThrows(IllegalStateException.class, () -> node.getByte(false)); + assertThrows(IllegalStateException.class, () -> node.getByte(node)); + + assertThrows(IllegalStateException.class, () -> node.getDouble("foo")); + assertThrows(IllegalStateException.class, () -> node.getDouble(1L)); + assertThrows(IllegalStateException.class, () -> node.getDouble(false)); + assertThrows(IllegalStateException.class, () -> node.getDouble(node)); + + assertThrows(IllegalStateException.class, () -> node.getFloat("foo")); + assertThrows(IllegalStateException.class, () -> node.getFloat(1L)); + assertThrows(IllegalStateException.class, () -> node.getFloat(false)); + assertThrows(IllegalStateException.class, () -> node.getFloat(node)); + + assertThrows(IllegalStateException.class, () -> node.getInstant("foo")); + assertThrows(IllegalStateException.class, () -> node.getInstant(1L)); + assertThrows(IllegalStateException.class, () -> node.getInstant(false)); + assertThrows(IllegalStateException.class, () -> node.getInstant(node)); + + assertThrows(IllegalStateException.class, () -> node.getInt("foo")); + assertThrows(IllegalStateException.class, () -> node.getInt(1L)); + assertThrows(IllegalStateException.class, () -> node.getInt(false)); + assertThrows(IllegalStateException.class, () -> node.getInt(node)); + + assertThrows(IllegalStateException.class, () -> node.getList("foo", String.class)); + assertThrows(IllegalStateException.class, () -> node.getList(1L, String.class)); + assertThrows(IllegalStateException.class, () -> node.getList(false, String.class)); + assertThrows(IllegalStateException.class, () -> node.getList(node, String.class)); + + assertThrows(IllegalStateException.class, () -> node.getLong("foo")); + assertThrows(IllegalStateException.class, () -> node.getLong(1L)); + assertThrows(IllegalStateException.class, () -> node.getLong(false)); + assertThrows(IllegalStateException.class, () -> node.getLong(node)); + + assertThrows(IllegalStateException.class, () -> node.getNumber("foo")); + assertThrows(IllegalStateException.class, () -> node.getNumber(1L)); + assertThrows(IllegalStateException.class, () -> node.getNumber(false)); + assertThrows(IllegalStateException.class, () -> node.getNumber(node)); + + assertThrows(IllegalStateException.class, () -> node.getMap("foo", String.class, String.class)); + assertThrows(IllegalStateException.class, () -> node.getMap(1L, String.class, String.class)); + assertThrows(IllegalStateException.class, () -> node.getMap(false, String.class, String.class)); + assertThrows(IllegalStateException.class, () -> node.getMap(node, String.class, String.class)); + + assertThrows(IllegalStateException.class, () -> node.getNdArray("foo")); + assertThrows(IllegalStateException.class, () -> node.getNdArray(1L)); + assertThrows(IllegalStateException.class, () -> node.getNdArray(false)); + assertThrows(IllegalStateException.class, () -> node.getNdArray(node)); + + assertThrows(IllegalStateException.class, () -> node.getShort("foo")); + assertThrows(IllegalStateException.class, () -> node.getShort(1L)); + assertThrows(IllegalStateException.class, () -> node.getShort(false)); + assertThrows(IllegalStateException.class, () -> node.getShort(node)); + + assertThrows(IllegalStateException.class, () -> node.getString("foo")); + assertThrows(IllegalStateException.class, () -> node.getString(1L)); + assertThrows(IllegalStateException.class, () -> node.getString(false)); + assertThrows(IllegalStateException.class, () -> node.getString(node)); + + assertThrows(IllegalStateException.class, node::asBigDecimal); + assertThrows(IllegalStateException.class, node::asBigInteger); + assertThrows(IllegalStateException.class, node::asBoolean); + assertThrows(IllegalStateException.class, node::asByte); + assertThrows(IllegalStateException.class, node::asDouble); + assertThrows(IllegalStateException.class, node::asFloat); + assertThrows(IllegalStateException.class, node::asInstant); + assertThrows(IllegalStateException.class, node::asInt); + assertThrows(IllegalStateException.class, () -> node.asList(String.class)); + assertThrows(IllegalStateException.class, node::asLong); + assertThrows(IllegalStateException.class, () -> node.asMap(String.class, String.class)); + assertThrows(IllegalStateException.class, node::asNdArray); + assertThrows(IllegalStateException.class, node::asNumber); + assertThrows(IllegalStateException.class, node::asShort); + assertThrows(IllegalStateException.class, node::asString); + } +} diff --git a/asdf-core/src/test/java/org/asdfformat/asdf/node/StringAsdfNodeTest.java b/asdf-core/src/test/java/org/asdfformat/asdf/node/StringAsdfNodeTest.java new file mode 100644 index 0000000..3035e7a --- /dev/null +++ b/asdf-core/src/test/java/org/asdfformat/asdf/node/StringAsdfNodeTest.java @@ -0,0 +1,208 @@ +package org.asdfformat.asdf.node; + +import org.asdfformat.asdf.node.impl.StringAsdfNode; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import org.yaml.snakeyaml.DumperOptions; +import org.yaml.snakeyaml.nodes.ScalarNode; +import org.yaml.snakeyaml.nodes.Tag; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class StringAsdfNodeTest { + @Nested + class ConstructionFromString { + private StringAsdfNode node; + + @BeforeEach + void beforeEach() { + node = StringAsdfNode.of("foo"); + } + + @Test + void testAsString() { + assertEquals("foo", node.asString()); + } + + @Test + void testGetTag() { + assertEquals(Tag.STR.getValue(), node.getTag()); + } + + @Test + void testEqualsAndHashCode() { + assertEquals(StringAsdfNode.of("foo"), node); + assertEquals(StringAsdfNode.of("foo").hashCode(), node.hashCode()); + + assertNotEquals(StringAsdfNode.of("bar"), node); + assertNotEquals(StringAsdfNode.of("bar").hashCode(), node.hashCode()); + + assertNotEquals(node, "bar"); + assertNotEquals(node, null); + assertEquals(node, node); + } + + @Test + void testToString() { + assertEquals("StringAsdfNode(value=foo)", node.toString()); + } + } + + @Nested + class ConstructionFromSnakeYamlNode { + void testBasic() { + final ScalarNode snakeYamlNode = new ScalarNode(Tag.STR, "foo", null, null, DumperOptions.ScalarStyle.LITERAL); + final StringAsdfNode asdfNode = StringAsdfNode.of(snakeYamlNode); + + assertEquals("foo", asdfNode.asString()); + assertEquals(snakeYamlNode.getTag().getValue(), asdfNode.getTag()); + + assertEquals(StringAsdfNode.of(snakeYamlNode), asdfNode); + + assertEquals("StringAsdfNode(value=foo)", asdfNode.toString()); + } + + @Test + void testCustomTag() { + final Tag customTag = new Tag("custom"); + final ScalarNode snakeYamlNode = new ScalarNode(customTag, "foo", null, null, DumperOptions.ScalarStyle.LITERAL); + final StringAsdfNode asdfNode = StringAsdfNode.of(snakeYamlNode); + + assertEquals("foo", asdfNode.asString()); + assertEquals(customTag.getValue(), asdfNode.getTag()); + + assertEquals(StringAsdfNode.of(snakeYamlNode), asdfNode); + assertNotEquals(StringAsdfNode.of("foo"), asdfNode); + + assertEquals("StringAsdfNode(tag=custom, value=foo)", asdfNode.toString()); + } + } + + @Test + void testNodeType() { + assertEquals(AsdfNodeType.STRING, StringAsdfNode.of("foo").getNodeType()); + } + + @Test + void testBaseMethods() { + final StringAsdfNode node = StringAsdfNode.of("foo"); + + assertFalse(node.isBoolean()); + assertFalse(node.isMapping()); + assertFalse(node.isNdArray()); + assertFalse(node.isNull()); + assertFalse(node.isNumber()); + assertFalse(node.isSequence()); + assertTrue(node.isString()); + assertFalse(node.isTimestamp()); + + assertFalse(node.containsKey("foo")); + assertFalse(node.containsKey(1L)); + assertFalse(node.containsKey(false)); + assertFalse(node.containsKey(node)); + + assertEquals(0, node.size()); + + assertFalse(node.iterator().hasNext()); + + assertThrows(IllegalStateException.class, () -> node.get("foo")); + assertThrows(IllegalStateException.class, () -> node.get(1L)); + assertThrows(IllegalStateException.class, () -> node.get(false)); + assertThrows(IllegalStateException.class, () -> node.get(node)); + + assertThrows(IllegalStateException.class, () -> node.getBigDecimal("foo")); + assertThrows(IllegalStateException.class, () -> node.getBigDecimal(1L)); + assertThrows(IllegalStateException.class, () -> node.getBigDecimal(false)); + assertThrows(IllegalStateException.class, () -> node.getBigDecimal(node)); + + assertThrows(IllegalStateException.class, () -> node.getBigInteger("foo")); + assertThrows(IllegalStateException.class, () -> node.getBigInteger(1L)); + assertThrows(IllegalStateException.class, () -> node.getBigInteger(false)); + assertThrows(IllegalStateException.class, () -> node.getBigInteger(node)); + + assertThrows(IllegalStateException.class, () -> node.getBoolean("foo")); + assertThrows(IllegalStateException.class, () -> node.getBoolean(1L)); + assertThrows(IllegalStateException.class, () -> node.getBoolean(false)); + assertThrows(IllegalStateException.class, () -> node.getBoolean(node)); + + assertThrows(IllegalStateException.class, () -> node.getByte("foo")); + assertThrows(IllegalStateException.class, () -> node.getByte(1L)); + assertThrows(IllegalStateException.class, () -> node.getByte(false)); + assertThrows(IllegalStateException.class, () -> node.getByte(node)); + + assertThrows(IllegalStateException.class, () -> node.getDouble("foo")); + assertThrows(IllegalStateException.class, () -> node.getDouble(1L)); + assertThrows(IllegalStateException.class, () -> node.getDouble(false)); + assertThrows(IllegalStateException.class, () -> node.getDouble(node)); + + assertThrows(IllegalStateException.class, () -> node.getFloat("foo")); + assertThrows(IllegalStateException.class, () -> node.getFloat(1L)); + assertThrows(IllegalStateException.class, () -> node.getFloat(false)); + assertThrows(IllegalStateException.class, () -> node.getFloat(node)); + + assertThrows(IllegalStateException.class, () -> node.getInstant("foo")); + assertThrows(IllegalStateException.class, () -> node.getInstant(1L)); + assertThrows(IllegalStateException.class, () -> node.getInstant(false)); + assertThrows(IllegalStateException.class, () -> node.getInstant(node)); + + assertThrows(IllegalStateException.class, () -> node.getInt("foo")); + assertThrows(IllegalStateException.class, () -> node.getInt(1L)); + assertThrows(IllegalStateException.class, () -> node.getInt(false)); + assertThrows(IllegalStateException.class, () -> node.getInt(node)); + + assertThrows(IllegalStateException.class, () -> node.getList("foo", String.class)); + assertThrows(IllegalStateException.class, () -> node.getList(1L, String.class)); + assertThrows(IllegalStateException.class, () -> node.getList(false, String.class)); + assertThrows(IllegalStateException.class, () -> node.getList(node, String.class)); + + assertThrows(IllegalStateException.class, () -> node.getLong("foo")); + assertThrows(IllegalStateException.class, () -> node.getLong(1L)); + assertThrows(IllegalStateException.class, () -> node.getLong(false)); + assertThrows(IllegalStateException.class, () -> node.getLong(node)); + + assertThrows(IllegalStateException.class, () -> node.getNumber("foo")); + assertThrows(IllegalStateException.class, () -> node.getNumber(1L)); + assertThrows(IllegalStateException.class, () -> node.getNumber(false)); + assertThrows(IllegalStateException.class, () -> node.getNumber(node)); + + assertThrows(IllegalStateException.class, () -> node.getMap("foo", String.class, String.class)); + assertThrows(IllegalStateException.class, () -> node.getMap(1L, String.class, String.class)); + assertThrows(IllegalStateException.class, () -> node.getMap(false, String.class, String.class)); + assertThrows(IllegalStateException.class, () -> node.getMap(node, String.class, String.class)); + + assertThrows(IllegalStateException.class, () -> node.getNdArray("foo")); + assertThrows(IllegalStateException.class, () -> node.getNdArray(1L)); + assertThrows(IllegalStateException.class, () -> node.getNdArray(false)); + assertThrows(IllegalStateException.class, () -> node.getNdArray(node)); + + assertThrows(IllegalStateException.class, () -> node.getShort("foo")); + assertThrows(IllegalStateException.class, () -> node.getShort(1L)); + assertThrows(IllegalStateException.class, () -> node.getShort(false)); + assertThrows(IllegalStateException.class, () -> node.getShort(node)); + + assertThrows(IllegalStateException.class, () -> node.getString("foo")); + assertThrows(IllegalStateException.class, () -> node.getString(1L)); + assertThrows(IllegalStateException.class, () -> node.getString(false)); + assertThrows(IllegalStateException.class, () -> node.getString(node)); + + assertThrows(IllegalStateException.class, node::asBigDecimal); + assertThrows(IllegalStateException.class, node::asBigInteger); + assertThrows(IllegalStateException.class, node::asBoolean); + assertThrows(IllegalStateException.class, node::asByte); + assertThrows(IllegalStateException.class, node::asDouble); + assertThrows(IllegalStateException.class, node::asFloat); + assertThrows(IllegalStateException.class, node::asInstant); + assertThrows(IllegalStateException.class, node::asInt); + assertThrows(IllegalStateException.class, () -> node.asList(String.class)); + assertThrows(IllegalStateException.class, node::asLong); + assertThrows(IllegalStateException.class, () -> node.asMap(String.class, String.class)); + assertThrows(IllegalStateException.class, node::asNdArray); + assertThrows(IllegalStateException.class, node::asNumber); + assertThrows(IllegalStateException.class, node::asShort); + } +} diff --git a/asdf-core/src/test/java/org/asdfformat/asdf/node/TimestampAsdfNodeTest.java b/asdf-core/src/test/java/org/asdfformat/asdf/node/TimestampAsdfNodeTest.java new file mode 100644 index 0000000..8c240c6 --- /dev/null +++ b/asdf-core/src/test/java/org/asdfformat/asdf/node/TimestampAsdfNodeTest.java @@ -0,0 +1,216 @@ +package org.asdfformat.asdf.node; + +import org.asdfformat.asdf.node.impl.TimestampAsdfNode; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import org.yaml.snakeyaml.DumperOptions; +import org.yaml.snakeyaml.nodes.ScalarNode; +import org.yaml.snakeyaml.nodes.Tag; + +import java.time.Instant; +import java.time.temporal.ChronoUnit; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class TimestampAsdfNodeTest { + @Nested + class ConstructionFromString { + private Instant instant ; + private TimestampAsdfNode node; + + @BeforeEach + void beforeEach() { + instant = Instant.now(); + node = TimestampAsdfNode.of(instant); + } + + @Test + void testAsInstant() { + assertEquals(instant, node.asInstant()); + } + + @Test + void testGetTag() { + assertEquals(Tag.TIMESTAMP.getValue(), node.getTag()); + } + + @Test + void testEqualsAndHashCode() { + assertEquals(TimestampAsdfNode.of(instant), node); + assertEquals(TimestampAsdfNode.of(instant).hashCode(), node.hashCode()); + + assertNotEquals(TimestampAsdfNode.of(Instant.now().minus(1, ChronoUnit.SECONDS)), node); + assertNotEquals(TimestampAsdfNode.of(Instant.now().minus(1, ChronoUnit.SECONDS)).hashCode(), node.hashCode()); + + assertNotEquals(node, instant); + assertNotEquals(node, null); + assertEquals(node, node); + } + + @Test + void testToString() { + assertEquals(String.format("TimestampAsdfNode(value=%s)", instant), node.toString()); + } + } + + @Nested + class ConstructionFromSnakeYamlNode { + final String value = "2001-12-15T02:59:43.100Z"; + final Instant instant = Instant.parse(value); + + void testBasic() { + final ScalarNode snakeYamlNode = new ScalarNode(Tag.TIMESTAMP, value, null, null, DumperOptions.ScalarStyle.LITERAL); + final TimestampAsdfNode asdfNode = TimestampAsdfNode.of(snakeYamlNode, instant); + + assertEquals(instant, asdfNode.asInstant()); + assertEquals(snakeYamlNode.getTag().getValue(), asdfNode.getTag()); + + assertEquals(TimestampAsdfNode.of(snakeYamlNode, instant), asdfNode); + + assertEquals(String.format("TimestampAsdfNode(value=%s)", value), asdfNode.toString()); + } + + @Test + void testCustomTag() { + final Tag customTag = new Tag("custom"); + final ScalarNode snakeYamlNode = new ScalarNode(customTag, value, null, null, DumperOptions.ScalarStyle.LITERAL); + final TimestampAsdfNode asdfNode = TimestampAsdfNode.of(snakeYamlNode, instant); + + assertEquals(instant, asdfNode.asInstant()); + assertEquals(customTag.getValue(), asdfNode.getTag()); + + assertEquals(TimestampAsdfNode.of(snakeYamlNode, instant), asdfNode); + assertNotEquals(TimestampAsdfNode.of(instant), asdfNode); + + assertEquals(String.format("TimestampAsdfNode(tag=custom, value=%s)", value), asdfNode.toString()); + } + } + + @Test + void testNodeType() { + assertEquals(AsdfNodeType.TIMESTAMP, TimestampAsdfNode.of(Instant.now()).getNodeType()); + } + + @Test + void testBaseMethods() { + final TimestampAsdfNode node = TimestampAsdfNode.of(Instant.now()); + + assertFalse(node.isBoolean()); + assertFalse(node.isMapping()); + assertFalse(node.isNdArray()); + assertFalse(node.isNull()); + assertFalse(node.isNumber()); + assertFalse(node.isSequence()); + assertFalse(node.isString()); + assertTrue(node.isTimestamp()); + + assertFalse(node.containsKey("foo")); + assertFalse(node.containsKey(1L)); + assertFalse(node.containsKey(false)); + assertFalse(node.containsKey(node)); + + assertEquals(0, node.size()); + + assertFalse(node.iterator().hasNext()); + + assertThrows(IllegalStateException.class, () -> node.get("foo")); + assertThrows(IllegalStateException.class, () -> node.get(1L)); + assertThrows(IllegalStateException.class, () -> node.get(false)); + assertThrows(IllegalStateException.class, () -> node.get(node)); + + assertThrows(IllegalStateException.class, () -> node.getBigDecimal("foo")); + assertThrows(IllegalStateException.class, () -> node.getBigDecimal(1L)); + assertThrows(IllegalStateException.class, () -> node.getBigDecimal(false)); + assertThrows(IllegalStateException.class, () -> node.getBigDecimal(node)); + + assertThrows(IllegalStateException.class, () -> node.getBigInteger("foo")); + assertThrows(IllegalStateException.class, () -> node.getBigInteger(1L)); + assertThrows(IllegalStateException.class, () -> node.getBigInteger(false)); + assertThrows(IllegalStateException.class, () -> node.getBigInteger(node)); + + assertThrows(IllegalStateException.class, () -> node.getBoolean("foo")); + assertThrows(IllegalStateException.class, () -> node.getBoolean(1L)); + assertThrows(IllegalStateException.class, () -> node.getBoolean(false)); + assertThrows(IllegalStateException.class, () -> node.getBoolean(node)); + + assertThrows(IllegalStateException.class, () -> node.getByte("foo")); + assertThrows(IllegalStateException.class, () -> node.getByte(1L)); + assertThrows(IllegalStateException.class, () -> node.getByte(false)); + assertThrows(IllegalStateException.class, () -> node.getByte(node)); + + assertThrows(IllegalStateException.class, () -> node.getDouble("foo")); + assertThrows(IllegalStateException.class, () -> node.getDouble(1L)); + assertThrows(IllegalStateException.class, () -> node.getDouble(false)); + assertThrows(IllegalStateException.class, () -> node.getDouble(node)); + + assertThrows(IllegalStateException.class, () -> node.getFloat("foo")); + assertThrows(IllegalStateException.class, () -> node.getFloat(1L)); + assertThrows(IllegalStateException.class, () -> node.getFloat(false)); + assertThrows(IllegalStateException.class, () -> node.getFloat(node)); + + assertThrows(IllegalStateException.class, () -> node.getInstant("foo")); + assertThrows(IllegalStateException.class, () -> node.getInstant(1L)); + assertThrows(IllegalStateException.class, () -> node.getInstant(false)); + assertThrows(IllegalStateException.class, () -> node.getInstant(node)); + + assertThrows(IllegalStateException.class, () -> node.getInt("foo")); + assertThrows(IllegalStateException.class, () -> node.getInt(1L)); + assertThrows(IllegalStateException.class, () -> node.getInt(false)); + assertThrows(IllegalStateException.class, () -> node.getInt(node)); + + assertThrows(IllegalStateException.class, () -> node.getList("foo", String.class)); + assertThrows(IllegalStateException.class, () -> node.getList(1L, String.class)); + assertThrows(IllegalStateException.class, () -> node.getList(false, String.class)); + assertThrows(IllegalStateException.class, () -> node.getList(node, String.class)); + + assertThrows(IllegalStateException.class, () -> node.getLong("foo")); + assertThrows(IllegalStateException.class, () -> node.getLong(1L)); + assertThrows(IllegalStateException.class, () -> node.getLong(false)); + assertThrows(IllegalStateException.class, () -> node.getLong(node)); + + assertThrows(IllegalStateException.class, () -> node.getNumber("foo")); + assertThrows(IllegalStateException.class, () -> node.getNumber(1L)); + assertThrows(IllegalStateException.class, () -> node.getNumber(false)); + assertThrows(IllegalStateException.class, () -> node.getNumber(node)); + + assertThrows(IllegalStateException.class, () -> node.getMap("foo", String.class, String.class)); + assertThrows(IllegalStateException.class, () -> node.getMap(1L, String.class, String.class)); + assertThrows(IllegalStateException.class, () -> node.getMap(false, String.class, String.class)); + assertThrows(IllegalStateException.class, () -> node.getMap(node, String.class, String.class)); + + assertThrows(IllegalStateException.class, () -> node.getNdArray("foo")); + assertThrows(IllegalStateException.class, () -> node.getNdArray(1L)); + assertThrows(IllegalStateException.class, () -> node.getNdArray(false)); + assertThrows(IllegalStateException.class, () -> node.getNdArray(node)); + + assertThrows(IllegalStateException.class, () -> node.getShort("foo")); + assertThrows(IllegalStateException.class, () -> node.getShort(1L)); + assertThrows(IllegalStateException.class, () -> node.getShort(false)); + assertThrows(IllegalStateException.class, () -> node.getShort(node)); + + assertThrows(IllegalStateException.class, () -> node.getString("foo")); + assertThrows(IllegalStateException.class, () -> node.getString(1L)); + assertThrows(IllegalStateException.class, () -> node.getString(false)); + assertThrows(IllegalStateException.class, () -> node.getString(node)); + + assertThrows(IllegalStateException.class, node::asBigDecimal); + assertThrows(IllegalStateException.class, node::asBigInteger); + assertThrows(IllegalStateException.class, node::asBoolean); + assertThrows(IllegalStateException.class, node::asByte); + assertThrows(IllegalStateException.class, node::asDouble); + assertThrows(IllegalStateException.class, node::asFloat); + assertThrows(IllegalStateException.class, node::asInt); + assertThrows(IllegalStateException.class, () -> node.asList(String.class)); + assertThrows(IllegalStateException.class, node::asLong); + assertThrows(IllegalStateException.class, () -> node.asMap(String.class, String.class)); + assertThrows(IllegalStateException.class, node::asNdArray); + assertThrows(IllegalStateException.class, node::asNumber); + assertThrows(IllegalStateException.class, node::asShort); + assertThrows(IllegalStateException.class, node::asString); + } +} From 579571ac8642655ffda5c53c48b8a7844f009002 Mon Sep 17 00:00:00 2001 From: Edward Slavich Date: Sun, 6 Jul 2025 12:07:29 -0800 Subject: [PATCH 2/2] Fix bug --- .../main/java/org/asdfformat/asdf/node/impl/NumberAsdfNode.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/asdf-core/src/main/java/org/asdfformat/asdf/node/impl/NumberAsdfNode.java b/asdf-core/src/main/java/org/asdfformat/asdf/node/impl/NumberAsdfNode.java index 2b688bc..74a8a93 100644 --- a/asdf-core/src/main/java/org/asdfformat/asdf/node/impl/NumberAsdfNode.java +++ b/asdf-core/src/main/java/org/asdfformat/asdf/node/impl/NumberAsdfNode.java @@ -43,7 +43,7 @@ public static NumberAsdfNode of(final ScalarNode scalarNode, final Number value) } public static NumberAsdfNode of(final Number value) { - if (value instanceof Byte || value instanceof Short || value instanceof Integer || value instanceof BigInteger) { + if (value instanceof Byte || value instanceof Short || value instanceof Integer || value instanceof Long || value instanceof BigInteger) { return new NumberAsdfNode(Tag.INT.getValue(), value.toString(), value); } else if (value instanceof Float || value instanceof Double || value instanceof BigDecimal) { return new NumberAsdfNode(Tag.FLOAT.getValue(), value.toString(), value);