forked from the-nft-company/flow-jvm-sdk
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Working on unit tests for Field, Address Field, Void Field
- Loading branch information
1 parent
0b96a4a
commit fb3c632
Showing
3 changed files
with
144 additions
and
0 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
src/test/kotlin/com/nftco/flow/sdk/cadence/fields/JsonCadenceBuilderAddressFieldTest.kt
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,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()) | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
src/test/kotlin/com/nftco/flow/sdk/cadence/fields/JsonCadenceBuilderFieldTest.kt
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,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) | ||
} |
33 changes: 33 additions & 0 deletions
33
src/test/kotlin/com/nftco/flow/sdk/cadence/fields/JsonCadenceBuilderVoidFieldTest.kt
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,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) | ||
} | ||
} |