Skip to content

Commit

Permalink
fix: clarify error message when a single value is needed but fewer/mo…
Browse files Browse the repository at this point in the history
…re values are present
  • Loading branch information
ledex committed Apr 9, 2024
1 parent 53d7504 commit a1c2fcf
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 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

0 comments on commit a1c2fcf

Please sign in to comment.