Skip to content

Commit

Permalink
SMHE-2524: Add unit test
Browse files Browse the repository at this point in the history
Signed-off-by: stefanermens <[email protected]>
  • Loading branch information
stefanermens committed Feb 13, 2025
1 parent 7fde6f0 commit 7324fb0
Showing 1 changed file with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,37 @@ void testDecodingFailsForOneAttribute() throws Exception {
""");
}

@Test
void testReadingAttributesFails() throws Exception {
final DataObject objListElementForKnownObject =
this.createObjectListElement(CLASS_ID_REGISTER, VERSION_0, KNOWN_OBIS, NO_OF_ATTR_REGISTER);
final DataObject objectList = DataObject.newArrayData(List.of(objListElementForKnownObject));
final GetResultImpl getResultObjectList =
new GetResultImpl(objectList, AccessResultCode.SUCCESS);

when(this.connectionManager.getConnection().get(any(AttributeAddress.class)))
.thenReturn(getResultObjectList);

when(this.connectionManager.getConnection().get(ArgumentMatchers.anyList()))
.thenThrow(new IOException());

final String result = this.executor.execute(this.connectionManager, DEVICE, null, MSG_METADATA);

assertThat(this.replaceNewLinesWithSystemNewLines(result))
.isEqualToIgnoringNewLines(
"""
[ {
"description" : "Active energy import (+A)",
"dlmsClass" : "REGISTER",
"version" : 0,
"obis" : "1.0.1.8.0.255",
"note" : "Failed reading attributes",
"attributes" : [ ],
"class-id" : 3
} ]
""");
}

private static DlmsDevice createDevice(final Protocol protocol) {
final DlmsDevice device = new DlmsDevice();
device.setProtocol(protocol);
Expand Down

0 comments on commit 7324fb0

Please sign in to comment.