From 41165b358a0fe49d25c80489917d8348d5da7655 Mon Sep 17 00:00:00 2001 From: Scott Leberknight <174812+sleberknight@users.noreply.github.com> Date: Thu, 17 Aug 2023 21:32:55 -0400 Subject: [PATCH] Fix DeleteOptions#isRecurse Fixes #263 --- .../consul/option/DeleteOptions.java | 2 +- .../consul/option/DeleteOptionsTest.java | 32 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 src/test/java/org/kiwiproject/consul/option/DeleteOptionsTest.java diff --git a/src/main/java/org/kiwiproject/consul/option/DeleteOptions.java b/src/main/java/org/kiwiproject/consul/option/DeleteOptions.java index 16c17a9..125c9dd 100644 --- a/src/main/java/org/kiwiproject/consul/option/DeleteOptions.java +++ b/src/main/java/org/kiwiproject/consul/option/DeleteOptions.java @@ -20,7 +20,7 @@ public abstract class DeleteOptions implements ParamAdder { @Value.Derived public boolean isRecurse() { - return getRecurse().isPresent(); + return getRecurse().orElse(false); } @Override diff --git a/src/test/java/org/kiwiproject/consul/option/DeleteOptionsTest.java b/src/test/java/org/kiwiproject/consul/option/DeleteOptionsTest.java new file mode 100644 index 0000000..5a67e8d --- /dev/null +++ b/src/test/java/org/kiwiproject/consul/option/DeleteOptionsTest.java @@ -0,0 +1,32 @@ +package org.kiwiproject.consul.option; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; + +@DisplayName("DeleteOptions") +class DeleteOptionsTest { + + @Nested + class IsRecurse { + + @Test + void shouldReturnFalse_WhenGetRecurseReturnsEmptyOptional() { + var deleteOptions = ImmutableDeleteOptions.builder().build(); + assertThat(deleteOptions.getRecurse()).isEmpty(); + assertThat(deleteOptions.isRecurse()).isFalse(); + } + + @ParameterizedTest + @ValueSource(booleans = { true, false }) + void shouldReturnExpectedValue_WhenGetRecurseReturnsOptionalWithValue(boolean recurse) { + var deleteOptions = ImmutableDeleteOptions.builder().recurse(recurse).build(); + assertThat(deleteOptions.getRecurse()).contains(recurse); + assertThat(deleteOptions.isRecurse()).isEqualTo(recurse); + } + } +}