-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added equals & hashcode method to ModbusTCPMaster & TCPMasterConnecti…
…on (#127) Co-authored-by: SimpleJack <ts.simplejack@gmail.com>
- Loading branch information
1 parent
8a024c8
commit f0f25b2
Showing
4 changed files
with
111 additions
and
1 deletion.
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
51 changes: 51 additions & 0 deletions
51
src/test/java/com/ghgande/j2mod/modbus/TestModbusTCPMasterEquality.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,51 @@ | ||
package com.ghgande.j2mod.modbus; | ||
|
||
import com.ghgande.j2mod.modbus.facade.ModbusTCPMaster; | ||
import com.ghgande.j2mod.modbus.utils.AbstractTestModbusTCPMaster; | ||
import org.junit.Test; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import static org.hamcrest.CoreMatchers.equalTo; | ||
import static org.hamcrest.CoreMatchers.not; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.junit.Assert.*; | ||
|
||
/** | ||
* Testing class for {@link ModbusTCPMaster#equals} & {@link ModbusTCPMaster#hashCode} methods | ||
*/ | ||
public class TestModbusTCPMasterEquality extends AbstractTestModbusTCPMaster { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(AbstractTestModbusTCPMaster.class); | ||
public static final String LOCALHOST_2 = "127.0.0.2"; | ||
public static final int PORT_2 = 2503; | ||
protected static ModbusTCPMaster master_2, master_3; | ||
|
||
@Test | ||
public void testEquality() { | ||
master_2 = new ModbusTCPMaster(LOCALHOST_2, PORT); | ||
master_3 = new ModbusTCPMaster(LOCALHOST, PORT_2); | ||
|
||
assertThat("2 unequal Modbus TCP masters identified as equal", master, not(equalTo(master_2))); | ||
assertThat("2 unequal Modbus TCP masters identified as equal", master, not(equalTo(master_3))); | ||
assertThat("2 unequal Modbus TCP masters identified as equal", master_2, not(equalTo(master_3))); | ||
|
||
assertThat("2 equal Modbus TCP masters identified as unequal", master, equalTo(master)); | ||
assertThat("2 equal Modbus TCP masters identified as unequal", master_2, equalTo(master_2)); | ||
assertThat("2 equal Modbus TCP masters identified as unequal", master_3, equalTo(master_3)); | ||
} | ||
|
||
@Test | ||
public void testHashCode() { | ||
master_2 = new ModbusTCPMaster(LOCALHOST_2, PORT); | ||
master_3 = new ModbusTCPMaster(LOCALHOST, PORT_2); | ||
|
||
assertThat("2 unequal Modbus TCP masters had same hash code", master.hashCode(), not(equalTo(master_2.hashCode()))); | ||
assertThat("2 unequal Modbus TCP masters had same hash code", master.hashCode(), not(equalTo(master_3.hashCode()))); | ||
assertThat("2 unequal Modbus TCP masters had same hash code", master_2.hashCode(), not(equalTo(master_3.hashCode()))); | ||
|
||
assertThat("2 equal Modbus TCP masters had NOT same hash code", master.hashCode(), equalTo(master.hashCode())); | ||
assertThat("2 equal Modbus TCP masters had NOT same hash code", master_2.hashCode(), equalTo(master_2.hashCode())); | ||
assertThat("2 equal Modbus TCP masters had NOT same hash code", master_3.hashCode(), equalTo(master_3.hashCode())); | ||
} | ||
} |