Skip to content

Commit

Permalink
Fix enum case warning
Browse files Browse the repository at this point in the history
  • Loading branch information
courtneyeh committed Nov 16, 2023
1 parent 9230bfe commit 7dd632b
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@
public class BeaconRestApiTypes {
private static final StringValueTypeDefinition<StatusParameter> STATUS_VALUE =
DeserializableTypeDefinition.string(StatusParameter.class)
.formatter(StatusParameter::toString)
.parser(StatusParameter::valueOf)
.formatter(StatusParameter::getValue)
.parser(StatusParameter::parse)
.example("active_ongoing")
.description("ValidatorStatus string")
.format("string")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,39 @@

import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import java.util.stream.Collectors;
import tech.pegasys.teku.api.response.v1.beacon.ValidatorStatus;

@SuppressWarnings("JavaCase")
public enum StatusParameter {
pending_initialized,
pending_queued,
active_ongoing,
active_exiting,
active_slashed,
exited_unslashed,
exited_slashed,
withdrawal_possible,
withdrawal_done,
active,
pending,
exited,
withdrawal;
PENDING_INITIALIZED("pending_initialized"),
PENDING_QUEUED("pending_queued"),
ACTIVE_ONGOING("active_ongoing"),
ACTIVE_EXITING("active_exiting"),
ACTIVE_SLASHED("active_slashed"),
EXITED_UNSLASHED("exited_unslashed"),
EXITED_SLASHED("exited_slashed"),
WITHDRAWAL_POSSIBLE("withdrawal_possible"),
WITHDRAWAL_DONE("withdrawal_done"),
ACTIVE("active"),
PENDING("pending"),
EXITED("exited"),
WITHDRAWAL("withdrawal");

private final String value;

StatusParameter(final String value) {
this.value = value;
}

public String getValue() {
return value;
}

public static StatusParameter parse(final String value) {
return StatusParameter.valueOf(value.toUpperCase(Locale.ROOT));
}

public static Set<ValidatorStatus> getApplicableValidatorStatuses(
final List<StatusParameter> statusParameters) {
Expand All @@ -42,7 +56,8 @@ public static Set<ValidatorStatus> getApplicableValidatorStatuses(
statusParameter ->
Arrays.stream(ValidatorStatus.values())
.filter(
validatorStatus -> validatorStatus.name().contains(statusParameter.name())))
validatorStatus ->
validatorStatus.name().contains(statusParameter.getValue())))
.collect(Collectors.toSet());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@ void statusParameterEnumContainsAllValidatorStatuses() {
validatorStatus ->
Arrays.stream(StatusParameter.values())
.anyMatch(
statusParameter -> statusParameter.name().equals(validatorStatus.name())));
statusParameter ->
statusParameter.getValue().equals(validatorStatus.name())));
}

private static Stream<Arguments> provideStatusParameters() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
import static tech.pegasys.teku.api.response.v1.beacon.ValidatorStatus.pending_queued;
import static tech.pegasys.teku.api.response.v1.beacon.ValidatorStatus.withdrawal_done;
import static tech.pegasys.teku.api.response.v1.beacon.ValidatorStatus.withdrawal_possible;
import static tech.pegasys.teku.beaconrestapi.handlers.v1.beacon.StatusParameter.active;
import static tech.pegasys.teku.beaconrestapi.handlers.v1.beacon.StatusParameter.exited;
import static tech.pegasys.teku.beaconrestapi.handlers.v1.beacon.StatusParameter.pending;
import static tech.pegasys.teku.beaconrestapi.handlers.v1.beacon.StatusParameter.withdrawal;
import static tech.pegasys.teku.beaconrestapi.handlers.v1.beacon.StatusParameter.ACTIVE;
import static tech.pegasys.teku.beaconrestapi.handlers.v1.beacon.StatusParameter.EXITED;
import static tech.pegasys.teku.beaconrestapi.handlers.v1.beacon.StatusParameter.PENDING;
import static tech.pegasys.teku.beaconrestapi.handlers.v1.beacon.StatusParameter.WITHDRAWAL;
import static tech.pegasys.teku.infrastructure.http.HttpStatusCodes.SC_BAD_REQUEST;
import static tech.pegasys.teku.infrastructure.http.HttpStatusCodes.SC_INTERNAL_SERVER_ERROR;
import static tech.pegasys.teku.infrastructure.http.HttpStatusCodes.SC_NOT_FOUND;
Expand Down Expand Up @@ -99,9 +99,9 @@ public void shouldGetValidatorFromStateWithList() throws Exception {
new PostStateValidators.RequestBody(
List.of("1", "2"),
List.of(
StatusParameter.active_ongoing,
StatusParameter.active_exiting,
StatusParameter.withdrawal_done));
StatusParameter.ACTIVE_ONGOING,
StatusParameter.ACTIVE_EXITING,
StatusParameter.WITHDRAWAL_DONE));
final StubRestApiRequest request =
StubRestApiRequest.builder()
.metadata(handler.getMetadata())
Expand Down Expand Up @@ -212,14 +212,15 @@ void statusParameterEnumContainsAllValidatorStatuses() {
validatorStatus ->
Arrays.stream(StatusParameter.values())
.anyMatch(
statusParameter -> statusParameter.name().equals(validatorStatus.name())));
statusParameter ->
statusParameter.getValue().equals(validatorStatus.name())));
}

private static Stream<Arguments> provideStatusParameters() {
return Stream.of(
Arguments.of(List.of(active), Set.of(active_ongoing, active_exiting, active_slashed)),
Arguments.of(List.of(pending), Set.of(pending_initialized, pending_queued)),
Arguments.of(List.of(exited), Set.of(exited_slashed, exited_unslashed)),
Arguments.of(List.of(withdrawal), Set.of(withdrawal_done, withdrawal_possible)));
Arguments.of(List.of(ACTIVE), Set.of(active_ongoing, active_exiting, active_slashed)),
Arguments.of(List.of(PENDING), Set.of(pending_initialized, pending_queued)),
Arguments.of(List.of(EXITED), Set.of(exited_slashed, exited_unslashed)),
Arguments.of(List.of(WITHDRAWAL), Set.of(withdrawal_done, withdrawal_possible)));
}
}

0 comments on commit 7dd632b

Please sign in to comment.