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 |
|
31 |
1.1 |
|
33 |
1.1 |
|
37 |
1.1 |
|
38 |
1.1 |
|
40 |
1.1 |