Skip to content

Commit

Permalink
Merge pull request #21 from telekom/fix/misleading-error-in-TooManyVa…
Browse files Browse the repository at this point in the history
…lueExeption

fix: clarify error message in TooManyValueExeption
  • Loading branch information
ledex authored Apr 9, 2024
2 parents 53d7504 + 086bfb4 commit 1f6a1b2
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// SPDX-FileCopyrightText: 2024 Deutsche Telekom AG
//
// SPDX-License-Identifier: Apache-2.0

package de.telekom.jsonfilter.exception;

public class NoSingleValueException extends Exception {

public NoSingleValueException(String jsonPath, int numberOfActualResults) {
super("The evaluation of \"" + jsonPath + "\" did not return a single value. Expected 1 value, got " + numberOfActualResults + ".");
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import com.jayway.jsonpath.InvalidPathException;
import com.jayway.jsonpath.JsonPath;
import com.jayway.jsonpath.internal.path.PathCompiler;
import de.telekom.jsonfilter.exception.TooManyValueExeption;
import de.telekom.jsonfilter.exception.NoSingleValueException;
import de.telekom.jsonfilter.operator.EvaluationResult;
import de.telekom.jsonfilter.operator.Operator;
import de.telekom.jsonfilter.operator.ValidationResult;
Expand Down Expand Up @@ -54,12 +54,12 @@ public EvaluationResult evaluate(String json) {

abstract EvaluationResult compare(String json, String jsonPath, T expectedValue);

protected Comparable<T> getActualValue(String json, String jsonPath) throws TooManyValueExeption {
protected Comparable<T> getActualValue(String json, String jsonPath) throws NoSingleValueException {
var valueList = getActualValues(json, jsonPath);
if (valueList.size() == 1) {
return valueList.getFirst();
} else {
throw new TooManyValueExeption(jsonPath, valueList.size());
throw new NoSingleValueException(jsonPath, valueList.size());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import de.telekom.jsonfilter.operator.EvaluationResult;


public class EqualsOperator<T> extends ComparisonOperator<T> {

public EqualsOperator(String jsonPath, T expectedValue) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,6 @@ void tooManyActualValuesShouldReturnError() throws URISyntaxException, IOExcepti
EvaluationResult result = operator.evaluate(payload.toString());

assertFalse(result.isMatch());
assertEquals("An exception occurred during the evaluation: \nThe evaluation of \"$..type\" contained too many values. Expected 1, got 2.", result.getCauseDescription());
assertEquals("An exception occurred during the evaluation: \nThe evaluation of \"$..type\" did not return a single value. Expected 1 value, got 2.", result.getCauseDescription());
}
}

0 comments on commit 1f6a1b2

Please sign in to comment.