Skip to content

Commit

Permalink
Add Missing Test Cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Costigliola committed Dec 6, 2023
1 parent 35fa210 commit 8d00943
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 2 deletions.
105 changes: 105 additions & 0 deletions test/com/amazon/ionelement/MutableStructFieldsTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8d00943

Please sign in to comment.