Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ of this software and associated documentation files (the "Software"), to deal
SOFTWARE.
*/

import eu.chargetime.ocpp.PropertyConstraintException;
import eu.chargetime.ocpp.model.RequestWithId;
import eu.chargetime.ocpp.utilities.MoreObjects;
import java.time.ZonedDateTime;
Expand Down Expand Up @@ -107,6 +108,10 @@ public Integer getRetries() {
*/
@XmlElement
public void setRetries(Integer retries) {
if (retries < 0) {
throw new PropertyConstraintException(retries, "retries must be >= 0");
}

this.retries = retries;
}

Expand All @@ -128,6 +133,10 @@ public Integer getRetryInterval() {
*/
@XmlElement
public void setRetryInterval(Integer retryInterval) {
if (retryInterval < 0) {
throw new PropertyConstraintException(retryInterval, "retryInterval must be >= 0");
}

this.retryInterval = retryInterval;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ public Integer getRetries() {
*/
@XmlElement
public void setRetries(int retries) {
if (retries <= 0) {
throw new PropertyConstraintException(retries, "retries must be > 0");
if (retries < 0) {
throw new PropertyConstraintException(retries, "retries must be >= 0");
}

this.retries = retries;
Expand Down Expand Up @@ -157,8 +157,8 @@ public Integer getRetryInterval() {
*/
@XmlElement
public void setRetryInterval(int retryInterval) {
if (retryInterval <= 0) {
throw new PropertyConstraintException(retryInterval, "retryInterval must be > 0");
if (retryInterval < 0) {
throw new PropertyConstraintException(retryInterval, "retryInterval must be >= 0");
}

this.retryInterval = retryInterval;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,23 @@ of this software and associated documentation files (the "Software"), to deal
SOFTWARE.
*/

import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;

import eu.chargetime.ocpp.PropertyConstraintException;
import eu.chargetime.ocpp.model.firmware.GetDiagnosticsRequest;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

public class GetDiagnosticsRequestTest {

@Rule
public ExpectedException thrownException = ExpectedException.none();

private GetDiagnosticsRequest request;

@Before
Expand Down Expand Up @@ -62,4 +70,54 @@ public void validate_locationIsSet_returnsTrue() {
// Then
assertThat(result, is(true));
}

@Test
public void setRetries_asPositive_isAccepted() {
request.setRetries(42);

assertThat(request.getRetries(), equalTo(42));
}

@Test
public void setRetries_asZero_isAccepted() {
request.setRetries(0);

assertThat(request.getRetries(), equalTo(0));
}

@Test
public void setRetries_asNegative_throwsPropertyConstraintException() {
int retries = -42;
thrownException.expect(instanceOf(PropertyConstraintException.class));
thrownException.expectMessage(
equalTo("Validation failed: [retries must be >= 0]. Current Value: [" + retries + "]"));

request.setRetries(retries);
}

@Test
public void setRetryInterval_asPositive_isAccepted() {
request.setRetryInterval(42);

assertThat(request.getRetryInterval(), equalTo(42));
}

@Test
public void setRetryInterval_asZero_isAccepted() {
request.setRetryInterval(0);

assertThat(request.getRetryInterval(), equalTo(0));
}

@Test
public void setRetryInterval_asNegative_throwsPropertyConstraintException() {
int retryInterval = -42;
thrownException.expect(instanceOf(PropertyConstraintException.class));
thrownException.expectMessage(
equalTo("Validation failed: [retryInterval must be >= 0]. Current Value: ["
+ retryInterval
+ "]"));

request.setRetryInterval(retryInterval);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,11 @@ public void validate_locationAndRetrieveDateIsSet_returnsTrue() {

@Test
public void setRetries_asNegative_throwsPropertyConstraintException() {
testInvalidRetries(-42);
}

@Test
public void setRetries_asZero_throwsPropertyConstraintException() {
testInvalidRetries(0);
}

private void testInvalidRetries(int retryInvalidRetries) {
int retries = -42;
defineThrownException(
"Validation failed: [retries must be > 0]. Current Value: [" + retryInvalidRetries + "]");
"Validation failed: [retries must be >= 0]. Current Value: [" + retries + "]");

request.setRetries(retryInvalidRetries);
request.setRetries(retries);
}

private void defineThrownException(String expectedExceptionMessage) {
Expand All @@ -117,22 +109,21 @@ public void setRetries_asPositive_isAccepted() {
}

@Test
public void setRetryInterval_asNegative_throwsPropertyConstraintException() {
testInvalidRetryInterval(-42);
}
public void setRetries_asZero_isAccepted() {
request.setRetries(0);

@Test
public void setRetryInterval_asZero_throwsPropertyConstraintException() {
testInvalidRetryInterval(0);
assertThat(request.getRetries(), equalTo(0));
}

private void testInvalidRetryInterval(int invalidRetryValue) {
@Test
public void setRetryInterval_asNegative_throwsPropertyConstraintException() {
int retryInterval = -42;
defineThrownException(
"Validation failed: [retryInterval must be > 0]. Current Value: ["
+ invalidRetryValue
"Validation failed: [retryInterval must be >= 0]. Current Value: ["
+ retryInterval
+ "]");

request.setRetryInterval(invalidRetryValue);
request.setRetryInterval(retryInterval);
}

@Test
Expand All @@ -141,4 +132,11 @@ public void setRetryInterval_asPositive_isAccepted() {

assertThat(request.getRetryInterval(), equalTo(42));
}

@Test
public void setRetryInterval_asZero_isAccepted() {
request.setRetryInterval(0);

assertThat(request.getRetryInterval(), equalTo(0));
}
}
Loading