Add Suntech encoder test

This commit is contained in:
Anton Tananaev
2026-06-02 05:47:35 -07:00
parent 711f86373d
commit f94cd73fa7
3 changed files with 33 additions and 4 deletions

View File

@@ -353,14 +353,14 @@ public class ProtocolTest extends BaseTest {
verifyFrame(expected, encoder.encodeCommand(command));
}
protected void verifyCommand(
BaseProtocolEncoder encoder, BaseProtocolDecoder decoder, Command command, ByteBuf expected) {
protected Object encodeCommand(
BaseProtocolEncoder encoder, BaseProtocolDecoder decoder, Command command) {
var pipeline = mock(ChannelPipeline.class);
when(pipeline.iterator()).thenReturn(
List.<Map.Entry<String, ChannelHandler>>of(Map.entry("decoder", decoder)).iterator());
var channel = mock(Channel.class);
when(channel.pipeline()).thenReturn(pipeline);
verifyFrame(expected, encoder.encodeCommand(channel, command));
return encoder.encodeCommand(channel, command);
}
protected void verifyFrame(ByteBuf expected, Object object) {

View File

@@ -16,7 +16,9 @@ public class Jt808ProtocolEncoderTest extends ProtocolTest {
command.setDeviceId(1);
command.setType(Command.TYPE_ENGINE_STOP);
verifyCommand(encoder, decoder, command, binary("7e810500010b3a73ce2ff20000f0247e"));
verifyFrame(
binary("7e810500010b3a73ce2ff20000f0247e"),
encodeCommand(encoder, decoder, command));
}

View File

@@ -0,0 +1,27 @@
package org.traccar.protocol;
import org.junit.jupiter.api.Test;
import org.traccar.ProtocolTest;
import org.traccar.model.Command;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class SuntechProtocolEncoderTest extends ProtocolTest {
@Test
public void testEncode() throws Exception {
var decoder = inject(new SuntechProtocolDecoder(null));
var encoder = inject(new SuntechProtocolEncoder(null));
Command command = new Command();
command.setDeviceId(1);
command.setType(Command.TYPE_REBOOT_DEVICE);
assertEquals(
"SA200CMD;123456789012345;02;Reboot\r",
encodeCommand(encoder, decoder, command));
}
}