Skip to content

Commit

Permalink
Add isDisabled to ConsulFactory
Browse files Browse the repository at this point in the history
Closes #122
  • Loading branch information
sleberknight committed Aug 8, 2023
1 parent 23168b3 commit 6ade436
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ public void setEnabled(boolean enabled) {
this.enabled = enabled;
}

@JsonIgnore
public boolean isDisabled() {
return !isEnabled();
}

@JsonProperty
public HostAndPort getEndpoint() {
return endpoint;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;

import io.dropwizard.util.Duration;

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

import org.junit.jupiter.api.Test;

import java.util.List;
Expand Down Expand Up @@ -61,6 +64,27 @@ void testSetServiceName() {
assertThat(consulFactory.getServiceName()).isEqualTo(serviceName);
}

@Test
void shouldBeEnabledByDefault() {
var consulFactory = new ConsulFactory();

assertAll(
() -> assertThat(consulFactory.isEnabled()).isTrue(),
() -> assertThat(consulFactory.isDisabled()).isFalse()
);
}

@Test
void shouldAllowDisabling() {
var consulFactory = new ConsulFactory();
consulFactory.setEnabled(false);

assertAll(
() -> assertThat(consulFactory.isEnabled()).isFalse(),
() -> assertThat(consulFactory.isDisabled()).isTrue()
);
}

private ConsulFactory createFullyPopulatedConsulFactory() {
var consulFactory = new ConsulFactory();
consulFactory.setServiceName("serviceName");
Expand Down

0 comments on commit 6ade436

Please sign in to comment.