-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added equals and hashcode to models. Updated/Added unit tests.
- Loading branch information
Showing
8 changed files
with
378 additions
and
13 deletions.
There are no files selected for viewing
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
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
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
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
74 changes: 74 additions & 0 deletions
74
src/test/java/com/github/wkennedy/abi/models/DecodedFunctionsTest.java
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,74 @@ | ||
package com.github.wkennedy.abi.models; | ||
|
||
import com.github.wkennedy.abi.models.DecodedFunctions; | ||
import com.github.wkennedy.abi.models.Param; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collections; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
public class DecodedFunctionsTest { | ||
|
||
@Test | ||
void testEquals_sameObject_ReturnsTrue() { | ||
DecodedFunctions decodedFunctions1 = new DecodedFunctions("function1", Collections.emptyList()); | ||
assertTrue(decodedFunctions1.equals(decodedFunctions1)); | ||
} | ||
|
||
@Test | ||
void testEquals_sameValues_ReturnsTrue() { | ||
DecodedFunctions decodedFunctions1 = new DecodedFunctions("function1", Collections.emptyList()); | ||
DecodedFunctions decodedFunctions2 = new DecodedFunctions("function1", Collections.emptyList()); | ||
assertTrue(decodedFunctions1.equals(decodedFunctions2)); | ||
} | ||
|
||
@Test | ||
void testEquals_differentNames_ReturnsFalse() { | ||
DecodedFunctions decodedFunctions1 = new DecodedFunctions("function1", Collections.emptyList()); | ||
DecodedFunctions decodedFunctions2 = new DecodedFunctions("function2", Collections.emptyList()); | ||
assertFalse(decodedFunctions1.equals(decodedFunctions2)); | ||
} | ||
|
||
@Test | ||
void testEquals_differentParams_ReturnsFalse() { | ||
Param param1 = new Param("param1", "type1", "value"); | ||
Param param2 = new Param("param2", "type1", "value"); | ||
|
||
DecodedFunctions decodedFunctions1 = new DecodedFunctions("function1", Arrays.asList(param1)); | ||
DecodedFunctions decodedFunctions2 = new DecodedFunctions("function1", Arrays.asList(param2)); | ||
|
||
assertFalse(decodedFunctions1.equals(decodedFunctions2)); | ||
} | ||
|
||
@Test | ||
void testEquals_nullObject_ReturnsFalse() { | ||
DecodedFunctions decodedFunctions1 = new DecodedFunctions("function1", Collections.emptyList()); | ||
assertFalse(decodedFunctions1.equals(null)); | ||
} | ||
|
||
@Test | ||
void testEquals_nonDecodedFunctionsObject_ReturnsFalse() { | ||
DecodedFunctions decodedFunctions1 = new DecodedFunctions("function1", Collections.emptyList()); | ||
assertFalse(decodedFunctions1.equals("Not a DecodedFunctions object")); | ||
} | ||
|
||
@Test | ||
void testEquals_differentNestedDecodedFunctions_ReturnsFalse() { | ||
DecodedFunctions decodedFunctions1 = new DecodedFunctions("function1", Collections.emptyList()); | ||
DecodedFunctions decodedFunctions2 = new DecodedFunctions("function1", Collections.emptyList()); | ||
|
||
DecodedFunctions nestedDecodedFunctions = new DecodedFunctions("nestedFunction", Collections.emptyList()); | ||
decodedFunctions1.addNestedDecodedFunction(nestedDecodedFunctions); | ||
|
||
assertFalse(decodedFunctions1.equals(decodedFunctions2)); | ||
} | ||
|
||
@Test | ||
void testHashCode_sameValues_ReturnsSameHashCode() { | ||
DecodedFunctions decodedFunctions1 = new DecodedFunctions("function1", Collections.emptyList()); | ||
DecodedFunctions decodedFunctions2 = new DecodedFunctions("function1", Collections.emptyList()); | ||
assertEquals(decodedFunctions1.hashCode(), decodedFunctions2.hashCode()); | ||
} | ||
} |
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
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,87 @@ | ||
|
||
package com.github.wkennedy.abi.models; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
class LogTest { | ||
|
||
@Test | ||
public void equals_sameObject_returnsTrue() { | ||
List<String> topics = new ArrayList<>(); | ||
topics.add("topic1"); | ||
Log log1 = new Log("data", topics, "address"); | ||
assertTrue(log1.equals(log1)); | ||
} | ||
|
||
@Test | ||
public void equals_nullObject_returnsFalse() { | ||
List<String> topics = new ArrayList<>(); | ||
topics.add("topic1"); | ||
Log log1 = new Log("data", topics, "address"); | ||
assertFalse(log1.equals(null)); | ||
} | ||
|
||
@Test | ||
public void equals_differentTypeObject_returnsFalse() { | ||
List<String> topics = new ArrayList<>(); | ||
topics.add("topic1"); | ||
Log log1 = new Log("data", topics, "address"); | ||
assertFalse(log1.equals("String")); | ||
} | ||
|
||
@Test | ||
public void equals_sameValueObject_returnsTrue() { | ||
List<String> topics1 = new ArrayList<>(); | ||
topics1.add("topic1"); | ||
Log log1 = new Log("data", topics1, "address"); | ||
|
||
List<String> topics2 = new ArrayList<>(); | ||
topics2.add("topic1"); | ||
Log log2 = new Log("data", topics2, "address"); | ||
|
||
assertTrue(log1.equals(log2)); | ||
} | ||
|
||
@Test | ||
public void equals_differentValueObject_returnsFalse() { | ||
List<String> topics1 = new ArrayList<>(); | ||
topics1.add("topic1"); | ||
Log log1 = new Log("data", topics1, "address"); | ||
|
||
List<String> topics2 = new ArrayList<>(); | ||
topics2.add("topic2"); | ||
Log log2 = new Log("data", topics2, "address"); | ||
|
||
assertFalse(log1.equals(log2)); | ||
} | ||
@Test | ||
public void hashCode_sameValueObjects_returnSameHashcode() { | ||
List<String> topics1 = new ArrayList<>(); | ||
topics1.add("topic1"); | ||
Log log1 = new Log("data", topics1, "address"); | ||
|
||
List<String> topics2 = new ArrayList<>(); | ||
topics2.add("topic1"); | ||
Log log2 = new Log("data", topics2, "address"); | ||
|
||
assertEquals(log1.hashCode(), log2.hashCode()); | ||
} | ||
|
||
@Test | ||
public void hashCode_differentValueObjects_returnDifferentHashcode() { | ||
List<String> topics1 = new ArrayList<>(); | ||
topics1.add("topic1"); | ||
Log log1 = new Log("data", topics1, "address"); | ||
|
||
List<String> topics2 = new ArrayList<>(); | ||
topics2.add("topic2"); | ||
Log log2 = new Log("data", topics2, "address"); | ||
|
||
assertNotEquals(log1.hashCode(), log2.hashCode()); | ||
} | ||
} |
Oops, something went wrong.