From c3e438ca3fe73857a6e85178c64019a0063c435a Mon Sep 17 00:00:00 2001 From: mmauksch Date: Thu, 17 Aug 2023 13:33:05 +0200 Subject: [PATCH] validate via test and use suggested fix from #231 --- .../ocpp/model/core/StopTransactionRequest.java | 2 +- .../model/test/StopTransactionRequestTest.java | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/StopTransactionRequest.java b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/StopTransactionRequest.java index 1f46b0c62..58f707a37 100644 --- a/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/StopTransactionRequest.java +++ b/ocpp-v1_6/src/main/java/eu/chargetime/ocpp/model/core/StopTransactionRequest.java @@ -103,7 +103,7 @@ public String getIdTag() { */ @XmlElement public void setIdTag(String idTag) { - if (!ModelUtil.validate(idTag, 20)) { + if (idTag != null && !ModelUtil.validate(idTag, 20)) { throw new PropertyConstraintException(idTag.length(), "Exceeded limit of 20 chars"); } diff --git a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/test/StopTransactionRequestTest.java b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/test/StopTransactionRequestTest.java index 2f2734ad1..559ff95fb 100644 --- a/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/test/StopTransactionRequestTest.java +++ b/ocpp-v1_6/src/test/java/eu/chargetime/ocpp/model/test/StopTransactionRequestTest.java @@ -75,6 +75,20 @@ public void setIdTag_moreThan20Chars_throwsPropertyConstraintException() { request.setIdTag(aString(42)); } + @Test + public void setIdTag_nullGiven_doesNotRaiseException() { + request.setIdTag(null); + Assert.assertNull(request.getIdTag()); + } + @Test + public void setIdTag_nullGiven_passesValidation() { + request.setMeterStop(2); + request.setTransactionId(5); + request.setTimestamp(ZonedDateTime.now()); + request.setIdTag(null); + Assert.assertTrue(request.validate()); + } + @Test public void setMeterStop_anInteger_meterStopIsSet() { // Given