-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tested and fixed ModbusSerializationCatcher
- Loading branch information
1 parent
6d733c7
commit 417dfc7
Showing
2 changed files
with
46 additions
and
2 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
33 changes: 33 additions & 0 deletions
33
.../test/java/me/retrodaredevil/solarthing/program/check/ModbusSerializationCatcherTest.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,33 @@ | ||
package me.retrodaredevil.solarthing.program.check; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import me.retrodaredevil.io.modbus.ModbusMessages; | ||
import me.retrodaredevil.io.modbus.handling.ErrorCodeException; | ||
import me.retrodaredevil.solarthing.util.JacksonUtil; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
class ModbusSerializationCatcherTest { | ||
|
||
@Test | ||
void test() throws JsonProcessingException { | ||
ObjectMapper modbusCatchingMapper = JacksonUtil.defaultMapper(); | ||
modbusCatchingMapper.registerModule(ModbusSerializationCatcher.createModule(TestObject.class)); | ||
assertEquals("{\"test1\":5,\"test2\":5,\"test3\":\"Modbus Exception: 2\"}", modbusCatchingMapper.writeValueAsString(new TestObject())); | ||
} | ||
|
||
private static class TestObject { | ||
@JsonProperty | ||
private int test1 = 5; | ||
@JsonProperty | ||
private int test2 = 5; | ||
|
||
@JsonProperty | ||
private int getTest3() { | ||
throw new ErrorCodeException(ModbusMessages.createMessage(131, new int[0]), 3, 2); | ||
} | ||
} | ||
} |