Skip to content

Commit

Permalink
Fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
elestedt committed Sep 15, 2020
1 parent a866321 commit 4b53f81
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 4 deletions.
Expand Up @@ -22,7 +22,6 @@ public IpocsConnectionConfigXml() {
@Override
public Element store(Object o) {
Element e = new Element("connection");
log.error(o.getClass().getName());
getInstance((IpocsConnectionConfig)o);

storeCommon(e, portController);
Expand Down
Expand Up @@ -12,6 +12,7 @@
public class IpocsConnectionConfigXmlTest extends jmri.jmrix.configurexml.AbstractConnectionConfigXmlTestBase {

private IpocsPortController portController;
private IpocsConnectionConfig connConfig;

@BeforeEach
@Override
Expand All @@ -21,8 +22,10 @@ public void setUp() {
xmlAdapter = new IpocsConnectionConfigXml();
portController = mock(IpocsPortController.class);
when(portController.getOptions()).thenReturn(new String[] {});
cc = new IpocsConnectionConfig(portController);
((IpocsConnectionConfigXml)xmlAdapter).getInstance((IpocsConnectionConfig)cc);
when(portController.getDisabled()).thenReturn(true);
connConfig = mock(IpocsConnectionConfig.class);
when(connConfig.getAdapter()).thenReturn(portController);
cc = connConfig;
}

@AfterEach
Expand Down
7 changes: 6 additions & 1 deletion java/test/jmri/jmrix/ipocs/protocol/packets/PacketTest.java
@@ -1,6 +1,8 @@
package jmri.jmrix.ipocs.protocol.packets;

import static org.junit.Assert.assertNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

import java.nio.ByteBuffer;
import java.util.Random;
Expand Down Expand Up @@ -44,9 +46,12 @@ public void ackTest() {

@Test
public void parseTest() {
// Right now this cannot be tested, because ServiceLoader cannot be mocked.
// This test is not a really good one - it relies on the actual ServiceLoader.
// Could be solved by using PowerMockito:
// stackoverflow.com/questions/21105403/mocking-static-methods-with-mockito
byte[] successPacket = { ResetControllerPacket.IDENT, 0x03, 0x00 };
assertNotNull(Packet.parse(ByteBuffer.wrap(successPacket)));
assertNull(Packet.parse(ByteBuffer.wrap(testPacket)));
}

@Test
Expand Down
@@ -1,12 +1,29 @@
package jmri.jmrix.ipocs.protocol.packets;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.nio.ByteBuffer;

import org.junit.Test;

public class RequestStatusPacketTest {
private byte[] testPacket = { };

@Test
public void getIdTest() {
assertEquals(RequestStatusPacket.IDENT, new RequestStatusPacket().getId());
}

@Test
public void parseSpecificTest() {
RequestStatusPacket pkt = new RequestStatusPacket();
pkt.parseSpecific(ByteBuffer.wrap(testPacket));
}

@Test
public void serializeSpecificTest() {
RequestStatusPacket pkt = new RequestStatusPacket();
assertArrayEquals(testPacket, pkt.serializeSpecific());
}
}
@@ -1,12 +1,29 @@
package jmri.jmrix.ipocs.protocol.packets;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.nio.ByteBuffer;

import org.junit.Test;

public class ResetControllerPacketTest {
private byte[] testPacket = { };

@Test
public void getIdTest() {
assertEquals(ResetControllerPacket.IDENT, new ResetControllerPacket().getId());
}

@Test
public void parseSpecificTest() {
ResetControllerPacket pkt = new ResetControllerPacket();
pkt.parseSpecific(ByteBuffer.wrap(testPacket));
}

@Test
public void serializeSpecificTest() {
ResetControllerPacket pkt = new ResetControllerPacket();
assertArrayEquals(testPacket, pkt.serializeSpecific());
}
}

0 comments on commit 4b53f81

Please sign in to comment.