StakeKeyLengthValidator.java

1
package org.cardanofoundation.explorer.api.controller.validation;
2
3
import jakarta.validation.ConstraintValidator;
4
import jakarta.validation.ConstraintValidatorContext;
5
6
import org.springframework.beans.factory.annotation.Value;
7
8
import org.apache.logging.log4j.util.Strings;
9
10
import org.cardanofoundation.explorer.api.common.constant.CommonConstant;
11
import org.cardanofoundation.explorer.api.common.constant.CommonConstant.NetworkType;
12
13
public class StakeKeyLengthValidator implements ConstraintValidator<StakeKeyLengthValid, String> {
14
15
  @Value("${application.network}")
16
  private String network;
17
18
  @Override
19
  public void initialize(StakeKeyLengthValid constraintAnnotation) {
20 1 1. initialize : removed call to jakarta/validation/ConstraintValidator::initialize → SURVIVED
    ConstraintValidator.super.initialize(constraintAnnotation);
21
  }
22
23
  @Override
24
  public boolean isValid(String value, ConstraintValidatorContext context) {
25
    int length = this.getStakeKeyLengthByNetwork(network);
26
    if (Strings.isBlank(value) || value.length() != length) {
27
      context
28
          .buildConstraintViolationWithTemplate(
29
              "The expected length of the hash is " + length + " characters")
30
          .addConstraintViolation();
31 1 1. isValid : replaced boolean return with true for org/cardanofoundation/explorer/api/controller/validation/StakeKeyLengthValidator::isValid → NO_COVERAGE
      return false;
32
    }
33 1 1. isValid : replaced boolean return with false for org/cardanofoundation/explorer/api/controller/validation/StakeKeyLengthValidator::isValid → KILLED
    return true;
34
  }
35
36
  private int getStakeKeyLengthByNetwork(String network) {
37 1 1. getStakeKeyLengthByNetwork : negated conditional → KILLED
    if (network.equals(NetworkType.MAINNET)) {
38 1 1. getStakeKeyLengthByNetwork : replaced int return with 0 for org/cardanofoundation/explorer/api/controller/validation/StakeKeyLengthValidator::getStakeKeyLengthByNetwork → NO_COVERAGE
      return CommonConstant.STAKE_KEY_LENGTH_MAINNET;
39
    } else {
40 1 1. getStakeKeyLengthByNetwork : replaced int return with 0 for org/cardanofoundation/explorer/api/controller/validation/StakeKeyLengthValidator::getStakeKeyLengthByNetwork → KILLED
      return CommonConstant.STAKE_KEY_LENGTH_TESTNET;
41
    }
42
  }
43
}

Mutations

20

1.1
Location : initialize
Killed by : none
removed call to jakarta/validation/ConstraintValidator::initialize → SURVIVED

31

1.1
Location : isValid
Killed by : none
replaced boolean return with true for org/cardanofoundation/explorer/api/controller/validation/StakeKeyLengthValidator::isValid → NO_COVERAGE

33

1.1
Location : isValid
Killed by : org.cardanofoundation.explorer.api.controller.StakeKeyControllerTest.[engine:junit-jupiter]/[class:org.cardanofoundation.explorer.api.controller.StakeKeyControllerTest]/[method:testGetStakeRewardAnalytics_thenReturn()]
replaced boolean return with false for org/cardanofoundation/explorer/api/controller/validation/StakeKeyLengthValidator::isValid → KILLED

37

1.1
Location : getStakeKeyLengthByNetwork
Killed by : org.cardanofoundation.explorer.api.controller.StakeKeyControllerTest.[engine:junit-jupiter]/[class:org.cardanofoundation.explorer.api.controller.StakeKeyControllerTest]/[method:testGetStakeRewardAnalytics_thenReturn()]
negated conditional → KILLED

38

1.1
Location : getStakeKeyLengthByNetwork
Killed by : none
replaced int return with 0 for org/cardanofoundation/explorer/api/controller/validation/StakeKeyLengthValidator::getStakeKeyLengthByNetwork → NO_COVERAGE

40

1.1
Location : getStakeKeyLengthByNetwork
Killed by : org.cardanofoundation.explorer.api.controller.StakeKeyControllerTest.[engine:junit-jupiter]/[class:org.cardanofoundation.explorer.api.controller.StakeKeyControllerTest]/[method:testGetStakeRewardAnalytics_thenReturn()]
replaced int return with 0 for org/cardanofoundation/explorer/api/controller/validation/StakeKeyLengthValidator::getStakeKeyLengthByNetwork → KILLED

Active mutators

Tests examined


Report generated by PIT 1.14.2