From 8d00943077ddb4a9e806d250378c752d0dc62b34 Mon Sep 17 00:00:00 2001 From: Tom Costigliola Date: Wed, 6 Dec 2023 13:30:00 -0500 Subject: [PATCH] Add Missing Test Cases --- .../ionelement/MutableStructFieldsTests.kt | 105 ++++++++++++++++++ .../demos/java/MutableStructFieldsDemo.java | 2 - 2 files changed, 105 insertions(+), 2 deletions(-) diff --git a/test/com/amazon/ionelement/MutableStructFieldsTests.kt b/test/com/amazon/ionelement/MutableStructFieldsTests.kt index b9c6ace..42afb10 100644 --- a/test/com/amazon/ionelement/MutableStructFieldsTests.kt +++ b/test/com/amazon/ionelement/MutableStructFieldsTests.kt @@ -216,6 +216,111 @@ class MutableStructFieldsTests { assertEquals(expected, updated) } + @Test + fun testClear() { + val mutableFields = testStruct.mutableFields() + mutableFields.clear() + + assertEquals(emptyIonStruct(), ionStructOf(mutableFields)) + assertTrue(mutableFields.size == 0) + assertFalse(mutableFields.iterator().hasNext()) + } + + @Test + fun testClearField() { + val mutableFields = testStruct.mutableFields() + mutableFields.clearField("author") + + val expected = testStruct.update { + removeAll( + listOf( + field( + "author", + buildStruct { + add("lastname", ionString("Doe")) + add("firstname", ionString("Jane")) + } + ), + field( + "author", + buildStruct { + add("lastname", ionString("Smith")) + add("firstname", ionString("Jane")) + } + ) + ) + ) + } + + assertEquals(expected, ionStructOf(mutableFields)) + } + + @Test + fun testContains() { + val mutableFields = testStruct.mutableFields() + + assertTrue( + mutableFields.contains( + field( + "author", + buildStruct { + add("lastname", ionString("Doe")) + add("firstname", ionString("Jane")) + } + ) + ) + ) + + assertFalse(mutableFields.contains(field("foo", ionString("bar")))) + } + + @Test + fun testContainsAll() { + val mutableFields = testStruct.mutableFields() + + assertTrue( + mutableFields.containsAll( + listOf( + field( + "author", + buildStruct { + add("lastname", ionString("Doe")) + add("firstname", ionString("Jane")) + } + ), + field( + "author", + buildStruct { + add("lastname", ionString("Smith")) + add("firstname", ionString("Jane")) + } + ) + ) + ) + ) + + assertFalse( + mutableFields.containsAll( + listOf( + field("foo", ionString("bar")), + field("isbn", ionString("123-456-789")) + ) + ) + ) + } + + @Test + fun testIsEmpty() { + val mutableFields = testStruct.mutableFields() + + assertFalse(mutableFields.isEmpty()) + + mutableFields.clear() + + assertTrue(mutableFields.isEmpty()) + assertTrue(emptyIonStruct().mutableFields().isEmpty()) + } + @Test fun testIterator() { val mutableFields = testStruct.mutableFields() diff --git a/test/com/amazon/ionelement/demos/java/MutableStructFieldsDemo.java b/test/com/amazon/ionelement/demos/java/MutableStructFieldsDemo.java index 6036982..af96eb1 100644 --- a/test/com/amazon/ionelement/demos/java/MutableStructFieldsDemo.java +++ b/test/com/amazon/ionelement/demos/java/MutableStructFieldsDemo.java @@ -3,13 +3,11 @@ import com.amazon.ionelement.api.Ion; import com.amazon.ionelement.api.StructElement; import kotlin.Unit; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import static com.amazon.ionelement.api.ElementLoader.loadSingleElement; import static org.junit.jupiter.api.Assertions.assertEquals; -@Disabled public class MutableStructFieldsDemo { @Test