Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: clarify error message in TooManyValueExeption #21

Merged
merged 2 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
}
}
Loading