Skip to content
This repository has been archived by the owner on Jun 14, 2024. It is now read-only.

Commit

Permalink
#14 Clean away unused test code
Browse files Browse the repository at this point in the history
  • Loading branch information
baardl committed Aug 25, 2020
1 parent 433429e commit 9450d8e
Showing 1 changed file with 1 addition and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,7 @@
import no.entra.bacnet.json.npdu.NpduParser;
import no.entra.bacnet.json.npdu.NpduResult;
import no.entra.bacnet.json.objects.PduType;
import org.json.JSONException;
import org.junit.jupiter.api.Test;
import org.skyscreamer.jsonassert.Customization;
import org.skyscreamer.jsonassert.JSONAssert;
import org.skyscreamer.jsonassert.JSONCompareMode;
import org.skyscreamer.jsonassert.comparator.CustomComparator;

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

Expand Down Expand Up @@ -62,72 +57,6 @@ void verifyConfirmedCOVNotificationSingleProperty() {
assertEquals("uncknown", JsonPath.read(observedJson, "$.configurationRequest.sender"));
assertEquals("SubscribeCov", JsonPath.read(observedJson, "$.configurationRequest.service"));
assertEquals("PresentValue", JsonPath.read(observedJson, "$.configurationRequest.observations[0].name"));
assertEquals("131109",JsonPath.read(observedJson, "$.configurationRequest.observations[0].source.deviceId"));
/*
String observedAt = JsonPath.read(observedJson, "$.configurationRequest.observations[0].observedAt");
String expectedAt = JsonPath.read(expectedJson, "$.configurationRequest.observations[0].observedAt");
assertNotNull(observedAt);
assertEquals(observedAt, expectedAt);
JSONAssert.assertEquals(expectedJson, observedJson,
new CustomComparator(JSONCompareMode.LENIENT,
new Customization("configurationRequest.observedAt", (o1, o2) -> true),
new Customization("configurationRequest.observations.observedAt", (o1, o2) -> true)
));
// JSONAssert.assertEquals(expectedJson, observedJson, new CustomComparator(JSONCompareMode.LENIENT,
// new Customization("configurationRequest.observations.observedAt", (o1, o2) -> true)));
// assertEqualsIgnoreTimestamp(expectedJson, observedJson, "observedAt");
*/
}

@Test
public void ignoringMultipleAttributesWorks() throws JSONException {
String expected = "{" +
" \"configurationRequest\": {" +
" \"observations\": [{" +
" \"observedAt\": \"2020-08-26T11:49:14.394374\"," +
" \"name\": \"PresentValue\"," +
" \"source\": {" +
" \"deviceId\": \"131109\"," +
" \"objectId\": \"0\"" +
" }," +
" \"value\": \"2e\"" +
" }]," +
" \"observedAt\":\"now\"," +
" }," +
" \"sender\": \"unknown\"," +
" \"service\": \"SubscribeCov\"" +
"}";
expected = "{\"configurationRequest\":{\"observations\":[{\"observedAt\":\"2020-08-25T12:23:02.183803\",\"name\":\"PresentValue\",\"source\":{\"deviceId\":\"131109\",\"objectId\":\"0\"},\"value\":\"2e\"}]},\"sender\":\"unknown\",\"service\":\"SubscribeCov\"}";
String actual = "{" +
" \"configurationRequest\": {" +
" \"observations\": [{" +
" \"observedAt\": \"2020-08-26T11:49:14.394374\"," +
" \"name\": \"PresentValue\"," +
" \"source\": {" +
" \"deviceId\": \"131109\"," +
" \"objectId\": \"0\"" +
" }," +
" \"value\": \"2e\"" +
" }]," +
" \"observedAt\":\"later\"," +
" }," +
" \"sender\": \"unknown\"," +
" \"service\": \"SubscribeCov\"" +
"}";
actual = "{\"configurationRequest\":{\"observations\":[{\"observedAt\":\"2020-08-25T12:23:02.183803\",\"name\":\"PresentValue\",\"source\":{\"deviceId\":\"131109\",\"objectId\":\"0\"},\"value\":\"2e\"}]},\"sender\":\"unknown\",\"service\":\"SubscribeCov\"}";

JSONAssert.assertEquals(expected, actual,
new CustomComparator(JSONCompareMode.LENIENT,
new Customization("configurationRequest.observedAt", (o1, o2) -> true),
new Customization("configurationRequest.observations.observedAt", (o1, o2) -> true)
));
}


void assertEqualsIgnoreTimestamp(String expectedJson, String observedJson, String ignoredParameter) {
JSONAssert.assertEquals(expectedJson, observedJson, new CustomComparator(JSONCompareMode.LENIENT,
new Customization(ignoredParameter, (o1, o2) -> true)));

assertEquals("131109", JsonPath.read(observedJson, "$.configurationRequest.observations[0].source.deviceId"));
}
}

0 comments on commit 9450d8e

Please sign in to comment.