18045010223
2025-07-07 0d3a683a0c97154b1f2e6657398664537e4e3e82
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package org.yzh.protocol;
 
import io.netty.buffer.ByteBufUtil;
import io.netty.buffer.Unpooled;
import org.junit.jupiter.api.Test;
import org.yzh.protocol.basics.JTMessage;
 
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
 
/**
 * JT/T HEX单元测试类
 * @author yezhihao
 * https://gitee.com/yezhihao/jt808-server
 */
public class TestHex {
 
    @Test
    public void testHex() throws Exception {
        try (BufferedReader reader = reader("target/test-classes/JT808.txt")) {
            reader.lines().filter(hex -> !hex.isEmpty()).forEach(hex -> BeanTest.selfCheck(hex));
        }
    }
 
    @Test
    public void testSubpackage() throws Exception {
        try (BufferedReader reader = reader("target/test-classes/JT1078.txt")) {
            reader.lines().filter(hex -> !hex.isEmpty()).forEach(hex -> {
                JTMessage message = BeanTest.coder.decode(Unpooled.wrappedBuffer(ByteBufUtil.decodeHexDump(hex)));
                if (message != null)
                    System.out.println(BeanTest.gson.toJson(message));
            });
        }
    }
 
    public static BufferedReader reader(String path) throws FileNotFoundException {
        return new BufferedReader(new InputStreamReader(new FileInputStream(path), StandardCharsets.UTF_8));
    }
}