-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Include property name/value when serialization fails
- Loading branch information
Showing
7 changed files
with
135 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package org.eclipse.yasson; | ||
|
||
import static org.junit.Assert.fail; | ||
|
||
import java.util.function.Function; | ||
import java.util.function.Supplier; | ||
|
||
import javax.json.bind.JsonbException; | ||
|
||
public class Assertions { | ||
|
||
/** | ||
* Asserts that the given operation will fail with a JsonbException | ||
* @param operation The operation that is expected to fail | ||
*/ | ||
public static void shouldFail(Supplier<?> operation) { | ||
shouldFail(operation, JsonbException.class, msg -> true); | ||
} | ||
|
||
public static void shouldFail(Runnable operation) { | ||
shouldFail(() -> { | ||
operation.run(); | ||
return null; | ||
}); | ||
} | ||
|
||
/** | ||
* Asserts that the given operation will fail with a JsonbException | ||
* @param operation The operation that is expected to fail | ||
* @param checkExceptionMessage Any checks that should be made on the exception message. For example, ensuring the exception | ||
* includes a specific token. | ||
*/ | ||
public static void shouldFail(Supplier<?> operation, Function<String,Boolean> checkExceptionMessage) { | ||
shouldFail(operation, JsonbException.class, checkExceptionMessage); | ||
} | ||
|
||
/** | ||
* Asserts that the given operation will fail | ||
* @param operation The operation that is expected to fail | ||
* @param expectedType The expected exception type to receive when evaluating the operation | ||
* @param checkExceptionMessage Any checks that should be made on the exception message. For example, ensuring the exception | ||
* includes a specific token. | ||
*/ | ||
public static void shouldFail(Supplier<?> operation, Class<? extends Throwable> expectedType, Function<String,Boolean> checkExceptionMessage) { | ||
try { | ||
operation.get(); | ||
fail("The operation should have failed with a " + expectedType.getCanonicalName() + " but it succeeded."); | ||
} catch (Throwable t) { | ||
String fullErrorMessage = t.getMessage(); | ||
for (Throwable current = t; current.getCause() != null && current.getCause() != current; current = current.getCause()) { | ||
fullErrorMessage += current.getMessage(); | ||
} | ||
if (expectedType.isAssignableFrom(t.getClass())) { | ||
if (!checkExceptionMessage.apply(fullErrorMessage)) { | ||
t.printStackTrace(); | ||
fail("Exception did not contain the proper content: " + fullErrorMessage); | ||
} | ||
} else { | ||
t.printStackTrace(); | ||
fail("Expected to get an exception of " + expectedType + " but instead was " + t.getClass()); | ||
} | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters