Skip to content

Commit

Permalink
Working on unit tests for Field, Address Field, Void Field
Browse files Browse the repository at this point in the history
  • Loading branch information
lealobanov committed Jan 25, 2024
1 parent 0b96a4a commit fb3c632
Show file tree
Hide file tree
Showing 3 changed files with 144 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.nftco.flow.sdk.cadence.fields

import com.nftco.flow.sdk.cadence.AddressField
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertNotEquals
import org.junit.jupiter.api.Test

class JsonCadenceBuilderAddressFieldTest {

@Test
fun `Test equality for AddressField with the same value`() {
val address1 = AddressField("0x123")
val address2 = AddressField("0x123")
assertEquals(address1, address2)
assertEquals(address1.hashCode(), address2.hashCode())
}

@Test
fun `Test equality for AddressField with different values`() {
val address1 = AddressField("0x123")
val address2 = AddressField("0x456")
assertNotEquals(address1, address2)
assertNotEquals(address1.hashCode(), address2.hashCode())
}

@Test
fun `Test equality for AddressField with lowercase value`() { // need to investigate this case
val address1 = AddressField("0xABC")
val address2 = AddressField("0xabc")
assertEquals(address1, address2)
assertEquals(address1.hashCode(), address2.hashCode())
}

@Test
fun `Test equality for AddressField with bytes`() {
val bytes = byteArrayOf(1, 2, 3)
val address1 = AddressField(bytes)
val address2 = AddressField("0x010203")
assertEquals(address1, address2)
assertEquals(address1.hashCode(), address2.hashCode())
}

@Test
fun `Test equality for AddressField with bytes and different values`() {
val bytes = byteArrayOf(1, 2, 3)
val address1 = AddressField(bytes)
val address2 = AddressField("0x040506")
assertNotEquals(address1, address2)
assertNotEquals(address1.hashCode(), address2.hashCode())
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.nftco.flow.sdk.cadence.fields

import com.nftco.flow.sdk.cadence.Field
import com.nftco.flow.sdk.cadence.TYPE_INT
import com.nftco.flow.sdk.cadence.TYPE_STRING
import org.junit.jupiter.api.Assertions.assertFalse
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Test

class JsonCadenceBuilderFieldTest {
@Test
fun `Test equality for Field with the same type and value`() {
val field1 = SampleField(TYPE_STRING, "value")
val field2 = SampleField(TYPE_STRING, "value")
assertTrue(field1 == field2)
assertTrue(field1.hashCode() == field2.hashCode())
}

@Test
fun `Test equality for Field with different values`() {
val field1 = SampleField(TYPE_STRING, "value1")
val field2 = SampleField(TYPE_STRING, "value2")
assertFalse(field1 == field2)
assertFalse(field1.hashCode() == field2.hashCode())
}

@Test
fun `Test equality for Field with different types`() {
val field1 = SampleField(TYPE_STRING, "value")
val field2 = SampleField(TYPE_INT, 42)
assertFalse(field1 == field2)
assertFalse(field1.hashCode() == field2.hashCode())
}

@Test
fun `Test equality for Field with null values`() {
val field1 = SampleField(TYPE_STRING, null)
val field2 = SampleField(TYPE_STRING, null)
assertTrue(field1 == field2)
assertTrue(field1.hashCode() == field2.hashCode())
}

@Test
fun `Test equality for Field with null value and non-null value`() {
val field1 = SampleField(TYPE_STRING, null)
val field2 = SampleField(TYPE_STRING, "value")
assertFalse(field1 == field2)
assertFalse(field1.hashCode() == field2.hashCode())
}

@Test
fun `Test equality for Field with different types and values`() {
val field1 = SampleField(TYPE_STRING, "value")
val field2 = SampleField(TYPE_INT, 42)
assertFalse(field1 == field2)
assertFalse(field1.hashCode() == field2.hashCode())
}

private class SampleField(type: String, value: Any?) : Field<Any>(type, value)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.nftco.flow.sdk.cadence.fields

import com.nftco.flow.sdk.cadence.*
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertNotEquals
import org.junit.jupiter.api.Test

class JsonCadenceBuilderVoidFieldTest {

@Test
fun `Test equality of VoidField instances`() {
val voidField1 = VoidField()
val voidField2 = VoidField()

assertEquals(voidField1, voidField2)
}

@Test
fun `Test hashing of VoidField instances`() {
val voidField1 = VoidField()
val voidField2 = VoidField()

assertEquals(voidField1.hashCode(), voidField2.hashCode())
}

@Test
fun `Test equality with other Field types`() {
val voidField = VoidField()
val stringField = StringField("test")

assertNotEquals(voidField, stringField)
}
}

0 comments on commit fb3c632

Please sign in to comment.