diff --git a/src/main/java/io/skelp/verifier/AbstractCustomVerifier.java b/src/main/java/io/skelp/verifier/AbstractCustomVerifier.java index 2881c1a..b85ffa0 100644 --- a/src/main/java/io/skelp/verifier/AbstractCustomVerifier.java +++ b/src/main/java/io/skelp/verifier/AbstractCustomVerifier.java @@ -192,7 +192,7 @@ public V equalTo(final Object other, final Object name) { final T value = verification.getValue(); final boolean result = isEqualTo(value, other); - verification.check(result, MessageKeys.EQUAL_TO, name); + verification.report(result, MessageKeys.EQUAL_TO, name); return chain(); } @@ -202,7 +202,7 @@ public V equalToAny(final Object... others) { final T value = verification.getValue(); final boolean result = matchAny(others, input -> isEqualTo(value, input)); - verification.check(result, MessageKeys.EQUAL_TO_ANY, (Object) others); + verification.report(result, MessageKeys.EQUAL_TO_ANY, (Object) others); return chain(); } @@ -212,7 +212,7 @@ public V hashedAs(final int hashCode) { final T value = verification.getValue(); final boolean result = value != null && value.hashCode() == hashCode; - verification.check(result, MessageKeys.HASHED_AS, hashCode); + verification.report(result, MessageKeys.HASHED_AS, hashCode); return chain(); } @@ -221,7 +221,7 @@ public V hashedAs(final int hashCode) { public V instanceOf(final Class cls) { final boolean result = cls != null && cls.isInstance(verification.getValue()); - verification.check(result, MessageKeys.INSTANCE_OF, cls); + verification.report(result, MessageKeys.INSTANCE_OF, cls); return chain(); } @@ -231,7 +231,7 @@ public V instanceOfAll(final Class... classes) { final T value = verification.getValue(); final boolean result = value != null && matchAll(classes, input -> input != null && input.isInstance(value)); - verification.check(result, MessageKeys.INSTANCE_OF_ALL, (Object) classes); + verification.report(result, MessageKeys.INSTANCE_OF_ALL, (Object) classes); return chain(); } @@ -241,7 +241,7 @@ public V instanceOfAny(final Class... classes) { final T value = verification.getValue(); final boolean result = value != null && matchAny(classes, input -> input != null && input.isInstance(value)); - verification.check(result, MessageKeys.INSTANCE_OF_ANY, (Object) classes); + verification.report(result, MessageKeys.INSTANCE_OF_ANY, (Object) classes); return chain(); } @@ -276,7 +276,7 @@ public V not() { public V nulled() { final boolean result = verification.getValue() == null; - verification.check(result, MessageKeys.NULLED); + verification.report(result, MessageKeys.NULLED); return chain(); } @@ -290,7 +290,7 @@ public V sameAs(final Object other) { public V sameAs(final Object other, final Object name) { final boolean result = verification.getValue() == other; - verification.check(result, MessageKeys.SAME_AS, name); + verification.report(result, MessageKeys.SAME_AS, name); return chain(); } @@ -300,7 +300,7 @@ public V sameAsAny(final Object... others) { final T value = verification.getValue(); final boolean result = matchAny(others, input -> value == input); - verification.check(result, MessageKeys.SAME_AS_ANY, (Object) others); + verification.report(result, MessageKeys.SAME_AS_ANY, (Object) others); return chain(); } @@ -317,7 +317,7 @@ public V that(final VerifierAssertion assertion, final MessageKey key, final final boolean result = assertion.verify(verification.getValue()); - verification.check(result, key, args); + verification.report(result, key, args); return chain(); } @@ -329,7 +329,7 @@ public V that(final VerifierAssertion assertion, final String message, final final boolean result = assertion.verify(verification.getValue()); - verification.check(result, message, args); + verification.report(result, message, args); return chain(); } diff --git a/src/main/java/io/skelp/verifier/CustomVerifierProvider.java b/src/main/java/io/skelp/verifier/CustomVerifierProvider.java index ac13e0d..7ac7eea 100644 --- a/src/main/java/io/skelp/verifier/CustomVerifierProvider.java +++ b/src/main/java/io/skelp/verifier/CustomVerifierProvider.java @@ -29,6 +29,16 @@ * Provides {@link CustomVerifier} instances to be used to verify custom data types based on their class and the current * {@link Verification}. *

+ *

+ * {@code CustomVerifierProviders} are registered via Java's SPI, so in order to register a custom + * {@code CustomVerifierProvider} projects should contain should create a + * {@code io.skelp.verifier.CustomVerifierProvider} file within {@code META-INF/services} listing the class reference + * for each custom {@code CustomVerifierProvider} (e.g. {@code com.example.verifier.MyCustomCustomVerifierProvider}) on + * separate lines. {@code CustomVerifierProviders} are also {@link Weighted}, which means that they are loaded in + * priority order (the lower the weight, the higher the priority). Verifier has a built-in default + * {@code CustomVerifierProvider} which is given a low priority (i.e. {@value #DEFAULT_IMPLEMENTATION_WEIGHT}) to allow + * custom implementations to be easily ordered around it. + *

* * @author Alasdair Mercer * @since 0.2.0 diff --git a/src/main/java/io/skelp/verifier/message/AbstractMessageSource.java b/src/main/java/io/skelp/verifier/message/AbstractMessageSource.java index c3efdd6..67d37ef 100644 --- a/src/main/java/io/skelp/verifier/message/AbstractMessageSource.java +++ b/src/main/java/io/skelp/verifier/message/AbstractMessageSource.java @@ -290,7 +290,7 @@ public Formatter getFormatter(final Object obj) { } @Override - public String getMessage(final Verification verification, final MessageKey key, final Object... args) { + public String getMessage(final Verification verification, final MessageKey key, final Object[] args) { final String formattedMessage = getMessageInternal(key, args, verification); if (formattedMessage != null) { return buildMessage(formattedMessage, verification); @@ -305,7 +305,7 @@ public String getMessage(final Verification verification, final MessageKey ke } @Override - public String getMessage(final Verification verification, final String message, final Object... args) { + public String getMessage(final Verification verification, final String message, final Object[] args) { final String formattedMessage = getMessageInternal(message, args, verification); if (formattedMessage != null) { return buildMessage(formattedMessage, verification); @@ -317,7 +317,7 @@ public String getMessage(final Verification verification, final String messag /** *

- * Called internally by {@link #getMessage(Verification, MessageKey, Object...)} to handle the actual logic of + * Called internally by {@link #getMessage(Verification, MessageKey, Object[])} to handle the actual logic of * looking up a message based on the specified {@code key} and potentially formatting it using the optional format * {@code args} provided. *

@@ -342,7 +342,7 @@ public String getMessage(final Verification verification, final String messag * @throws IllegalArgumentException * If the resolved message is formatted but is an invalid format pattern or any of the format {@code args} * are invalid for their placeholders. - * @see #getMessage(Verification, MessageKey, Object...) + * @see #getMessage(Verification, MessageKey, Object[]) */ protected String getMessageInternal(final MessageKey key, final Object[] args, final Verification verification) { if (key == null) { @@ -366,7 +366,7 @@ protected String getMessageInternal(final MessageKey key, final Object[] args, f /** *

- * Called internally by {@link #getMessage(Verification, String, Object...)} to handle the actual logic of + * Called internally by {@link #getMessage(Verification, String, Object[])} to handle the actual logic of * potentially formatting {@code message} using the optional format {@code args} provided. *

*

@@ -388,7 +388,7 @@ protected String getMessageInternal(final MessageKey key, final Object[] args, f * @throws IllegalArgumentException * If {@code message} is formatted but is an invalid format pattern or any of the format {@code args} are * invalid for their placeholders. - * @see #getMessage(Verification, String, Object...) + * @see #getMessage(Verification, String, Object[]) */ protected String getMessageInternal(final String message, final Object[] args, final Verification verification) { if (message == null) { diff --git a/src/main/java/io/skelp/verifier/message/MessageSource.java b/src/main/java/io/skelp/verifier/message/MessageSource.java index b261738..6ef836b 100644 --- a/src/main/java/io/skelp/verifier/message/MessageSource.java +++ b/src/main/java/io/skelp/verifier/message/MessageSource.java @@ -76,7 +76,7 @@ public interface MessageSource { * @throws NoSuchMessageException * If no message could be found for {@code key} or any other that is required to build the full message. */ - String getMessage(Verification verification, MessageKey key, Object... args); + String getMessage(Verification verification, MessageKey key, Object[] args); /** *

@@ -102,5 +102,5 @@ public interface MessageSource { * @throws NoSuchMessageException * If no message could be found for any keys that are required to build the full message. */ - String getMessage(Verification verification, String message, Object... args); + String getMessage(Verification verification, String message, Object[] args); } diff --git a/src/main/java/io/skelp/verifier/message/MessageSourceProvider.java b/src/main/java/io/skelp/verifier/message/MessageSourceProvider.java index 023ab97..02d1418 100644 --- a/src/main/java/io/skelp/verifier/message/MessageSourceProvider.java +++ b/src/main/java/io/skelp/verifier/message/MessageSourceProvider.java @@ -28,6 +28,16 @@ *

* Provides {@link MessageSource} instances to be used to retrieve localized and/or formatted messages. *

+ *

+ * {@code MessageSourceProviders} are registered via Java's SPI, so in order to register a custom + * {@code MessageSourceProvider} projects should contain should create a + * {@code io.skelp.verifier.verification.message.MessageSourceProvider} file within {@code META-INF/services} listing + * the class reference for each custom {@code MessageSourceProvider} (e.g. + * {@code com.example.verifier.MyCustomMessageSourceProvider}) on separate lines. {@code MessageSourceProviders} are + * also {@link Weighted}, which means that they are loaded in priority order (the lower the weight, the higher the + * priority). Verifier has a built-in default {@code MessageSourceProvider} which is given a low priority (i.e. + * {@value #DEFAULT_IMPLEMENTATION_WEIGHT}) to allow custom implementations to be easily ordered around it. + *

* * @author Alasdair Mercer * @since 0.2.0 diff --git a/src/main/java/io/skelp/verifier/message/formatter/Formatter.java b/src/main/java/io/skelp/verifier/message/formatter/Formatter.java index 6697b18..f36565e 100644 --- a/src/main/java/io/skelp/verifier/message/formatter/Formatter.java +++ b/src/main/java/io/skelp/verifier/message/formatter/Formatter.java @@ -31,6 +31,12 @@ * {@code Formatters} can choose which types of objects that they support to allow other implementations to provide more * precise formatting for that type as only one {@code Formatter} will be used for a single instance. *

+ *

+ * {@code Formatters} are registered via Java's SPI, so in order to register a custom {@code Formatter} projects should + * contain should create a {@code io.skelp.verifier.message.formatter.Formatter} file within {@code META-INF/services} + * listing the class reference for each custom {@code Formatter} (e.g. {@code com.example.verifier.MyCustomFormatter}) + * on separate lines. + *

* * @author Alasdair Mercer * @since 0.2.0 diff --git a/src/main/java/io/skelp/verifier/message/locale/DefaultLocaleContextProvider.java b/src/main/java/io/skelp/verifier/message/locale/DefaultLocaleContextProvider.java index 73ae1f1..6c2d26a 100644 --- a/src/main/java/io/skelp/verifier/message/locale/DefaultLocaleContextProvider.java +++ b/src/main/java/io/skelp/verifier/message/locale/DefaultLocaleContextProvider.java @@ -33,7 +33,7 @@ * @see Locale#getDefault() * @since 0.2.0 */ -public class DefaultLocaleContextProvider implements LocaleContextProvider { +public final class DefaultLocaleContextProvider implements LocaleContextProvider { @Override public LocaleContext getLocaleContext() { diff --git a/src/main/java/io/skelp/verifier/message/locale/LocaleContextProvider.java b/src/main/java/io/skelp/verifier/message/locale/LocaleContextProvider.java index b15bd2d..0bea6e4 100644 --- a/src/main/java/io/skelp/verifier/message/locale/LocaleContextProvider.java +++ b/src/main/java/io/skelp/verifier/message/locale/LocaleContextProvider.java @@ -28,6 +28,16 @@ *

* Provides {@link LocaleContext} instances to be used to localize messages. *

+ *

+ * {@code LocaleContextProviders} are registered via Java's SPI, so in order to register a custom + * {@code LocaleContextProvider} projects should contain should create a + * {@code io.skelp.verifier.verification.message.locale.LocaleContextProvider} file within {@code META-INF/services} + * listing the class reference for each custom {@code LocaleContextProvider} (e.g. + * {@code com.example.verifier.MyCustomLocaleContextProvider}) on separate lines. {@code LocaleContextProviders} are + * also {@link Weighted}, which means that they are loaded in priority order (the lower the weight, the higher the + * priority). Verifier has a built-in default {@code LocaleContextProvider} which is given a low priority (i.e. + * {@value #DEFAULT_IMPLEMENTATION_WEIGHT}) to allow custom implementations to be easily ordered around it. + *

* * @author Alasdair Mercer * @since 0.2.0 diff --git a/src/main/java/io/skelp/verifier/message/locale/SimpleLocaleContext.java b/src/main/java/io/skelp/verifier/message/locale/SimpleLocaleContext.java index b327f99..a661e81 100644 --- a/src/main/java/io/skelp/verifier/message/locale/SimpleLocaleContext.java +++ b/src/main/java/io/skelp/verifier/message/locale/SimpleLocaleContext.java @@ -33,7 +33,7 @@ * @see Locale#getDefault() * @since 0.2.0 */ -public class SimpleLocaleContext implements LocaleContext { +public final class SimpleLocaleContext implements LocaleContext { private final Locale locale; diff --git a/src/main/java/io/skelp/verifier/type/BigDecimalVerifier.java b/src/main/java/io/skelp/verifier/type/BigDecimalVerifier.java index e58721b..c448fa8 100644 --- a/src/main/java/io/skelp/verifier/type/BigDecimalVerifier.java +++ b/src/main/java/io/skelp/verifier/type/BigDecimalVerifier.java @@ -60,7 +60,7 @@ public BigDecimalVerifier even() { final BigDecimal value = verification().getValue(); final boolean result = value != null && !value.stripTrailingZeros().unscaledValue().testBit(0); - verification().check(result, BaseNumberVerifier.MessageKeys.EVEN); + verification().report(result, BaseNumberVerifier.MessageKeys.EVEN); return this; } @@ -70,7 +70,7 @@ public BigDecimalVerifier falsy() { final BigDecimal value = verification().getValue(); final boolean result = value == null || value.compareTo(BigDecimal.ZERO) == 0; - verification().check(result, BaseTruthVerifier.MessageKeys.FALSY); + verification().report(result, BaseTruthVerifier.MessageKeys.FALSY); return this; } @@ -80,7 +80,7 @@ public BigDecimalVerifier negative() { final BigDecimal value = verification().getValue(); final boolean result = value != null && value.compareTo(BigDecimal.ZERO) < 0; - verification().check(result, BaseNumberVerifier.MessageKeys.NEGATIVE); + verification().report(result, BaseNumberVerifier.MessageKeys.NEGATIVE); return this; } @@ -90,7 +90,7 @@ public BigDecimalVerifier odd() { final BigDecimal value = verification().getValue(); final boolean result = value != null && value.stripTrailingZeros().unscaledValue().testBit(0); - verification().check(result, BaseNumberVerifier.MessageKeys.ODD); + verification().report(result, BaseNumberVerifier.MessageKeys.ODD); return this; } @@ -100,7 +100,7 @@ public BigDecimalVerifier one() { final BigDecimal value = verification().getValue(); final boolean result = value != null && value.compareTo(BigDecimal.ONE) == 0; - verification().check(result, BaseNumberVerifier.MessageKeys.ONE); + verification().report(result, BaseNumberVerifier.MessageKeys.ONE); return this; } @@ -110,7 +110,7 @@ public BigDecimalVerifier positive() { final BigDecimal value = verification().getValue(); final boolean result = value != null && value.compareTo(BigDecimal.ZERO) >= 0; - verification().check(result, BaseNumberVerifier.MessageKeys.POSITIVE); + verification().report(result, BaseNumberVerifier.MessageKeys.POSITIVE); return this; } @@ -120,7 +120,7 @@ public BigDecimalVerifier truthy() { final BigDecimal value = verification().getValue(); final boolean result = value != null && value.compareTo(BigDecimal.ONE) == 0; - verification().check(result, BaseTruthVerifier.MessageKeys.TRUTHY); + verification().report(result, BaseTruthVerifier.MessageKeys.TRUTHY); return this; } @@ -130,7 +130,7 @@ public BigDecimalVerifier zero() { final BigDecimal value = verification().getValue(); final boolean result = value != null && value.compareTo(BigDecimal.ZERO) == 0; - verification().check(result, BaseNumberVerifier.MessageKeys.ZERO); + verification().report(result, BaseNumberVerifier.MessageKeys.ZERO); return this; } diff --git a/src/main/java/io/skelp/verifier/type/BigIntegerVerifier.java b/src/main/java/io/skelp/verifier/type/BigIntegerVerifier.java index e0b03b5..abd5132 100644 --- a/src/main/java/io/skelp/verifier/type/BigIntegerVerifier.java +++ b/src/main/java/io/skelp/verifier/type/BigIntegerVerifier.java @@ -60,7 +60,7 @@ public BigIntegerVerifier even() { final BigInteger value = verification().getValue(); final boolean result = value != null && !value.testBit(0); - verification().check(result, BaseNumberVerifier.MessageKeys.EVEN); + verification().report(result, BaseNumberVerifier.MessageKeys.EVEN); return this; } @@ -70,7 +70,7 @@ public BigIntegerVerifier falsy() { final BigInteger value = verification().getValue(); final boolean result = value == null || value.compareTo(BigInteger.ZERO) == 0; - verification().check(result, BaseTruthVerifier.MessageKeys.FALSY); + verification().report(result, BaseTruthVerifier.MessageKeys.FALSY); return this; } @@ -80,7 +80,7 @@ public BigIntegerVerifier negative() { final BigInteger value = verification().getValue(); final boolean result = value != null && value.compareTo(BigInteger.ZERO) < 0; - verification().check(result, BaseNumberVerifier.MessageKeys.NEGATIVE); + verification().report(result, BaseNumberVerifier.MessageKeys.NEGATIVE); return this; } @@ -90,7 +90,7 @@ public BigIntegerVerifier odd() { final BigInteger value = verification().getValue(); final boolean result = value != null && value.testBit(0); - verification().check(result, BaseNumberVerifier.MessageKeys.ODD); + verification().report(result, BaseNumberVerifier.MessageKeys.ODD); return this; } @@ -100,7 +100,7 @@ public BigIntegerVerifier one() { final BigInteger value = verification().getValue(); final boolean result = value != null && value.compareTo(BigInteger.ONE) == 0; - verification().check(result, BaseNumberVerifier.MessageKeys.ONE); + verification().report(result, BaseNumberVerifier.MessageKeys.ONE); return this; } @@ -110,7 +110,7 @@ public BigIntegerVerifier positive() { final BigInteger value = verification().getValue(); final boolean result = value != null && value.compareTo(BigInteger.ZERO) >= 0; - verification().check(result, BaseNumberVerifier.MessageKeys.POSITIVE); + verification().report(result, BaseNumberVerifier.MessageKeys.POSITIVE); return this; } @@ -120,7 +120,7 @@ public BigIntegerVerifier truthy() { final BigInteger value = verification().getValue(); final boolean result = value != null && value.compareTo(BigInteger.ONE) == 0; - verification().check(result, BaseTruthVerifier.MessageKeys.TRUTHY); + verification().report(result, BaseTruthVerifier.MessageKeys.TRUTHY); return this; } @@ -130,7 +130,7 @@ public BigIntegerVerifier zero() { final BigInteger value = verification().getValue(); final boolean result = value != null && value.compareTo(BigInteger.ZERO) == 0; - verification().check(result, BaseNumberVerifier.MessageKeys.ZERO); + verification().report(result, BaseNumberVerifier.MessageKeys.ZERO); return this; } diff --git a/src/main/java/io/skelp/verifier/type/BooleanVerifier.java b/src/main/java/io/skelp/verifier/type/BooleanVerifier.java index 42d020a..1d08d3d 100644 --- a/src/main/java/io/skelp/verifier/type/BooleanVerifier.java +++ b/src/main/java/io/skelp/verifier/type/BooleanVerifier.java @@ -55,7 +55,7 @@ public BooleanVerifier(final Verification verification) { public BooleanVerifier falsy() { final boolean result = !Boolean.TRUE.equals(verification().getValue()); - verification().check(result, BaseTruthVerifier.MessageKeys.FALSY); + verification().report(result, BaseTruthVerifier.MessageKeys.FALSY); return this; } @@ -64,7 +64,7 @@ public BooleanVerifier falsy() { public BooleanVerifier truthy() { final boolean result = Boolean.TRUE.equals(verification().getValue()); - verification().check(result, BaseTruthVerifier.MessageKeys.TRUTHY); + verification().report(result, BaseTruthVerifier.MessageKeys.TRUTHY); return this; } diff --git a/src/main/java/io/skelp/verifier/type/ByteVerifier.java b/src/main/java/io/skelp/verifier/type/ByteVerifier.java index d2bdcd7..5dc05d4 100644 --- a/src/main/java/io/skelp/verifier/type/ByteVerifier.java +++ b/src/main/java/io/skelp/verifier/type/ByteVerifier.java @@ -58,7 +58,7 @@ public ByteVerifier even() { final Byte value = verification().getValue(); final boolean result = value != null && value % 2 == 0; - verification().check(result, BaseNumberVerifier.MessageKeys.EVEN); + verification().report(result, BaseNumberVerifier.MessageKeys.EVEN); return this; } @@ -68,7 +68,7 @@ public ByteVerifier falsy() { final Byte value = verification().getValue(); final boolean result = value == null || value == 0; - verification().check(result, BaseTruthVerifier.MessageKeys.FALSY); + verification().report(result, BaseTruthVerifier.MessageKeys.FALSY); return this; } @@ -78,7 +78,7 @@ public ByteVerifier negative() { final Byte value = verification().getValue(); final boolean result = value != null && value < 0; - verification().check(result, BaseNumberVerifier.MessageKeys.NEGATIVE); + verification().report(result, BaseNumberVerifier.MessageKeys.NEGATIVE); return this; } @@ -88,7 +88,7 @@ public ByteVerifier odd() { final Byte value = verification().getValue(); final boolean result = value != null && value % 2 != 0; - verification().check(result, BaseNumberVerifier.MessageKeys.ODD); + verification().report(result, BaseNumberVerifier.MessageKeys.ODD); return this; } @@ -98,7 +98,7 @@ public ByteVerifier one() { final Byte value = verification().getValue(); final boolean result = value != null && value == 1; - verification().check(result, BaseNumberVerifier.MessageKeys.ONE); + verification().report(result, BaseNumberVerifier.MessageKeys.ONE); return this; } @@ -108,7 +108,7 @@ public ByteVerifier positive() { final Byte value = verification().getValue(); final boolean result = value != null && value >= 0; - verification().check(result, BaseNumberVerifier.MessageKeys.POSITIVE); + verification().report(result, BaseNumberVerifier.MessageKeys.POSITIVE); return this; } @@ -118,7 +118,7 @@ public ByteVerifier truthy() { final Byte value = verification().getValue(); final boolean result = value != null && value == 1; - verification().check(result, BaseTruthVerifier.MessageKeys.TRUTHY); + verification().report(result, BaseTruthVerifier.MessageKeys.TRUTHY); return this; } @@ -128,7 +128,7 @@ public ByteVerifier zero() { final Byte value = verification().getValue(); final boolean result = value != null && value == 0; - verification().check(result, BaseNumberVerifier.MessageKeys.ZERO); + verification().report(result, BaseNumberVerifier.MessageKeys.ZERO); return this; } diff --git a/src/main/java/io/skelp/verifier/type/CharacterVerifier.java b/src/main/java/io/skelp/verifier/type/CharacterVerifier.java index 277305a..f7f94b5 100644 --- a/src/main/java/io/skelp/verifier/type/CharacterVerifier.java +++ b/src/main/java/io/skelp/verifier/type/CharacterVerifier.java @@ -91,7 +91,7 @@ public CharacterVerifier alpha() { final Character value = verification().getValue(); final boolean result = value != null && Character.isLetter(value); - verification().check(result, MessageKeys.ALPHA); + verification().report(result, MessageKeys.ALPHA); return this; } @@ -118,7 +118,7 @@ public CharacterVerifier alphanumeric() { final Character value = verification().getValue(); final boolean result = value != null && Character.isLetterOrDigit(value); - verification().check(result, MessageKeys.ALPHANUMERIC); + verification().report(result, MessageKeys.ALPHANUMERIC); return this; } @@ -144,7 +144,7 @@ public CharacterVerifier ascii() { final Character value = verification().getValue(); final boolean result = value != null && value < 128; - verification().check(result, MessageKeys.ASCII); + verification().report(result, MessageKeys.ASCII); return this; } @@ -171,7 +171,7 @@ public CharacterVerifier asciiAlpha() { final Character value = verification().getValue(); final boolean result = value != null && isAsciiAlpha(value); - verification().check(result, MessageKeys.ASCII_ALPHA); + verification().report(result, MessageKeys.ASCII_ALPHA); return this; } @@ -200,7 +200,7 @@ public CharacterVerifier asciiAlphaLowerCase() { final Character value = verification().getValue(); final boolean result = value != null && isAsciiAlphaLowerCase(value); - verification().check(result, MessageKeys.ASCII_ALPHA_LOWER_CASE); + verification().report(result, MessageKeys.ASCII_ALPHA_LOWER_CASE); return this; } @@ -229,7 +229,7 @@ public CharacterVerifier asciiAlphaUpperCase() { final Character value = verification().getValue(); final boolean result = value != null && isAsciiAlphaUpperCase(value); - verification().check(result, MessageKeys.ASCII_ALPHA_UPPER_CASE); + verification().report(result, MessageKeys.ASCII_ALPHA_UPPER_CASE); return this; } @@ -256,7 +256,7 @@ public CharacterVerifier asciiAlphanumeric() { final Character value = verification().getValue(); final boolean result = value != null && (isAsciiAlpha(value) || isAsciiNumeric(value)); - verification().check(result, MessageKeys.ASCII_ALPHANUMERIC); + verification().report(result, MessageKeys.ASCII_ALPHANUMERIC); return this; } @@ -282,7 +282,7 @@ public CharacterVerifier asciiControl() { final Character value = verification().getValue(); final boolean result = value != null && (value < 32 || value == 127); - verification().check(result, MessageKeys.ASCII_CONTROL); + verification().report(result, MessageKeys.ASCII_CONTROL); return this; } @@ -309,7 +309,7 @@ public CharacterVerifier asciiNumeric() { final Character value = verification().getValue(); final boolean result = value != null && isAsciiNumeric(value); - verification().check(result, MessageKeys.ASCII_NUMERIC); + verification().report(result, MessageKeys.ASCII_NUMERIC); return this; } @@ -337,7 +337,7 @@ public CharacterVerifier asciiPrintable() { final Character value = verification().getValue(); final boolean result = value != null && value >= 32 && value < 127; - verification().check(result, MessageKeys.ASCII_PRINTABLE); + verification().report(result, MessageKeys.ASCII_PRINTABLE); return this; } @@ -347,7 +347,7 @@ public CharacterVerifier falsy() { final Character value = verification().getValue(); final boolean result = value == null || value == '0'; - verification().check(result, BaseTruthVerifier.MessageKeys.FALSY); + verification().report(result, BaseTruthVerifier.MessageKeys.FALSY); return this; } @@ -377,7 +377,7 @@ public CharacterVerifier lowerCase() { final Character value = verification().getValue(); final boolean result = value != null && Character.isLowerCase(value); - verification().check(result, MessageKeys.LOWER_CASE); + verification().report(result, MessageKeys.LOWER_CASE); return this; } @@ -404,7 +404,7 @@ public CharacterVerifier numeric() { final Character value = verification().getValue(); final boolean result = value != null && Character.isDigit(value); - verification().check(result, MessageKeys.NUMERIC); + verification().report(result, MessageKeys.NUMERIC); return this; } @@ -414,7 +414,7 @@ public CharacterVerifier truthy() { final Character value = verification().getValue(); final boolean result = value != null && value == '1'; - verification().check(result, BaseTruthVerifier.MessageKeys.TRUTHY); + verification().report(result, BaseTruthVerifier.MessageKeys.TRUTHY); return this; } @@ -444,7 +444,7 @@ public CharacterVerifier upperCase() { final Character value = verification().getValue(); final boolean result = value != null && Character.isUpperCase(value); - verification().check(result, MessageKeys.UPPER_CASE); + verification().report(result, MessageKeys.UPPER_CASE); return this; } @@ -472,7 +472,7 @@ public CharacterVerifier whitespace() { final Character value = verification().getValue(); final boolean result = value != null && Character.isWhitespace(value); - verification().check(result, MessageKeys.WHITESPACE); + verification().report(result, MessageKeys.WHITESPACE); return this; } diff --git a/src/main/java/io/skelp/verifier/type/ClassVerifier.java b/src/main/java/io/skelp/verifier/type/ClassVerifier.java index c28552b..e8d67f3 100644 --- a/src/main/java/io/skelp/verifier/type/ClassVerifier.java +++ b/src/main/java/io/skelp/verifier/type/ClassVerifier.java @@ -79,7 +79,7 @@ public ClassVerifier annotated() { final Class value = verification().getValue(); final boolean result = value != null && value.getAnnotations().length > 0; - verification().check(result, MessageKeys.ANNOTATED); + verification().report(result, MessageKeys.ANNOTATED); return this; } @@ -109,7 +109,7 @@ public ClassVerifier annotatedWith(final Class type) { final Class value = verification().getValue(); final boolean result = value != null && type != null && value.isAnnotationPresent(type); - verification().check(result, MessageKeys.ANNOTATED_WITH, type); + verification().report(result, MessageKeys.ANNOTATED_WITH, type); return this; } @@ -141,7 +141,7 @@ public ClassVerifier annotatedWithAll(final Class... types final Class value = verification().getValue(); final boolean result = value != null && matchAll(types, input -> input != null && value.isAnnotationPresent(input)); - verification().check(result, MessageKeys.ANNOTATED_WITH_ALL, (Object) types); + verification().report(result, MessageKeys.ANNOTATED_WITH_ALL, (Object) types); return this; } @@ -172,7 +172,7 @@ public ClassVerifier annotatedWithAny(final Class... types final Class value = verification().getValue(); final boolean result = value != null && matchAny(types, input -> input != null && value.isAnnotationPresent(input)); - verification().check(result, MessageKeys.ANNOTATED_WITH_ANY, (Object) types); + verification().report(result, MessageKeys.ANNOTATED_WITH_ANY, (Object) types); return this; } @@ -195,7 +195,7 @@ public ClassVerifier annotation() { final Class value = verification().getValue(); final boolean result = value != null && value.isAnnotation(); - verification().check(result, MessageKeys.ANNOTATION); + verification().report(result, MessageKeys.ANNOTATION); return this; } @@ -218,7 +218,7 @@ public ClassVerifier anonymous() { final Class value = verification().getValue(); final boolean result = value != null && value.isAnonymousClass(); - verification().check(result, MessageKeys.ANONYMOUS); + verification().report(result, MessageKeys.ANONYMOUS); return this; } @@ -241,7 +241,7 @@ public ClassVerifier array() { final Class value = verification().getValue(); final boolean result = value != null && value.isArray(); - verification().check(result, MessageKeys.ARRAY); + verification().report(result, MessageKeys.ARRAY); return this; } @@ -271,7 +271,7 @@ public ClassVerifier assignableFrom(final Class type) { final Class value = verification().getValue(); final boolean result = value != null && type != null && value.isAssignableFrom(type); - verification().check(result, MessageKeys.ASSIGNABLE_FROM, type); + verification().report(result, MessageKeys.ASSIGNABLE_FROM, type); return this; } @@ -294,7 +294,7 @@ public ClassVerifier enumeration() { final Class value = verification().getValue(); final boolean result = value != null && value.isEnum(); - verification().check(result, MessageKeys.ENUMERATION); + verification().report(result, MessageKeys.ENUMERATION); return this; } @@ -317,7 +317,7 @@ public ClassVerifier interfacing() { final Class value = verification().getValue(); final boolean result = value != null && value.isInterface(); - verification().check(result, MessageKeys.INTERFACING); + verification().report(result, MessageKeys.INTERFACING); return this; } @@ -340,7 +340,7 @@ public ClassVerifier nested() { final Class value = verification().getValue(); final boolean result = value != null && value.getEnclosingClass() != null; - verification().check(result, MessageKeys.NESTED); + verification().report(result, MessageKeys.NESTED); return this; } @@ -364,7 +364,7 @@ public ClassVerifier primitive() { final Class value = verification().getValue(); final boolean result = value != null && value.isPrimitive(); - verification().check(result, MessageKeys.PRIMITIVE); + verification().report(result, MessageKeys.PRIMITIVE); return this; } @@ -388,7 +388,7 @@ public ClassVerifier primitiveOrWrapper() { final Class value = verification().getValue(); final boolean result = value != null && (value.isPrimitive() || PRIMITIVE_WRAPPERS.contains(value)); - verification().check(result, MessageKeys.PRIMITIVE_OR_WRAPPER); + verification().report(result, MessageKeys.PRIMITIVE_OR_WRAPPER); return this; } @@ -412,7 +412,7 @@ public ClassVerifier primitiveWrapper() { final Class value = verification().getValue(); final boolean result = PRIMITIVE_WRAPPERS.contains(value); - verification().check(result, MessageKeys.PRIMITIVE_WRAPPER); + verification().report(result, MessageKeys.PRIMITIVE_WRAPPER); return this; } diff --git a/src/main/java/io/skelp/verifier/type/DoubleVerifier.java b/src/main/java/io/skelp/verifier/type/DoubleVerifier.java index 8bd043c..817655d 100644 --- a/src/main/java/io/skelp/verifier/type/DoubleVerifier.java +++ b/src/main/java/io/skelp/verifier/type/DoubleVerifier.java @@ -58,7 +58,7 @@ public DoubleVerifier even() { final Double value = verification().getValue(); final boolean result = value != null && value % 2D == 0; - verification().check(result, BaseNumberVerifier.MessageKeys.EVEN); + verification().report(result, BaseNumberVerifier.MessageKeys.EVEN); return this; } @@ -68,7 +68,7 @@ public DoubleVerifier falsy() { final Double value = verification().getValue(); final boolean result = value == null || value == 0D; - verification().check(result, BaseTruthVerifier.MessageKeys.FALSY); + verification().report(result, BaseTruthVerifier.MessageKeys.FALSY); return this; } @@ -78,7 +78,7 @@ public DoubleVerifier negative() { final Double value = verification().getValue(); final boolean result = value != null && value < 0D; - verification().check(result, BaseNumberVerifier.MessageKeys.NEGATIVE); + verification().report(result, BaseNumberVerifier.MessageKeys.NEGATIVE); return this; } @@ -88,7 +88,7 @@ public DoubleVerifier odd() { final Double value = verification().getValue(); final boolean result = value != null && value % 2 != 0D; - verification().check(result, BaseNumberVerifier.MessageKeys.ODD); + verification().report(result, BaseNumberVerifier.MessageKeys.ODD); return this; } @@ -98,7 +98,7 @@ public DoubleVerifier one() { final Double value = verification().getValue(); final boolean result = value != null && value == 1D; - verification().check(result, BaseNumberVerifier.MessageKeys.ONE); + verification().report(result, BaseNumberVerifier.MessageKeys.ONE); return this; } @@ -108,7 +108,7 @@ public DoubleVerifier positive() { final Double value = verification().getValue(); final boolean result = value != null && value >= 0D; - verification().check(result, BaseNumberVerifier.MessageKeys.POSITIVE); + verification().report(result, BaseNumberVerifier.MessageKeys.POSITIVE); return this; } @@ -118,7 +118,7 @@ public DoubleVerifier truthy() { final Double value = verification().getValue(); final boolean result = value != null && value == 1D; - verification().check(result, BaseTruthVerifier.MessageKeys.TRUTHY); + verification().report(result, BaseTruthVerifier.MessageKeys.TRUTHY); return this; } @@ -128,7 +128,7 @@ public DoubleVerifier zero() { final Double value = verification().getValue(); final boolean result = value != null && value == 0D; - verification().check(result, BaseNumberVerifier.MessageKeys.ZERO); + verification().report(result, BaseNumberVerifier.MessageKeys.ZERO); return this; } diff --git a/src/main/java/io/skelp/verifier/type/FloatVerifier.java b/src/main/java/io/skelp/verifier/type/FloatVerifier.java index ce06e45..b20d5ea 100644 --- a/src/main/java/io/skelp/verifier/type/FloatVerifier.java +++ b/src/main/java/io/skelp/verifier/type/FloatVerifier.java @@ -58,7 +58,7 @@ public FloatVerifier even() { final Float value = verification().getValue(); final boolean result = value != null && value % 2F == 0; - verification().check(result, BaseNumberVerifier.MessageKeys.EVEN); + verification().report(result, BaseNumberVerifier.MessageKeys.EVEN); return this; } @@ -68,7 +68,7 @@ public FloatVerifier falsy() { final Float value = verification().getValue(); final boolean result = value == null || value == 0F; - verification().check(result, BaseTruthVerifier.MessageKeys.FALSY); + verification().report(result, BaseTruthVerifier.MessageKeys.FALSY); return this; } @@ -78,7 +78,7 @@ public FloatVerifier negative() { final Float value = verification().getValue(); final boolean result = value != null && value < 0F; - verification().check(result, BaseNumberVerifier.MessageKeys.NEGATIVE); + verification().report(result, BaseNumberVerifier.MessageKeys.NEGATIVE); return this; } @@ -88,7 +88,7 @@ public FloatVerifier odd() { final Float value = verification().getValue(); final boolean result = value != null && value % 2 != 0F; - verification().check(result, BaseNumberVerifier.MessageKeys.ODD); + verification().report(result, BaseNumberVerifier.MessageKeys.ODD); return this; } @@ -98,7 +98,7 @@ public FloatVerifier one() { final Float value = verification().getValue(); final boolean result = value != null && value == 1F; - verification().check(result, BaseNumberVerifier.MessageKeys.ONE); + verification().report(result, BaseNumberVerifier.MessageKeys.ONE); return this; } @@ -108,7 +108,7 @@ public FloatVerifier positive() { final Float value = verification().getValue(); final boolean result = value != null && value >= 0F; - verification().check(result, BaseNumberVerifier.MessageKeys.POSITIVE); + verification().report(result, BaseNumberVerifier.MessageKeys.POSITIVE); return this; } @@ -118,7 +118,7 @@ public FloatVerifier truthy() { final Float value = verification().getValue(); final boolean result = value != null && value == 1F; - verification().check(result, BaseTruthVerifier.MessageKeys.TRUTHY); + verification().report(result, BaseTruthVerifier.MessageKeys.TRUTHY); return this; } @@ -128,7 +128,7 @@ public FloatVerifier zero() { final Float value = verification().getValue(); final boolean result = value != null && value == 0F; - verification().check(result, BaseNumberVerifier.MessageKeys.ZERO); + verification().report(result, BaseNumberVerifier.MessageKeys.ZERO); return this; } diff --git a/src/main/java/io/skelp/verifier/type/IntegerVerifier.java b/src/main/java/io/skelp/verifier/type/IntegerVerifier.java index 3f28daf..8d4f4fe 100644 --- a/src/main/java/io/skelp/verifier/type/IntegerVerifier.java +++ b/src/main/java/io/skelp/verifier/type/IntegerVerifier.java @@ -58,7 +58,7 @@ public IntegerVerifier even() { final Integer value = verification().getValue(); final boolean result = value != null && value % 2 == 0; - verification().check(result, BaseNumberVerifier.MessageKeys.EVEN); + verification().report(result, BaseNumberVerifier.MessageKeys.EVEN); return this; } @@ -68,7 +68,7 @@ public IntegerVerifier falsy() { final Integer value = verification().getValue(); final boolean result = value == null || value == 0; - verification().check(result, BaseTruthVerifier.MessageKeys.FALSY); + verification().report(result, BaseTruthVerifier.MessageKeys.FALSY); return this; } @@ -78,7 +78,7 @@ public IntegerVerifier negative() { final Integer value = verification().getValue(); final boolean result = value != null && value < 0; - verification().check(result, BaseNumberVerifier.MessageKeys.NEGATIVE); + verification().report(result, BaseNumberVerifier.MessageKeys.NEGATIVE); return this; } @@ -88,7 +88,7 @@ public IntegerVerifier odd() { final Integer value = verification().getValue(); final boolean result = value != null && value % 2 != 0; - verification().check(result, BaseNumberVerifier.MessageKeys.ODD); + verification().report(result, BaseNumberVerifier.MessageKeys.ODD); return this; } @@ -98,7 +98,7 @@ public IntegerVerifier one() { final Integer value = verification().getValue(); final boolean result = value != null && value == 1; - verification().check(result, BaseNumberVerifier.MessageKeys.ONE); + verification().report(result, BaseNumberVerifier.MessageKeys.ONE); return this; } @@ -108,7 +108,7 @@ public IntegerVerifier positive() { final Integer value = verification().getValue(); final boolean result = value != null && value >= 0; - verification().check(result, BaseNumberVerifier.MessageKeys.POSITIVE); + verification().report(result, BaseNumberVerifier.MessageKeys.POSITIVE); return this; } @@ -118,7 +118,7 @@ public IntegerVerifier truthy() { final Integer value = verification().getValue(); final boolean result = value != null && value == 1; - verification().check(result, BaseTruthVerifier.MessageKeys.TRUTHY); + verification().report(result, BaseTruthVerifier.MessageKeys.TRUTHY); return this; } @@ -128,7 +128,7 @@ public IntegerVerifier zero() { final Integer value = verification().getValue(); final boolean result = value != null && value == 0; - verification().check(result, BaseNumberVerifier.MessageKeys.ZERO); + verification().report(result, BaseNumberVerifier.MessageKeys.ZERO); return this; } diff --git a/src/main/java/io/skelp/verifier/type/LocaleVerifier.java b/src/main/java/io/skelp/verifier/type/LocaleVerifier.java index 846a7ea..861d18a 100644 --- a/src/main/java/io/skelp/verifier/type/LocaleVerifier.java +++ b/src/main/java/io/skelp/verifier/type/LocaleVerifier.java @@ -72,7 +72,7 @@ public LocaleVerifier available() { final Locale value = verification().getValue(); final boolean result = LazyHolder.AVAILABLE_LOCALES.contains(value); - verification().check(result, MessageKeys.AVAILABLE); + verification().report(result, MessageKeys.AVAILABLE); return this; } @@ -102,7 +102,7 @@ public LocaleVerifier country(final String country) { final Locale value = verification().getValue(); final boolean result = value != null && value.getCountry().equals(country); - verification().check(result, MessageKeys.COUNTRY, country); + verification().report(result, MessageKeys.COUNTRY, country); return this; } @@ -125,7 +125,7 @@ public LocaleVerifier defaulting() { final Locale value = verification().getValue(); final boolean result = Locale.getDefault().equals(value); - verification().check(result, MessageKeys.DEFAULTING); + verification().report(result, MessageKeys.DEFAULTING); return this; } @@ -154,7 +154,7 @@ public LocaleVerifier language(final String language) { final Locale value = verification().getValue(); final boolean result = value != null && value.getLanguage().equals(language); - verification().check(result, MessageKeys.LANGUAGE, language); + verification().report(result, MessageKeys.LANGUAGE, language); return this; } @@ -184,7 +184,7 @@ public LocaleVerifier script(final String script) { final Locale value = verification().getValue(); final boolean result = value != null && value.getScript().equals(script); - verification().check(result, MessageKeys.SCRIPT, script); + verification().report(result, MessageKeys.SCRIPT, script); return this; } @@ -214,7 +214,7 @@ public LocaleVerifier variant(final String variant) { final Locale value = verification().getValue(); final boolean result = value != null && value.getVariant().equals(variant); - verification().check(result, MessageKeys.VARIANT, variant); + verification().report(result, MessageKeys.VARIANT, variant); return this; } diff --git a/src/main/java/io/skelp/verifier/type/LongVerifier.java b/src/main/java/io/skelp/verifier/type/LongVerifier.java index fcee44a..d2aa649 100644 --- a/src/main/java/io/skelp/verifier/type/LongVerifier.java +++ b/src/main/java/io/skelp/verifier/type/LongVerifier.java @@ -58,7 +58,7 @@ public LongVerifier even() { final Long value = verification().getValue(); final boolean result = value != null && value % 2L == 0; - verification().check(result, BaseNumberVerifier.MessageKeys.EVEN); + verification().report(result, BaseNumberVerifier.MessageKeys.EVEN); return this; } @@ -68,7 +68,7 @@ public LongVerifier falsy() { final Long value = verification().getValue(); final boolean result = value == null || value == 0L; - verification().check(result, BaseTruthVerifier.MessageKeys.FALSY); + verification().report(result, BaseTruthVerifier.MessageKeys.FALSY); return this; } @@ -78,7 +78,7 @@ public LongVerifier negative() { final Long value = verification().getValue(); final boolean result = value != null && value < 0L; - verification().check(result, BaseNumberVerifier.MessageKeys.NEGATIVE); + verification().report(result, BaseNumberVerifier.MessageKeys.NEGATIVE); return this; } @@ -88,7 +88,7 @@ public LongVerifier odd() { final Long value = verification().getValue(); final boolean result = value != null && value % 2 != 0L; - verification().check(result, BaseNumberVerifier.MessageKeys.ODD); + verification().report(result, BaseNumberVerifier.MessageKeys.ODD); return this; } @@ -98,7 +98,7 @@ public LongVerifier one() { final Long value = verification().getValue(); final boolean result = value != null && value == 1L; - verification().check(result, BaseNumberVerifier.MessageKeys.ONE); + verification().report(result, BaseNumberVerifier.MessageKeys.ONE); return this; } @@ -108,7 +108,7 @@ public LongVerifier positive() { final Long value = verification().getValue(); final boolean result = value != null && value >= 0L; - verification().check(result, BaseNumberVerifier.MessageKeys.POSITIVE); + verification().report(result, BaseNumberVerifier.MessageKeys.POSITIVE); return this; } @@ -118,7 +118,7 @@ public LongVerifier truthy() { final Long value = verification().getValue(); final boolean result = value != null && value == 1L; - verification().check(result, BaseTruthVerifier.MessageKeys.TRUTHY); + verification().report(result, BaseTruthVerifier.MessageKeys.TRUTHY); return this; } @@ -128,7 +128,7 @@ public LongVerifier zero() { final Long value = verification().getValue(); final boolean result = value != null && value == 0L; - verification().check(result, BaseNumberVerifier.MessageKeys.ZERO); + verification().report(result, BaseNumberVerifier.MessageKeys.ZERO); return this; } diff --git a/src/main/java/io/skelp/verifier/type/MapVerifier.java b/src/main/java/io/skelp/verifier/type/MapVerifier.java index 451f59e..025e707 100644 --- a/src/main/java/io/skelp/verifier/type/MapVerifier.java +++ b/src/main/java/io/skelp/verifier/type/MapVerifier.java @@ -83,7 +83,7 @@ public MapVerifier containAllKeys(final K... keys) { final Map value = verification().getValue(); final boolean result = value != null && matchAll(keys, value::containsKey); - verification().check(result, MessageKeys.CONTAIN_ALL_KEYS, (Object) keys); + verification().report(result, MessageKeys.CONTAIN_ALL_KEYS, (Object) keys); return this; } @@ -116,7 +116,7 @@ public MapVerifier containAnyKey(final K... keys) { final Map value = verification().getValue(); final boolean result = value != null && matchAny(keys, value::containsKey); - verification().check(result, MessageKeys.CONTAIN_ANY_KEY, (Object) keys); + verification().report(result, MessageKeys.CONTAIN_ANY_KEY, (Object) keys); return this; } @@ -147,7 +147,7 @@ public MapVerifier containKey(final K key) { final Map value = verification().getValue(); final boolean result = value != null && value.containsKey(key); - verification().check(result, MessageKeys.CONTAIN_KEY, key); + verification().report(result, MessageKeys.CONTAIN_KEY, key); return this; } diff --git a/src/main/java/io/skelp/verifier/type/ShortVerifier.java b/src/main/java/io/skelp/verifier/type/ShortVerifier.java index 7277929..931b83f 100644 --- a/src/main/java/io/skelp/verifier/type/ShortVerifier.java +++ b/src/main/java/io/skelp/verifier/type/ShortVerifier.java @@ -58,7 +58,7 @@ public ShortVerifier even() { final Short value = verification().getValue(); final boolean result = value != null && value % 2 == 0; - verification().check(result, BaseNumberVerifier.MessageKeys.EVEN); + verification().report(result, BaseNumberVerifier.MessageKeys.EVEN); return this; } @@ -68,7 +68,7 @@ public ShortVerifier falsy() { final Short value = verification().getValue(); final boolean result = value == null || value == 0; - verification().check(result, BaseTruthVerifier.MessageKeys.FALSY); + verification().report(result, BaseTruthVerifier.MessageKeys.FALSY); return this; } @@ -78,7 +78,7 @@ public ShortVerifier negative() { final Short value = verification().getValue(); final boolean result = value != null && value < 0; - verification().check(result, BaseNumberVerifier.MessageKeys.NEGATIVE); + verification().report(result, BaseNumberVerifier.MessageKeys.NEGATIVE); return this; } @@ -88,7 +88,7 @@ public ShortVerifier odd() { final Short value = verification().getValue(); final boolean result = value != null && value % 2 != 0; - verification().check(result, BaseNumberVerifier.MessageKeys.ODD); + verification().report(result, BaseNumberVerifier.MessageKeys.ODD); return this; } @@ -98,7 +98,7 @@ public ShortVerifier one() { final Short value = verification().getValue(); final boolean result = value != null && value == 1; - verification().check(result, BaseNumberVerifier.MessageKeys.ONE); + verification().report(result, BaseNumberVerifier.MessageKeys.ONE); return this; } @@ -108,7 +108,7 @@ public ShortVerifier positive() { final Short value = verification().getValue(); final boolean result = value != null && value >= 0; - verification().check(result, BaseNumberVerifier.MessageKeys.POSITIVE); + verification().report(result, BaseNumberVerifier.MessageKeys.POSITIVE); return this; } @@ -118,7 +118,7 @@ public ShortVerifier truthy() { final Short value = verification().getValue(); final boolean result = value != null && value == 1; - verification().check(result, BaseTruthVerifier.MessageKeys.TRUTHY); + verification().report(result, BaseTruthVerifier.MessageKeys.TRUTHY); return this; } @@ -128,7 +128,7 @@ public ShortVerifier zero() { final Short value = verification().getValue(); final boolean result = value != null && value == 0; - verification().check(result, BaseNumberVerifier.MessageKeys.ZERO); + verification().report(result, BaseNumberVerifier.MessageKeys.ZERO); return this; } diff --git a/src/main/java/io/skelp/verifier/type/StringVerifier.java b/src/main/java/io/skelp/verifier/type/StringVerifier.java index 4772e51..3dc7e20 100644 --- a/src/main/java/io/skelp/verifier/type/StringVerifier.java +++ b/src/main/java/io/skelp/verifier/type/StringVerifier.java @@ -155,7 +155,7 @@ public StringVerifier alpha() { final String value = verification().getValue(); final boolean result = matchCharacters(value, Character::isLetter); - verification().check(result, MessageKeys.ALPHA); + verification().report(result, MessageKeys.ALPHA); return this; } @@ -181,7 +181,7 @@ public StringVerifier alphaSpace() { final String value = verification().getValue(); final boolean result = matchCharacters(value, character -> Character.isLetter(character) || character == ' '); - verification().check(result, MessageKeys.ALPHA_SPACE); + verification().report(result, MessageKeys.ALPHA_SPACE); return this; } @@ -208,7 +208,7 @@ public StringVerifier alphanumeric() { final String value = verification().getValue(); final boolean result = matchCharacters(value, Character::isLetterOrDigit); - verification().check(result, MessageKeys.ALPHANUMERIC); + verification().report(result, MessageKeys.ALPHANUMERIC); return this; } @@ -234,7 +234,7 @@ public StringVerifier alphanumericSpace() { final String value = verification().getValue(); final boolean result = matchCharacters(value, character -> Character.isLetterOrDigit(character) || character == ' '); - verification().check(result, MessageKeys.ALPHANUMERIC_SPACE); + verification().report(result, MessageKeys.ALPHANUMERIC_SPACE); return this; } @@ -258,7 +258,7 @@ public StringVerifier asciiPrintable() { final String value = verification().getValue(); final boolean result = matchCharacters(value, character -> character >= 32 && character < 127); - verification().check(result, MessageKeys.ASCII_PRINTABLE); + verification().report(result, MessageKeys.ASCII_PRINTABLE); return this; } @@ -289,7 +289,7 @@ public StringVerifier blank() { final String value = verification().getValue(); final boolean result = value == null || value.trim().isEmpty(); - verification().check(result, MessageKeys.BLANK); + verification().report(result, MessageKeys.BLANK); return this; } @@ -322,7 +322,7 @@ public StringVerifier contain(final CharSequence other) { final String value = verification().getValue(); final boolean result = value != null && other != null && value.contains(other); - verification().check(result, MessageKeys.CONTAIN, other); + verification().report(result, MessageKeys.CONTAIN, other); return this; } @@ -354,7 +354,7 @@ public StringVerifier containAll(final CharSequence... others) { final String value = verification().getValue(); final boolean result = value != null && matchAll(others, input -> input != null && value.contains(input)); - verification().check(result, MessageKeys.CONTAIN_ALL, (Object) others); + verification().report(result, MessageKeys.CONTAIN_ALL, (Object) others); return this; } @@ -386,7 +386,7 @@ public StringVerifier containAllIgnoreCase(final CharSequence... others) { final String value = verification().getValue(); final boolean result = value != null && matchAll(others, input -> containsIgnoreCase(value, input)); - verification().check(result, MessageKeys.CONTAIN_ALL_IGNORE_CASE, (Object) others); + verification().report(result, MessageKeys.CONTAIN_ALL_IGNORE_CASE, (Object) others); return this; } @@ -419,7 +419,7 @@ public StringVerifier containAny(final CharSequence... others) { final String value = verification().getValue(); final boolean result = value != null && matchAny(others, input -> input != null && value.contains(input)); - verification().check(result, MessageKeys.CONTAIN_ANY, (Object) others); + verification().report(result, MessageKeys.CONTAIN_ANY, (Object) others); return this; } @@ -452,7 +452,7 @@ public StringVerifier containAnyIgnoreCase(final CharSequence... others) { final String value = verification().getValue(); final boolean result = value != null && matchAny(others, input -> containsIgnoreCase(value, input)); - verification().check(result, MessageKeys.CONTAIN_ANY_IGNORE_CASE, (Object) others); + verification().report(result, MessageKeys.CONTAIN_ANY_IGNORE_CASE, (Object) others); return this; } @@ -485,7 +485,7 @@ public StringVerifier containIgnoreCase(final CharSequence other) { final String value = verification().getValue(); final boolean result = value != null && containsIgnoreCase(value, other); - verification().check(result, MessageKeys.CONTAIN_IGNORE_CASE, other); + verification().report(result, MessageKeys.CONTAIN_IGNORE_CASE, other); return this; } @@ -514,7 +514,7 @@ public StringVerifier empty() { final String value = verification().getValue(); final boolean result = value == null || value.isEmpty(); - verification().check(result, MessageKeys.EMPTY); + verification().report(result, MessageKeys.EMPTY); return this; } @@ -547,7 +547,7 @@ public StringVerifier endWith(final CharSequence other) { final String value = verification().getValue(); final boolean result = value != null && endsWith(value, other, false); - verification().check(result, MessageKeys.END_WITH, other); + verification().report(result, MessageKeys.END_WITH, other); return this; } @@ -579,7 +579,7 @@ public StringVerifier endWithAny(final CharSequence... others) { final String value = verification().getValue(); final boolean result = value != null && matchAny(others, input -> endsWith(value, input, false)); - verification().check(result, MessageKeys.END_WITH_ANY, (Object) others); + verification().report(result, MessageKeys.END_WITH_ANY, (Object) others); return this; } @@ -611,7 +611,7 @@ public StringVerifier endWithAnyIgnoreCase(final CharSequence... others) { final String value = verification().getValue(); final boolean result = value != null && matchAny(others, input -> endsWith(value, input, true)); - verification().check(result, MessageKeys.END_WITH_ANY_IGNORE_CASE, (Object) others); + verification().report(result, MessageKeys.END_WITH_ANY_IGNORE_CASE, (Object) others); return this; } @@ -644,7 +644,7 @@ public StringVerifier endWithIgnoreCase(final CharSequence other) { final String value = verification().getValue(); final boolean result = value != null && endsWith(value, other, true); - verification().check(result, MessageKeys.END_WITH_IGNORE_CASE, other); + verification().report(result, MessageKeys.END_WITH_IGNORE_CASE, other); return this; } @@ -678,7 +678,7 @@ public StringVerifier equalToAnyIgnoreCase(final CharSequence... others) { final String value = verification().getValue(); final boolean result = matchAny(others, input -> isEqualToIgnoreCase(value, input)); - verification().check(result, MessageKeys.EQUAL_TO_ANY_IGNORE_CASE, (Object) others); + verification().report(result, MessageKeys.EQUAL_TO_ANY_IGNORE_CASE, (Object) others); return chain(); } @@ -710,7 +710,7 @@ public StringVerifier equalToIgnoreCase(final CharSequence other) { final String value = verification().getValue(); final boolean result = isEqualToIgnoreCase(value, other); - verification().check(result, MessageKeys.EQUAL_TO_IGNORE_CASE, other); + verification().report(result, MessageKeys.EQUAL_TO_IGNORE_CASE, other); return this; } @@ -720,7 +720,7 @@ public StringVerifier falsy() { final String value = verification().getValue(); final boolean result = value == null || value.isEmpty() || Boolean.FALSE.toString().equalsIgnoreCase(value); - verification().check(result, BaseTruthVerifier.MessageKeys.FALSY); + verification().report(result, BaseTruthVerifier.MessageKeys.FALSY); return this; } @@ -747,7 +747,7 @@ public StringVerifier lowerCase() { final String value = verification().getValue(); final boolean result = matchCharacters(value, Character::isLowerCase); - verification().check(result, MessageKeys.LOWER_CASE); + verification().report(result, MessageKeys.LOWER_CASE); return this; } @@ -778,7 +778,7 @@ public StringVerifier match(final CharSequence regex) { final String value = verification().getValue(); final boolean result = value != null && regex != null && value.matches(regex.toString()); - verification().check(result, MessageKeys.MATCH, regex); + verification().report(result, MessageKeys.MATCH, regex); return this; } @@ -809,7 +809,7 @@ public StringVerifier match(final Pattern pattern) { final String value = verification().getValue(); final boolean result = value != null && pattern != null && pattern.matcher(value).matches(); - verification().check(result, MessageKeys.MATCH, pattern); + verification().report(result, MessageKeys.MATCH, pattern); return this; } @@ -836,7 +836,7 @@ public StringVerifier numeric() { final String value = verification().getValue(); final boolean result = matchCharacters(value, Character::isDigit); - verification().check(result, MessageKeys.NUMERIC); + verification().report(result, MessageKeys.NUMERIC); return this; } @@ -862,7 +862,7 @@ public StringVerifier numericSpace() { final String value = verification().getValue(); final boolean result = matchCharacters(value, character -> Character.isDigit(character) || character == ' '); - verification().check(result, MessageKeys.NUMERIC_SPACE); + verification().report(result, MessageKeys.NUMERIC_SPACE); return this; } @@ -894,7 +894,7 @@ public StringVerifier sizeOf(final int size) { final String value = verification().getValue(); final boolean result = value == null ? size == 0 : value.length() == size; - verification().check(result, MessageKeys.SIZE_OF, size); + verification().report(result, MessageKeys.SIZE_OF, size); return this; } @@ -927,7 +927,7 @@ public StringVerifier startWith(final CharSequence other) { final String value = verification().getValue(); final boolean result = startsWith(value, other, false); - verification().check(result, MessageKeys.START_WITH, other); + verification().report(result, MessageKeys.START_WITH, other); return this; } @@ -959,7 +959,7 @@ public StringVerifier startWithAny(final CharSequence... others) { final String value = verification().getValue(); final boolean result = matchAny(others, input -> startsWith(value, input, false)); - verification().check(result, MessageKeys.START_WITH_ANY, (Object) others); + verification().report(result, MessageKeys.START_WITH_ANY, (Object) others); return this; } @@ -991,7 +991,7 @@ public StringVerifier startWithAnyIgnoreCase(final CharSequence... others) { final String value = verification().getValue(); final boolean result = matchAny(others, input -> startsWith(value, input, true)); - verification().check(result, MessageKeys.START_WITH_ANY_IGNORE_CASE, (Object) others); + verification().report(result, MessageKeys.START_WITH_ANY_IGNORE_CASE, (Object) others); return this; } @@ -1024,7 +1024,7 @@ public StringVerifier startWithIgnoreCase(final CharSequence other) { final String value = verification().getValue(); final boolean result = startsWith(value, other, true); - verification().check(result, MessageKeys.START_WITH_IGNORE_CASE, other); + verification().report(result, MessageKeys.START_WITH_IGNORE_CASE, other); return this; } @@ -1034,7 +1034,7 @@ public StringVerifier truthy() { final String value = verification().getValue(); final boolean result = Boolean.TRUE.toString().equalsIgnoreCase(value); - verification().check(result, BaseTruthVerifier.MessageKeys.TRUTHY); + verification().report(result, BaseTruthVerifier.MessageKeys.TRUTHY); return this; } @@ -1061,7 +1061,7 @@ public StringVerifier upperCase() { final String value = verification().getValue(); final boolean result = matchCharacters(value, Character::isUpperCase); - verification().check(result, MessageKeys.UPPER_CASE); + verification().report(result, MessageKeys.UPPER_CASE); return this; } diff --git a/src/main/java/io/skelp/verifier/type/ThrowableVerifier.java b/src/main/java/io/skelp/verifier/type/ThrowableVerifier.java index 096dd31..86b8ed0 100644 --- a/src/main/java/io/skelp/verifier/type/ThrowableVerifier.java +++ b/src/main/java/io/skelp/verifier/type/ThrowableVerifier.java @@ -96,7 +96,7 @@ public ThrowableVerifier causedBy(final Class type) { } } - verification().check(result, MessageKeys.CAUSED_BY, type); + verification().report(result, MessageKeys.CAUSED_BY, type); return this; } @@ -163,7 +163,7 @@ public ThrowableVerifier causedBy(final Throwable cause, final Object name) { final Throwable value = verification().getValue(); final boolean result = getThrowables(value).contains(cause); - verification().check(result, MessageKeys.CAUSED_BY, name); + verification().report(result, MessageKeys.CAUSED_BY, name); return this; } @@ -189,7 +189,7 @@ public ThrowableVerifier checked() { final Throwable value = verification().getValue(); final boolean result = value != null && !(value instanceof RuntimeException); - verification().check(result, MessageKeys.CHECKED); + verification().report(result, MessageKeys.CHECKED); return this; } @@ -221,7 +221,7 @@ public ThrowableVerifier message(final String message) { final Throwable value = verification().getValue(); final boolean result = value != null && (value.getMessage() == null ? message == null : value.getMessage().equals(message)); - verification().check(result, MessageKeys.MESSAGE, message); + verification().report(result, MessageKeys.MESSAGE, message); return this; } @@ -247,7 +247,7 @@ public ThrowableVerifier unchecked() { final Throwable value = verification().getValue(); final boolean result = value instanceof RuntimeException; - verification().check(result, MessageKeys.UNCHECKED); + verification().report(result, MessageKeys.UNCHECKED); return this; } diff --git a/src/main/java/io/skelp/verifier/type/base/BaseCollectionVerifier.java b/src/main/java/io/skelp/verifier/type/base/BaseCollectionVerifier.java index e93badf..bcf5183 100644 --- a/src/main/java/io/skelp/verifier/type/base/BaseCollectionVerifier.java +++ b/src/main/java/io/skelp/verifier/type/base/BaseCollectionVerifier.java @@ -85,7 +85,7 @@ public V contain(final E element) { final Collection value = getCollection(verification().getValue()); final boolean result = value != null && value.contains(element); - verification().check(result, MessageKeys.CONTAIN, element); + verification().report(result, MessageKeys.CONTAIN, element); return chain(); } @@ -118,7 +118,7 @@ public V containAll(final E... elements) { final Collection value = getCollection(verification().getValue()); final boolean result = value != null && matchAll(elements, value::contains); - verification().check(result, MessageKeys.CONTAIN_ALL, (Object) elements); + verification().report(result, MessageKeys.CONTAIN_ALL, (Object) elements); return chain(); } @@ -151,7 +151,7 @@ public V containAny(final E... elements) { final Collection value = getCollection(verification().getValue()); final boolean result = value != null && matchAny(elements, value::contains); - verification().check(result, MessageKeys.CONTAIN_ANY, (Object) elements); + verification().report(result, MessageKeys.CONTAIN_ANY, (Object) elements); return chain(); } @@ -177,7 +177,7 @@ public V empty() { final T value = verification().getValue(); final boolean result = value == null || getSize(value) == 0; - verification().check(result, MessageKeys.EMPTY); + verification().report(result, MessageKeys.EMPTY); return chain(); } @@ -208,7 +208,7 @@ public V sizeOf(final int size) { final T value = verification().getValue(); final boolean result = value == null ? size == 0 : getSize(value) == size; - verification().check(result, MessageKeys.SIZE_OF, size); + verification().report(result, MessageKeys.SIZE_OF, size); return chain(); } @@ -241,7 +241,7 @@ public V sizeOf(final int size) { * @see #thatAll(VerifierAssertion, String, Object...) */ public V thatAll(final VerifierAssertion assertion) { - verification().check(thatAllInternal(assertion), (String) null); + verification().report(thatAllInternal(assertion), (String) null); return chain(); } @@ -273,7 +273,7 @@ public V thatAll(final VerifierAssertion assertion) { * @since 0.2.0 */ public V thatAll(final VerifierAssertion assertion, final MessageKey key, final Object... args) { - verification().check(thatAllInternal(assertion), key, args); + verification().report(thatAllInternal(assertion), key, args); return chain(); } @@ -303,7 +303,7 @@ public V thatAll(final VerifierAssertion assertion, final MessageKey key, fin * @see #thatAll(VerifierAssertion, MessageKey, Object...) */ public V thatAll(final VerifierAssertion assertion, final String message, final Object... args) { - verification().check(thatAllInternal(assertion), message, args); + verification().report(thatAllInternal(assertion), message, args); return chain(); } @@ -364,7 +364,7 @@ protected boolean thatAllInternal(final VerifierAssertion assertion) { * @see #thatAny(VerifierAssertion, String, Object...) */ public V thatAny(final VerifierAssertion assertion) { - verification().check(thatAnyInternal(assertion), (String) null); + verification().report(thatAnyInternal(assertion), (String) null); return chain(); } @@ -396,7 +396,7 @@ public V thatAny(final VerifierAssertion assertion) { * @since 0.2.0 */ public V thatAny(final VerifierAssertion assertion, final MessageKey key, final Object... args) { - verification().check(thatAnyInternal(assertion), key, args); + verification().report(thatAnyInternal(assertion), key, args); return chain(); } @@ -426,7 +426,7 @@ public V thatAny(final VerifierAssertion assertion, final MessageKey key, fin * @see #thatAny(VerifierAssertion, MessageKey, Object...) */ public V thatAny(final VerifierAssertion assertion, final String message, final Object... args) { - verification().check(thatAnyInternal(assertion), message, args); + verification().report(thatAnyInternal(assertion), message, args); return chain(); } diff --git a/src/main/java/io/skelp/verifier/type/base/BaseComparableVerifier.java b/src/main/java/io/skelp/verifier/type/base/BaseComparableVerifier.java index 015cbc3..24da0b5 100644 --- a/src/main/java/io/skelp/verifier/type/base/BaseComparableVerifier.java +++ b/src/main/java/io/skelp/verifier/type/base/BaseComparableVerifier.java @@ -455,7 +455,7 @@ private V between(final T start, final Comparison startComparison, final Object final boolean result = value != null && start != null && end != null && (startComparison.compare(value.compareTo(start)) && endComparison.compare(value.compareTo(end))); - verification().check(result, key, startName, endName); + verification().report(result, key, startName, endName); return chain(); } @@ -464,7 +464,7 @@ private V comparesTo(final Comparison comparison, final T other, final Object na final T value = verification().getValue(); final boolean result = (value == null || other == null) ? comparison.areNullsEqual() && value == other : comparison.compare(value.compareTo(other)); - verification().check(result, key, name); + verification().report(result, key, name); return chain(); } diff --git a/src/main/java/io/skelp/verifier/type/base/BaseSortableCollectionVerifier.java b/src/main/java/io/skelp/verifier/type/base/BaseSortableCollectionVerifier.java index ecb3277..bce36b2 100644 --- a/src/main/java/io/skelp/verifier/type/base/BaseSortableCollectionVerifier.java +++ b/src/main/java/io/skelp/verifier/type/base/BaseSortableCollectionVerifier.java @@ -144,7 +144,7 @@ public V sortedBy(final Comparator comparator, final Object name) { } } - verification().check(result, MessageKeys.SORTED_BY, name); + verification().report(result, MessageKeys.SORTED_BY, name); return chain(); } diff --git a/src/main/java/io/skelp/verifier/type/base/BaseTimeVerifier.java b/src/main/java/io/skelp/verifier/type/base/BaseTimeVerifier.java index 649b59e..d3e4586 100644 --- a/src/main/java/io/skelp/verifier/type/base/BaseTimeVerifier.java +++ b/src/main/java/io/skelp/verifier/type/base/BaseTimeVerifier.java @@ -83,7 +83,7 @@ public V sameDayAs(final T other) { calendar1.get(Calendar.YEAR) == calendar2.get(Calendar.YEAR) && calendar1.get(Calendar.DAY_OF_YEAR) == calendar2.get(Calendar.DAY_OF_YEAR)); - verification().check(result, MessageKeys.SAME_DAY_AS, other); + verification().report(result, MessageKeys.SAME_DAY_AS, other); return chain(); } @@ -114,7 +114,7 @@ public V sameEraAs(final T other) { final boolean result = calendar1 != null && calendar2 != null && calendar1.get(Calendar.ERA) == calendar2.get(Calendar.ERA); - verification().check(result, MessageKeys.SAME_ERA_AS, other); + verification().report(result, MessageKeys.SAME_ERA_AS, other); return chain(); } @@ -149,7 +149,7 @@ public V sameHourAs(final T other) { calendar1.get(Calendar.DAY_OF_YEAR) == calendar2.get(Calendar.DAY_OF_YEAR) && calendar1.get(Calendar.HOUR_OF_DAY) == calendar2.get(Calendar.HOUR_OF_DAY)); - verification().check(result, MessageKeys.SAME_HOUR_AS, other); + verification().report(result, MessageKeys.SAME_HOUR_AS, other); return chain(); } @@ -185,7 +185,7 @@ public V sameMinuteAs(final T other) { calendar1.get(Calendar.HOUR_OF_DAY) == calendar2.get(Calendar.HOUR_OF_DAY) && calendar1.get(Calendar.MINUTE) == calendar2.get(Calendar.MINUTE)); - verification().check(result, MessageKeys.SAME_MINUTE_AS, other); + verification().report(result, MessageKeys.SAME_MINUTE_AS, other); return chain(); } @@ -219,7 +219,7 @@ public V sameMonthAs(final T other) { calendar1.get(Calendar.YEAR) == calendar2.get(Calendar.YEAR) && calendar1.get(Calendar.MONTH) == calendar2.get(Calendar.MONTH)); - verification().check(result, MessageKeys.SAME_MONTH_AS, other); + verification().report(result, MessageKeys.SAME_MONTH_AS, other); return chain(); } @@ -256,7 +256,7 @@ public V sameSecondAs(final T other) { calendar1.get(Calendar.MINUTE) == calendar2.get(Calendar.MINUTE) && calendar1.get(Calendar.SECOND) == calendar2.get(Calendar.SECOND)); - verification().check(result, MessageKeys.SAME_SECOND_AS, other); + verification().report(result, MessageKeys.SAME_SECOND_AS, other); return chain(); } @@ -288,7 +288,7 @@ public V sameTimeAs(final T other) { final boolean result = calendar1 != null && calendar2 != null && calendar1.getTimeInMillis() == calendar2.getTimeInMillis(); - verification().check(result, MessageKeys.SAME_TIME_AS, other); + verification().report(result, MessageKeys.SAME_TIME_AS, other); return chain(); } @@ -322,7 +322,7 @@ public V sameWeekAs(final T other) { calendar1.get(Calendar.YEAR) == calendar2.get(Calendar.YEAR) && calendar1.get(Calendar.WEEK_OF_YEAR) == calendar2.get(Calendar.WEEK_OF_YEAR)); - verification().check(result, MessageKeys.SAME_WEEK_AS, other); + verification().report(result, MessageKeys.SAME_WEEK_AS, other); return chain(); } @@ -355,7 +355,7 @@ public V sameYearAs(final T other) { (calendar1.get(Calendar.ERA) == calendar2.get(Calendar.ERA) && calendar1.get(Calendar.YEAR) == calendar2.get(Calendar.YEAR)); - verification().check(result, MessageKeys.SAME_YEAR_AS, other); + verification().report(result, MessageKeys.SAME_YEAR_AS, other); return chain(); } diff --git a/src/main/java/io/skelp/verifier/verification/DefaultVerificationProvider.java b/src/main/java/io/skelp/verifier/verification/DefaultVerificationProvider.java index 5314de3..8dc72c4 100644 --- a/src/main/java/io/skelp/verifier/verification/DefaultVerificationProvider.java +++ b/src/main/java/io/skelp/verifier/verification/DefaultVerificationProvider.java @@ -26,6 +26,8 @@ import io.skelp.verifier.message.locale.LocaleContext; import io.skelp.verifier.message.locale.LocaleContextProvider; import io.skelp.verifier.service.Services; +import io.skelp.verifier.verification.report.ReportExecutor; +import io.skelp.verifier.verification.report.ReportExecutorProvider; /** *

@@ -42,8 +44,9 @@ public final class DefaultVerificationProvider implements VerificationProvider { public Verification getVerification(final T value, final Object name) { final LocaleContext localeContext = Services.findFirstNonNullForWeightedService(LocaleContextProvider.class, LocaleContextProvider::getLocaleContext); final MessageSource messageSource = Services.findFirstNonNullForWeightedService(MessageSourceProvider.class, MessageSourceProvider::getMessageSource); + final ReportExecutor reportExecutor = Services.findFirstNonNullForWeightedService(ReportExecutorProvider.class, ReportExecutorProvider::getReportExecutor); - return new SimpleVerification<>(localeContext, messageSource, value, name); + return new SimpleVerification<>(localeContext, messageSource, reportExecutor, value, name); } @Override diff --git a/src/main/java/io/skelp/verifier/verification/SimpleVerification.java b/src/main/java/io/skelp/verifier/verification/SimpleVerification.java index def822c..ef5b481 100644 --- a/src/main/java/io/skelp/verifier/verification/SimpleVerification.java +++ b/src/main/java/io/skelp/verifier/verification/SimpleVerification.java @@ -21,12 +21,14 @@ */ package io.skelp.verifier.verification; -import java.util.function.Supplier; - import io.skelp.verifier.VerifierException; import io.skelp.verifier.message.MessageKey; import io.skelp.verifier.message.MessageSource; import io.skelp.verifier.message.locale.LocaleContext; +import io.skelp.verifier.verification.report.KeyMessageHolder; +import io.skelp.verifier.verification.report.MessageHolder; +import io.skelp.verifier.verification.report.ReportExecutor; +import io.skelp.verifier.verification.report.StringMessageHolder; /** *

@@ -44,6 +46,7 @@ public final class SimpleVerification implements Verification { private final MessageSource messageSource; private final Object name; private boolean negated; + private final ReportExecutor reportExecutor; private final T value; /** @@ -56,38 +59,38 @@ public final class SimpleVerification implements Verification { * @param messageSource * the {@link MessageSource} to be used to lookup and/or format the messages for any {@link * VerifierException VerifierExceptions} + * @param reportExecutor + * the {@link ReportExecutor} to be used to report verification results * @param value * the value being verified * @param name * the optional name used to represent {@code value} */ - public SimpleVerification(final LocaleContext localeContext, final MessageSource messageSource, final T value, final Object name) { + public SimpleVerification(final LocaleContext localeContext, final MessageSource messageSource, final ReportExecutor reportExecutor, final T value, final Object name) { this.localeContext = localeContext; this.messageSource = messageSource; + this.reportExecutor = reportExecutor; this.value = value; this.name = name; } @Override - public SimpleVerification check(final boolean result, final MessageKey key, final Object... args) { - return check(result, () -> getMessageSource().getMessage(this, key, args)); + public SimpleVerification report(final boolean result, final MessageKey key, final Object... args) { + return report(result, new KeyMessageHolder(key, args)); } @Override - public SimpleVerification check(final boolean result, final String message, final Object... args) { - return check(result, () -> getMessageSource().getMessage(this, message, args)); + public SimpleVerification report(final boolean result, final String message, final Object... args) { + return report(result, new StringMessageHolder(message, args)); } - private SimpleVerification check(final boolean result, final Supplier messageSupplier) { - if (result && isNegated() || !result && !isNegated()) { - final String errorMessage = messageSupplier.get(); + private SimpleVerification report(final boolean result, final MessageHolder messageHolder) { + try { + reportExecutor.execute(this, result, messageHolder); + } finally { setNegated(false); - - throw new VerifierException(errorMessage); } - setNegated(false); - return this; } @@ -116,6 +119,11 @@ public void setNegated(final boolean negated) { this.negated = negated; } + @Override + public ReportExecutor getReportExecutor() { + return reportExecutor; + } + @Override public T getValue() { return value; diff --git a/src/main/java/io/skelp/verifier/verification/Verification.java b/src/main/java/io/skelp/verifier/verification/Verification.java index 5116110..9a6b459 100644 --- a/src/main/java/io/skelp/verifier/verification/Verification.java +++ b/src/main/java/io/skelp/verifier/verification/Verification.java @@ -25,6 +25,9 @@ import io.skelp.verifier.message.MessageKey; import io.skelp.verifier.message.MessageSource; import io.skelp.verifier.message.locale.LocaleContext; +import io.skelp.verifier.verification.report.AssertionReporter; +import io.skelp.verifier.verification.report.ReportExecutor; +import io.skelp.verifier.verification.report.Reporter; /** *

@@ -44,13 +47,14 @@ public interface Verification { /** *

- * Checks the specified {@code result} to determine whether it passes verification. + * Reports the specified {@code result}, which may determine whether it passes verification. *

*

- * {@code result} will pass it is {@literal true} and this {@link Verification} has not be negated or if it has been - * negated and {@code result} is {@literal false}. If it does not pass, a {@link VerifierException} will be thrown - * with a suitable localized message, which can be enhanced by providing an optional {@code key} and format - * {@code args}. + * The {@code result} will pass depending on the {@link Reporter Reporters}. That said; generally, the default + * reporter ({@link AssertionReporter}) will pass {@code result} if it is {@literal true} and this + * {@link Verification} has not be negated or if it has been negated and {@code result} is {@literal false}. If it + * does not pass, a {@link VerifierException} will be thrown with a suitable localized message, which can be + * enhanced by providing an optional {@code key} and format {@code args}. *

*

* This {@link Verification} will no longer be negated as a result of calling this method, regardless of whether @@ -66,20 +70,22 @@ public interface Verification { * the optional format arguments which are used to format the localized message * @return A reference to this {@link Verification} for chaining purposes. * @throws VerifierException - * If {@code result} does not pass verification or if a problem occurs while formatting the error message. - * @see #check(boolean, String, Object...) + * If any {@link Reporter} deems that {@code result} should not pass verification. + * @see #report(boolean, String, Object...) * @since 0.2.0 */ - Verification check(boolean result, MessageKey key, Object... args); + Verification report(boolean result, MessageKey key, Object... args); /** *

- * Checks the specified {@code result} to determine whether it passes verification. + * Reports the specified {@code result}, which may determine whether it passes verification. *

*

- * {@code result} will pass it is {@literal true} and this {@link Verification} has not be negated or if it has been - * negated and {@code result} is {@literal false}. If it does not pass, a {@link VerifierException} will be thrown - * with a suitable message, which can be enhanced by providing an optional {@code message} and format {@code args}. + * The {@code result} will pass depending on the {@link Reporter Reporters}. That said; generally, the default + * reporter ({@link AssertionReporter}) will pass {@code result} if it is {@literal true} and this + * {@link Verification} has not be negated or if it has been negated and {@code result} is {@literal false}. If it + * does not pass, a {@link VerifierException} will be thrown with a suitable localized message, which can be + * enhanced by providing an optional (unlocalized) {@code message} and format {@code args}. *

*

* This {@link Verification} will no longer be negated as a result of calling this method, regardless of whether @@ -94,15 +100,16 @@ public interface Verification { * the optional format arguments which are used to format {@code message} * @return A reference to this {@link Verification} for chaining purposes. * @throws VerifierException - * If {@code result} does not pass verification or if a problem occurs while formatting the error message. - * @see #check(boolean, MessageKey, Object...) + * If any {@link Reporter} deems that {@code result} should not pass verification. + * @see #report(boolean, MessageKey, Object...) + * @since 0.2.0 */ - Verification check(boolean result, String message, Object... args); + Verification report(boolean result, String message, Object... args); /** *

* Returns the {@link LocaleContext} that is being used by this {@link Verification} to lookup and format messages - * for any {@link VerifierException VerifierExceptions} that are thrown by {@link #check}. + * for any {@link VerifierException VerifierExceptions} that are thrown by a {@link Reporter}. *

* * @return The {@link LocaleContext}. @@ -113,7 +120,7 @@ public interface Verification { /** *

* Returns the message source that is being used by this {@link Verification} to lookup and/or format the messages - * for any {@link VerifierException VerifierExceptions} that are thrown by {@link #check}. + * for any {@link VerifierException VerifierExceptions} that are thrown by a {@link Reporter}. *

* * @return The {@link MessageSource}. @@ -132,8 +139,7 @@ public interface Verification { /** *

- * Returns whether the next result that is passed to {@link #check(boolean, String, Object...)} is negated for this - * {@link Verification}. + * Returns whether the next result that is passed to {@link #report} is negated for this {@link Verification}. *

* * @return {@literal true} if the next result will be negated; otherwise {@literal false}. @@ -142,8 +148,8 @@ public interface Verification { /** *

- * Sets whether the next result that is passed to {@link #check(boolean, String, Object...)} is negated for this - * {@link Verification} to {@code negated}. + * Sets whether the next result that is passed to {@link #report} is negated for this {@link Verification} to + * {@code negated}. *

* * @param negated @@ -151,6 +157,17 @@ public interface Verification { */ void setNegated(boolean negated); + /** + *

+ * Returns the report executor that is being used by this {@link Verification} to execute {@link Reporter Reporters} + * for a verification result. + *

+ * + * @return The {@link ReportExecutor}. + * @since 0.2.0 + */ + ReportExecutor getReportExecutor(); + /** *

* Returns the value for this {@link Verification}. diff --git a/src/main/java/io/skelp/verifier/verification/VerificationProvider.java b/src/main/java/io/skelp/verifier/verification/VerificationProvider.java index ea35f74..e342fdc 100644 --- a/src/main/java/io/skelp/verifier/verification/VerificationProvider.java +++ b/src/main/java/io/skelp/verifier/verification/VerificationProvider.java @@ -29,6 +29,16 @@ * Provides {@link Verification} instances to be used to provide context to verifications based on a given value and * optional name. *

+ *

+ * {@code VerificationProviders} are registered via Java's SPI, so in order to register a custom + * {@code VerificationProvider} projects should contain should create a + * {@code io.skelp.verifier.verification.verification.VerificationProvider} file within {@code META-INF/services} + * listing the class reference for each custom {@code VerificationProvider} (e.g. + * {@code com.example.verifier.MyCustomVerificationProvider}) on separate lines. {@code VerificationProviders} are also + * {@link Weighted}, which means that they are loaded in priority order (the lower the weight, the higher the priority). + * Verifier has a built-in default {@code VerificationProvider} which is given a low priority (i.e. + * {@value #DEFAULT_IMPLEMENTATION_WEIGHT}) to allow custom implementations to be easily ordered around it. + *

* * @author Alasdair Mercer * @since 0.2.0 diff --git a/src/main/java/io/skelp/verifier/verification/report/AbstractReportExecutor.java b/src/main/java/io/skelp/verifier/verification/report/AbstractReportExecutor.java new file mode 100644 index 0000000..ff4e3dc --- /dev/null +++ b/src/main/java/io/skelp/verifier/verification/report/AbstractReportExecutor.java @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2017 Alasdair Mercer, Skelp + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package io.skelp.verifier.verification.report; + +import io.skelp.verifier.verification.Verification; + +/** + *

+ * An abstract implementation of {@link AbstractReportExecutor} that implements + * {@link #execute(Verification, boolean, MessageHolder)} to meet the contract while only requiring implementations to + * provide the list of {@link Reporter Reporters} to be executed. + *

+ * + * @author Alasdair Mercer + * @since 0.2.0 + */ +public abstract class AbstractReportExecutor implements ReportExecutor { + + @Override + public void execute(final Verification verification, final boolean result, final MessageHolder messageHolder) { + for (final Reporter reporter : getReporters()) { + if (!reporter.report(verification, result, messageHolder)) { + break; + } + } + } +} diff --git a/src/main/java/io/skelp/verifier/verification/report/AssertionReporter.java b/src/main/java/io/skelp/verifier/verification/report/AssertionReporter.java new file mode 100644 index 0000000..8a3474a --- /dev/null +++ b/src/main/java/io/skelp/verifier/verification/report/AssertionReporter.java @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2017 Alasdair Mercer, Skelp + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package io.skelp.verifier.verification.report; + +import io.skelp.verifier.VerifierException; +import io.skelp.verifier.verification.Verification; + +/** + *

+ * An implementation of {@link Reporter} that simply asserts that the given result passes verification. + *

+ *

+ * Basically, a {@link VerifierException} will be thrown in the following cases: + *

+ *
    + *
  • Result is {@literal true} and the {@link Verification} is negated
  • + *
  • Result is {@literal false} and the {@link Verification} is not negated
  • + *
+ *

+ * For this reason, this is the ideal {@link Reporter} to be last in the chain as it does what Verifier was designed to + * do. + *

+ * + * @author Alasdair Mercer + * @since 0.2.0 + */ +public final class AssertionReporter implements Reporter { + + @Override + public boolean report(final Verification verification, final boolean result, final MessageHolder messageHolder) { + if (result && verification.isNegated() || !result && !verification.isNegated()) { + throw new VerifierException(messageHolder.getMessage(verification)); + } + + return true; + } + + @Override + public int getWeight() { + return DEFAULT_IMPLEMENTATION_WEIGHT; + } +} diff --git a/src/main/java/io/skelp/verifier/verification/report/DefaultReportExecutorProvider.java b/src/main/java/io/skelp/verifier/verification/report/DefaultReportExecutorProvider.java new file mode 100644 index 0000000..0e4830e --- /dev/null +++ b/src/main/java/io/skelp/verifier/verification/report/DefaultReportExecutorProvider.java @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2017 Alasdair Mercer, Skelp + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package io.skelp.verifier.verification.report; + +import java.util.List; + +import io.skelp.verifier.service.Services; + +/** + *

+ * The default implementation of {@link ReportExecutorProvider} which provides an instance of + * {@link SimpleReportExecutor} populated with all discoverable {@link Reporter Reporters}. + *

+ * + * @author Alasdair Mercer + * @since 0.2.0 + */ +public final class DefaultReportExecutorProvider implements ReportExecutorProvider { + + @Override + public ReportExecutor getReportExecutor() { + final List reporters = Services.getWeightedServices(Reporter.class); + + return new SimpleReportExecutor(reporters); + } + + @Override + public int getWeight() { + return DEFAULT_IMPLEMENTATION_WEIGHT; + } +} diff --git a/src/main/java/io/skelp/verifier/verification/report/KeyMessageHolder.java b/src/main/java/io/skelp/verifier/verification/report/KeyMessageHolder.java new file mode 100644 index 0000000..abed0c0 --- /dev/null +++ b/src/main/java/io/skelp/verifier/verification/report/KeyMessageHolder.java @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2017 Alasdair Mercer, Skelp + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package io.skelp.verifier.verification.report; + +import io.skelp.verifier.message.MessageKey; +import io.skelp.verifier.message.MessageSource; +import io.skelp.verifier.verification.Verification; + +/** + *

+ * An immutable implementation of {@link MessageHolder} that contains the {@link MessageKey} relating to a localized + * message message and format arguments which are later passed to + * {@link MessageSource#getMessage(Verification, MessageKey, Object[])}. + *

+ * + * @author Alasdair Mercer + * @since 0.2.0 + */ +public final class KeyMessageHolder implements MessageHolder { + + private final Object[] args; + private final MessageKey key; + + /** + *

+ * Creates an instance of {@link KeyMessageHolder} for the optional message {@code key} and format {@code args} + * provided. + *

+ * + * @param key + * the optional {@link MessageKey} which provides a more detailed localized explanation of what was + * verified + * @param args + * the optional format arguments which are used to format the localized message + */ + public KeyMessageHolder(final MessageKey key, final Object[] args) { + this.key = key; + this.args = args; + } + + @Override + public String getMessage(final Verification verification) { + return verification.getMessageSource().getMessage(verification, key, args); + } +} diff --git a/src/main/java/io/skelp/verifier/verification/report/MessageHolder.java b/src/main/java/io/skelp/verifier/verification/report/MessageHolder.java new file mode 100644 index 0000000..60234c2 --- /dev/null +++ b/src/main/java/io/skelp/verifier/verification/report/MessageHolder.java @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2017 Alasdair Mercer, Skelp + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package io.skelp.verifier.verification.report; + +import io.skelp.verifier.VerifierException; +import io.skelp.verifier.verification.Verification; + +/** + *

+ * Holds a verification message to be retrieved as and when needed as a complete error message. + *

+ * + * @author Alasdair Mercer + * @since 0.2.0 + */ +public interface MessageHolder { + + /** + *

+ * Returns the complete error message being held by this {@link MessageHolder}. + *

+ * + * @param verification + * the current {@link Verification} + * @return The complete error message. + * @throws VerifierException + * If a problem occurs while trying to retrieve the message. + */ + String getMessage(Verification verification); +} diff --git a/src/main/java/io/skelp/verifier/verification/report/ReportExecutor.java b/src/main/java/io/skelp/verifier/verification/report/ReportExecutor.java new file mode 100644 index 0000000..89f0cfe --- /dev/null +++ b/src/main/java/io/skelp/verifier/verification/report/ReportExecutor.java @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2017 Alasdair Mercer, Skelp + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package io.skelp.verifier.verification.report; + +import java.util.List; + +import io.skelp.verifier.VerifierException; +import io.skelp.verifier.verification.Verification; + +/** + *

+ * Responsible for executing a chain of {@link Reporter Reporters} one after the other. + *

+ * + * @author Alasdair Mercer + * @since 0.2.0 + */ +public interface ReportExecutor { + + /** + *

+ * Executes all of the {@link Reporter Reporters} for this {@link ReportExecutor} sequentially with the information + * provided. + *

+ *

+ * Any of the {@link Reporter Reporters} may throw a {@link VerifierException} with a suitable message held in the + * {@code messageHolder} provided should they deem that {@code result} does not pass verification, breaking the + * chain, meaning none of the remaining {@link Reporter Reporters} within the chain will be executed. The chain can + * also be broken should {@link Reporter#report(Verification, boolean, MessageHolder)} return {@literal false} at + * any time. + *

+ * + * @param verification + * the current {@link Verification} + * @param result + * the result of the verification to be reported + * @param messageHolder + * the {@link MessageHolder} containing the optional message which provides a more detailed explanation of + * what was verified + * @throws VerifierException + * If any of the {@link Reporter Reporters} deem that {@code result} should not pass for verification. + */ + void execute(Verification verification, boolean result, MessageHolder messageHolder); + + /** + *

+ * Returns the reporters to be executed by this {@link ReportExecutor}. + *

+ * + * @return The {@code List} of {@link Reporter Reporters} to be executed. + */ + List getReporters(); +} diff --git a/src/main/java/io/skelp/verifier/verification/report/ReportExecutorProvider.java b/src/main/java/io/skelp/verifier/verification/report/ReportExecutorProvider.java new file mode 100644 index 0000000..f20509c --- /dev/null +++ b/src/main/java/io/skelp/verifier/verification/report/ReportExecutorProvider.java @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2017 Alasdair Mercer, Skelp + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package io.skelp.verifier.verification.report; + +import io.skelp.verifier.VerifierException; +import io.skelp.verifier.service.Weighted; + +/** + *

+ * Provides {@link ReportExecutor} instances to be used to execute {@link Reporter Reporters} for a given verification + * result, potentially to determine whether it passes. + *

+ *

+ * {@code ReportExecutorProviders} are registered via Java's SPI, so in order to register a custom + * {@code ReportExecutorProvider} projects should contain should create a + * {@code io.skelp.verifier.verification.report.ReportExecutorProvider} file within {@code META-INF/services} listing + * the class reference for each custom {@code ReportExecutorProvider} (e.g. + * {@code com.example.verifier.MyCustomReportExecutorProvider}) on separate lines. {@code ReportExecutorProviders} are + * also {@link Weighted}, which means that they are loaded in priority order (the lower the weight, the higher the + * priority). Verifier has a built-in default {@code ReportExecutorProvider} which is given a low priority (i.e. + * {@value #DEFAULT_IMPLEMENTATION_WEIGHT}) to allow custom implementations to be easily ordered around it. + *

+ * + * @author Alasdair Mercer + * @since 0.2.0 + */ +public interface ReportExecutorProvider extends Weighted { + + /** + *

+ * Returns an instance of {@link ReportExecutor}. + *

+ * + * @return The {@link ReportExecutor} instance. + * @throws VerifierException + * If a problem occurs while providing the {@link ReportExecutor} instance. + */ + ReportExecutor getReportExecutor(); +} diff --git a/src/main/java/io/skelp/verifier/verification/report/Reporter.java b/src/main/java/io/skelp/verifier/verification/report/Reporter.java new file mode 100644 index 0000000..ab63aaa --- /dev/null +++ b/src/main/java/io/skelp/verifier/verification/report/Reporter.java @@ -0,0 +1,83 @@ +/* + * Copyright (C) 2017 Alasdair Mercer, Skelp + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package io.skelp.verifier.verification.report; + +import io.skelp.verifier.VerifierException; +import io.skelp.verifier.service.Weighted; +import io.skelp.verifier.verification.Verification; + +/** + *

+ * Reports a given result, which may determine whether it passes verification, which are generally executed via a + * {@link ReportExecutor}. It should not modify the state of the {@link Verification} in any way. + *

+ *

+ * If a {@code Reporter} determines that the result has not passed verification, then it should throw a + * {@link VerifierException} with a suitable message provided by a {@link MessageHolder}. However they are not required + * to determine whether the verification has passed and can report differently instead (e.g. logging, profiling). + *

+ *

+ * When a {@code Reporter} is executed by a {@link ReportExecutor}, it can control whether the next {@code Reporter} in + * the chain gets executed. + *

+ *

+ * {@code Reporters} are registered via Java's SPI, so in order to register a custom {@code Reporter} projects should + * contain should create a {@code io.skelp.verifier.verification.report.Reporter} file within {@code META-INF/services} + * listing the class reference for each custom {@code Reporter} (e.g. {@code com.example.verifier.MyCustomReporter}) on + * separate lines. {@code Reporters} are also {@link Weighted}, which means that they are loaded in priority order (the + * lower the weight, the higher the priority). Verifier has a built-in default {@code Reporter} which is given a low + * priority (i.e. {@value #DEFAULT_IMPLEMENTATION_WEIGHT}) to allow custom implementations to be easily ordered around + * it. + *

+ * + * @author Alasdair Mercer + * @since 0.2.0 + */ +public interface Reporter extends Weighted { + + /** + *

+ * Reports the specified {@code result}, which may determine whether it passes for the given verification. + *

+ *

+ * If this {@link Reporter} determines that {@code result} has not passed verification, a {@link VerifierException} + * will be thrown with a suitable message held in the {@code messageHolder} provided. + *

+ *

+ * When this method is invoked by a {@link ReportExecutor}, the value returned by this method can be used to control + * whether the next {@link Reporter} in the chain is executed. + *

+ * + * @param verification + * the current {@link Verification} + * @param result + * the result of the verification + * @param messageHolder + * the {@link MessageHolder} containing the optional message which provides a more detailed explanation of + * what was verified + * @return {@literal true} if the next {@link Reporter} in the chain of the {@link ReportExecutor} should be + * executed; otherwise {@literal false}. + * @throws VerifierException + * If deemed that {@code result} should not pass for verification. + */ + boolean report(Verification verification, boolean result, MessageHolder messageHolder); +} diff --git a/src/main/java/io/skelp/verifier/verification/report/SimpleReportExecutor.java b/src/main/java/io/skelp/verifier/verification/report/SimpleReportExecutor.java new file mode 100644 index 0000000..dc49242 --- /dev/null +++ b/src/main/java/io/skelp/verifier/verification/report/SimpleReportExecutor.java @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2017 Alasdair Mercer, Skelp + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package io.skelp.verifier.verification.report; + +import java.util.ArrayList; +import java.util.List; + +/** + *

+ * A simple immutable implementation of {@link ReportExecutor}. + *

+ * + * @author Alasdair Mercer + * @since 0.2.0 + */ +public final class SimpleReportExecutor extends AbstractReportExecutor { + + private final List reporters; + + /** + *

+ * Creates an instance of {@link SimpleReportExecutor} for the {@code reporters} provided. + *

+ * + * @param reporters + * the {@code List} of {@link Reporter Reporters} to be used + */ + public SimpleReportExecutor(final List reporters) { + this.reporters = new ArrayList<>(reporters); + } + + @Override + public List getReporters() { + return reporters; + } +} diff --git a/src/main/java/io/skelp/verifier/verification/report/StringMessageHolder.java b/src/main/java/io/skelp/verifier/verification/report/StringMessageHolder.java new file mode 100644 index 0000000..6e60aff --- /dev/null +++ b/src/main/java/io/skelp/verifier/verification/report/StringMessageHolder.java @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2017 Alasdair Mercer, Skelp + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package io.skelp.verifier.verification.report; + +import io.skelp.verifier.message.MessageSource; +import io.skelp.verifier.verification.Verification; + +/** + *

+ * An immutable implementation of {@link MessageHolder} that contains an unlocalized string message and format arguments + * which are later passed to {@link MessageSource#getMessage(Verification, String, Object[])}. + *

+ * + * @author Alasdair Mercer + * @since 0.2.0 + */ +public final class StringMessageHolder implements MessageHolder { + + private final Object[] args; + private final String message; + + /** + *

+ * Creates an instance of {@link StringMessageHolder} for the optional {@code message} and format {@code args} + * provided. + *

+ * + * @param message + * the optional message which provides a more detailed explanation of what was verified + * @param args + * the optional format arguments which are used to format {@code message} + */ + public StringMessageHolder(final String message, final Object[] args) { + this.message = message; + this.args = args; + } + + @Override + public String getMessage(final Verification verification) { + return verification.getMessageSource().getMessage(verification, message, args); + } +} diff --git a/src/main/resources/META-INF/services/io.skelp.verifier.verification.report.ReportExecutorProvider b/src/main/resources/META-INF/services/io.skelp.verifier.verification.report.ReportExecutorProvider new file mode 100644 index 0000000..335994c --- /dev/null +++ b/src/main/resources/META-INF/services/io.skelp.verifier.verification.report.ReportExecutorProvider @@ -0,0 +1 @@ +io.skelp.verifier.verification.report.DefaultReportExecutorProvider diff --git a/src/main/resources/META-INF/services/io.skelp.verifier.verification.report.Reporter b/src/main/resources/META-INF/services/io.skelp.verifier.verification.report.Reporter new file mode 100644 index 0000000..52eaa9a --- /dev/null +++ b/src/main/resources/META-INF/services/io.skelp.verifier.verification.report.Reporter @@ -0,0 +1 @@ +io.skelp.verifier.verification.report.AssertionReporter diff --git a/src/test/java/io/skelp/verifier/AbstractCustomVerifierTestCase.java b/src/test/java/io/skelp/verifier/AbstractCustomVerifierTestCase.java index bb2d748..809ff11 100644 --- a/src/test/java/io/skelp/verifier/AbstractCustomVerifierTestCase.java +++ b/src/test/java/io/skelp/verifier/AbstractCustomVerifierTestCase.java @@ -86,7 +86,7 @@ private void testEqualToHelper(T value, Object other, boolean expected) { assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().equalTo(other)); - verify(getMockVerification()).check(eq(expected), eq(AbstractCustomVerifier.MessageKeys.EQUAL_TO), getArgsCaptor().capture()); + verify(getMockVerification()).report(eq(expected), eq(AbstractCustomVerifier.MessageKeys.EQUAL_TO), getArgsCaptor().capture()); assertSame("Passes other for message formatting", other, getArgsCaptor().getValue()); } @@ -128,7 +128,7 @@ private void testEqualToHelper(T value, Object other, Object name, boolean expec assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().equalTo(other, name)); - verify(getMockVerification()).check(eq(expected), eq(AbstractCustomVerifier.MessageKeys.EQUAL_TO), getArgsCaptor().capture()); + verify(getMockVerification()).report(eq(expected), eq(AbstractCustomVerifier.MessageKeys.EQUAL_TO), getArgsCaptor().capture()); assertSame("Passes name for message formatting", name, getArgsCaptor().getValue()); } @@ -185,7 +185,7 @@ private void testEqualToAnyHelper(T value, Object[] others, boolean expected) { assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().equalToAny(others)); - verify(getMockVerification()).check(expected, AbstractCustomVerifier.MessageKeys.EQUAL_TO_ANY, (Object) others); + verify(getMockVerification()).report(expected, AbstractCustomVerifier.MessageKeys.EQUAL_TO_ANY, (Object) others); } @Test @@ -212,7 +212,7 @@ private void testHashedAsHelper(T value, int hashCode, boolean expected) { assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().hashedAs(hashCode)); - verify(getMockVerification()).check(eq(expected), eq(AbstractCustomVerifier.MessageKeys.HASHED_AS), getArgsCaptor().capture()); + verify(getMockVerification()).report(eq(expected), eq(AbstractCustomVerifier.MessageKeys.HASHED_AS), getArgsCaptor().capture()); assertEquals("Passes hash code for message formatting", hashCode, getArgsCaptor().getValue()); } @@ -252,7 +252,7 @@ private void testInstanceOfHelper(T value, Class cls, boolean expected) { assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().instanceOf(cls)); - verify(getMockVerification()).check(eq(expected), eq(AbstractCustomVerifier.MessageKeys.INSTANCE_OF), getArgsCaptor().capture()); + verify(getMockVerification()).report(eq(expected), eq(AbstractCustomVerifier.MessageKeys.INSTANCE_OF), getArgsCaptor().capture()); assertEquals("Passes class for message formatting", cls, getArgsCaptor().getValue()); } @@ -307,7 +307,7 @@ private void testInstanceOfAllHelper(T value, Class[] classes, boolean expect assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().instanceOfAll(classes)); - verify(getMockVerification()).check(expected, AbstractCustomVerifier.MessageKeys.INSTANCE_OF_ALL, (Object) classes); + verify(getMockVerification()).report(expected, AbstractCustomVerifier.MessageKeys.INSTANCE_OF_ALL, (Object) classes); } @Test @@ -360,7 +360,7 @@ private void testInstanceOfAnyHelper(T value, Class[] classes, boolean expect assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().instanceOfAny(classes)); - verify(getMockVerification()).check(expected, AbstractCustomVerifier.MessageKeys.INSTANCE_OF_ANY, (Object) classes); + verify(getMockVerification()).report(expected, AbstractCustomVerifier.MessageKeys.INSTANCE_OF_ANY, (Object) classes); } @Test @@ -394,7 +394,7 @@ private void testNulledHelper(T value, boolean expected) { assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().nulled()); - verify(getMockVerification()).check(expected, AbstractCustomVerifier.MessageKeys.NULLED); + verify(getMockVerification()).report(expected, AbstractCustomVerifier.MessageKeys.NULLED); } @Test @@ -434,7 +434,7 @@ private void testSameAsHelper(T value, Object other, boolean expected) { assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().sameAs(other)); - verify(getMockVerification()).check(eq(expected), eq(AbstractCustomVerifier.MessageKeys.SAME_AS), getArgsCaptor().capture()); + verify(getMockVerification()).report(eq(expected), eq(AbstractCustomVerifier.MessageKeys.SAME_AS), getArgsCaptor().capture()); assertSame("Passes other for message formatting", other, getArgsCaptor().getValue()); } @@ -476,7 +476,7 @@ private void testSameAsHelper(T value, Object other, Object name, boolean expect assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().sameAs(other, name)); - verify(getMockVerification()).check(eq(expected), eq(AbstractCustomVerifier.MessageKeys.SAME_AS), getArgsCaptor().capture()); + verify(getMockVerification()).report(eq(expected), eq(AbstractCustomVerifier.MessageKeys.SAME_AS), getArgsCaptor().capture()); assertSame("Passes name for message formatting", name, getArgsCaptor().getValue()); } @@ -533,7 +533,7 @@ private void testSameAsAnyHelper(T value, Object[] others, boolean expected) { assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().sameAsAny(others)); - verify(getMockVerification()).check(expected, AbstractCustomVerifier.MessageKeys.SAME_AS_ANY, (Object) others); + verify(getMockVerification()).report(expected, AbstractCustomVerifier.MessageKeys.SAME_AS_ANY, (Object) others); } @Test @@ -563,7 +563,7 @@ private void testThatHelper(boolean expected) { assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().that(mockAssertion)); verify(mockAssertion).verify(value); - verify(getMockVerification()).check(eq(expected), isNull(String.class)); + verify(getMockVerification()).report(eq(expected), isNull(String.class)); } @Test @@ -593,7 +593,7 @@ private void testThatHelper(boolean expected, String message, Object[] args) { assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().that(mockAssertion, message, args)); verify(mockAssertion).verify(value); - verify(getMockVerification()).check(eq(expected), eq(message), getArgsCaptor().capture()); + verify(getMockVerification()).report(eq(expected), eq(message), getArgsCaptor().capture()); assertEquals("Passes args for message formatting", Arrays.asList(args), getArgsCaptor().getAllValues()); } @@ -625,7 +625,7 @@ private void testThatHelper(boolean expected, MessageKey key, Object[] args) { assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().that(mockAssertion, key, args)); verify(mockAssertion).verify(value); - verify(getMockVerification()).check(eq(expected), eq(key), getArgsCaptor().capture()); + verify(getMockVerification()).report(eq(expected), eq(key), getArgsCaptor().capture()); assertEquals("Passes args for message formatting", Arrays.asList(args), getArgsCaptor().getAllValues()); } diff --git a/src/test/java/io/skelp/verifier/CustomVerifierTestCaseBase.java b/src/test/java/io/skelp/verifier/CustomVerifierTestCaseBase.java index f1bc676..aee8005 100644 --- a/src/test/java/io/skelp/verifier/CustomVerifierTestCaseBase.java +++ b/src/test/java/io/skelp/verifier/CustomVerifierTestCaseBase.java @@ -44,6 +44,8 @@ import io.skelp.verifier.verification.TestVerificationProvider; import io.skelp.verifier.verification.Verification; import io.skelp.verifier.verification.VerificationProvider; +import io.skelp.verifier.verification.report.DefaultReportExecutorProvider; +import io.skelp.verifier.verification.report.ReportExecutor; /** *

@@ -126,6 +128,8 @@ protected static Map createMap(K[] keys, V[] values) { @Mock private MessageSource mockMessageSource; @Mock + private ReportExecutor mockReportExecutor; + @Mock private Verification mockVerification; @Mock private VerificationProvider mockVerificationProvider; @@ -136,12 +140,13 @@ protected static Map createMap(K[] keys, V[] values) { @Before public void setUp() throws Exception { - when(mockVerificationProvider.getVerification(any(), any())).thenAnswer(invocation -> new SimpleVerification<>(new SimpleLocaleContext(), new ResourceBundleMessageSource(), invocation.getArguments()[0], invocation.getArguments()[1])); + when(mockVerificationProvider.getVerification(any(), any())).thenAnswer(invocation -> new SimpleVerification<>(new SimpleLocaleContext(), new ResourceBundleMessageSource(), new DefaultReportExecutorProvider().getReportExecutor(), invocation.getArguments()[0], invocation.getArguments()[1])); TestVerificationProvider.setDelegate(mockVerificationProvider); when(mockVerification.getLocaleContext()).thenReturn(mockLocaleContext); when(mockVerification.getMessageSource()).thenReturn(mockMessageSource); + when(mockVerification.getReportExecutor()).thenReturn(mockReportExecutor); when(mockVerification.getValue()).thenAnswer(invocation -> value); value = null; @@ -165,8 +170,7 @@ public void tearDown() throws Exception { /** *

- * Returns an argument captor to be be used to capture any varargs that are passed to {@link - * Verification#check(boolean, String, Object...)}. + * Returns an argument captor to be be used to capture any varargs that are passed to {@link Verification#report}. *

* * @return An {@code ArgumentCaptor} to be used to capture optional format arguments. @@ -208,6 +212,17 @@ protected MessageSource getMockMessageSource() { return mockMessageSource; } + /** + *

+ * Returns the mock report executor being used to test the subject. + *

+ * + * @return The mock {@link ReportExecutor}. + */ + protected ReportExecutor getMockReportExecutor() { + return mockReportExecutor; + } + /** *

* Returns the mock verification being used to test the subject. diff --git a/src/test/java/io/skelp/verifier/DefaultCustomVerifierProviderTest.java b/src/test/java/io/skelp/verifier/DefaultCustomVerifierProviderTest.java index 5b16ae5..e95bef6 100644 --- a/src/test/java/io/skelp/verifier/DefaultCustomVerifierProviderTest.java +++ b/src/test/java/io/skelp/verifier/DefaultCustomVerifierProviderTest.java @@ -39,6 +39,7 @@ import io.skelp.verifier.verification.TestVerificationProvider; import io.skelp.verifier.verification.Verification; import io.skelp.verifier.verification.VerificationProvider; +import io.skelp.verifier.verification.report.DefaultReportExecutorProvider; /** *

@@ -59,7 +60,7 @@ public class DefaultCustomVerifierProviderTest { @Before public void setUp() { - when(mockVerificationProvider.getVerification(any(), any())).thenAnswer(invocation -> new SimpleVerification<>(new SimpleLocaleContext(Locale.ENGLISH), new ResourceBundleMessageSource(), invocation.getArguments()[0], invocation.getArguments()[1])); + when(mockVerificationProvider.getVerification(any(), any())).thenAnswer(invocation -> new SimpleVerification<>(new SimpleLocaleContext(Locale.ENGLISH), new ResourceBundleMessageSource(), new DefaultReportExecutorProvider().getReportExecutor(), invocation.getArguments()[0], invocation.getArguments()[1])); TestVerificationProvider.setDelegate(mockVerificationProvider); diff --git a/src/test/java/io/skelp/verifier/message/AbstractMessageSourceTestCase.java b/src/test/java/io/skelp/verifier/message/AbstractMessageSourceTestCase.java index 25ddfe8..f9af95e 100644 --- a/src/test/java/io/skelp/verifier/message/AbstractMessageSourceTestCase.java +++ b/src/test/java/io/skelp/verifier/message/AbstractMessageSourceTestCase.java @@ -400,7 +400,7 @@ public void testGetMessageWithMessageKeyWhenMessageNotFoundAndUseKeyAsDefaultMes @Test(expected = NoSuchMessageException.class) public void testGetMessageWithMessageKeyThrowsWhenMessageNotFound() throws Exception { - messageSource.getMessage(mockVerification, (MessageKey) null); + messageSource.getMessage(mockVerification, getMissingMessageKey(), null); } private void testGetMessageWithMessageKeyHelper(MessageKey key, Object[] args, boolean useKeyAsDefaultMessage, boolean negated, String expected) { diff --git a/src/test/java/io/skelp/verifier/type/BooleanVerifierTest.java b/src/test/java/io/skelp/verifier/type/BooleanVerifierTest.java index 04c48e8..de9c4a2 100644 --- a/src/test/java/io/skelp/verifier/type/BooleanVerifierTest.java +++ b/src/test/java/io/skelp/verifier/type/BooleanVerifierTest.java @@ -88,7 +88,7 @@ private void testBetweenHelper(Boolean value) { assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().between(false, true)); - verify(getMockVerification()).check(eq(true), eq(BaseComparableVerifier.MessageKeys.BETWEEN), getArgsCaptor().capture()); + verify(getMockVerification()).report(eq(true), eq(BaseComparableVerifier.MessageKeys.BETWEEN), getArgsCaptor().capture()); assertArrayEquals("Passes start and end for message formatting", new Object[]{false, true}, getArgsCaptor().getAllValues().toArray()); } @@ -108,7 +108,7 @@ private void testBetweenExclusiveHelper(Boolean value) { assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().betweenExclusive(false, true)); - verify(getMockVerification()).check(eq(false), eq(BaseComparableVerifier.MessageKeys.BETWEEN_EXCLUSIVE), getArgsCaptor().capture()); + verify(getMockVerification()).report(eq(false), eq(BaseComparableVerifier.MessageKeys.BETWEEN_EXCLUSIVE), getArgsCaptor().capture()); assertArrayEquals("Passes start and end for message formatting", new Object[]{false, true}, getArgsCaptor().getAllValues().toArray()); } @@ -133,7 +133,7 @@ private void testLessThanHelper(Boolean value, Boolean other, boolean expected) assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().lessThan(other)); - verify(getMockVerification()).check(eq(expected), eq(BaseComparableVerifier.MessageKeys.LESS_THAN), getArgsCaptor().capture()); + verify(getMockVerification()).report(eq(expected), eq(BaseComparableVerifier.MessageKeys.LESS_THAN), getArgsCaptor().capture()); assertSame("Passes other for message formatting", other, getArgsCaptor().getValue()); } @@ -158,7 +158,7 @@ private void testLessThanOrEqualToHelper(Boolean value, Boolean other, boolean e assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().lessThanOrEqualTo(other)); - verify(getMockVerification()).check(eq(expected), eq(BaseComparableVerifier.MessageKeys.LESS_THAN_OR_EQUAL_TO), getArgsCaptor().capture()); + verify(getMockVerification()).report(eq(expected), eq(BaseComparableVerifier.MessageKeys.LESS_THAN_OR_EQUAL_TO), getArgsCaptor().capture()); assertSame("Passes other for message formatting", other, getArgsCaptor().getValue()); } @@ -183,7 +183,7 @@ private void testGreaterThanHelper(Boolean value, Boolean other, boolean expecte assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().greaterThan(other)); - verify(getMockVerification()).check(eq(expected), eq(BaseComparableVerifier.MessageKeys.GREATER_THAN), getArgsCaptor().capture()); + verify(getMockVerification()).report(eq(expected), eq(BaseComparableVerifier.MessageKeys.GREATER_THAN), getArgsCaptor().capture()); assertSame("Passes other for message formatting", other, getArgsCaptor().getValue()); } @@ -208,7 +208,7 @@ private void testGreaterThanOrEqualToHelper(Boolean value, Boolean other, boolea assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().greaterThanOrEqualTo(other)); - verify(getMockVerification()).check(eq(expected), eq(BaseComparableVerifier.MessageKeys.GREATER_THAN_OR_EQUAL_TO), getArgsCaptor().capture()); + verify(getMockVerification()).report(eq(expected), eq(BaseComparableVerifier.MessageKeys.GREATER_THAN_OR_EQUAL_TO), getArgsCaptor().capture()); assertSame("Passes other for message formatting", other, getArgsCaptor().getValue()); } diff --git a/src/test/java/io/skelp/verifier/type/CharacterVerifierTest.java b/src/test/java/io/skelp/verifier/type/CharacterVerifierTest.java index e693c2c..ceb157d 100644 --- a/src/test/java/io/skelp/verifier/type/CharacterVerifierTest.java +++ b/src/test/java/io/skelp/verifier/type/CharacterVerifierTest.java @@ -212,7 +212,7 @@ private void testAlphaHelper(Character[] values, boolean expected) { assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().alpha()); } - verify(getMockVerification(), times(values.length)).check(expected, CharacterVerifier.MessageKeys.ALPHA); + verify(getMockVerification(), times(values.length)).report(expected, CharacterVerifier.MessageKeys.ALPHA); } @Test @@ -262,7 +262,7 @@ private void testAlphanumericHelper(Character[] values, boolean expected) { assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().alphanumeric()); } - verify(getMockVerification(), times(values.length)).check(expected, CharacterVerifier.MessageKeys.ALPHANUMERIC); + verify(getMockVerification(), times(values.length)).report(expected, CharacterVerifier.MessageKeys.ALPHANUMERIC); } @Test @@ -312,7 +312,7 @@ private void testAsciiHelper(Character[] values, boolean expected) { assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().ascii()); } - verify(getMockVerification(), times(values.length)).check(expected, CharacterVerifier.MessageKeys.ASCII); + verify(getMockVerification(), times(values.length)).report(expected, CharacterVerifier.MessageKeys.ASCII); } @Test @@ -362,7 +362,7 @@ private void testAsciiAlphaHelper(Character[] values, boolean expected) { assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().asciiAlpha()); } - verify(getMockVerification(), times(values.length)).check(expected, CharacterVerifier.MessageKeys.ASCII_ALPHA); + verify(getMockVerification(), times(values.length)).report(expected, CharacterVerifier.MessageKeys.ASCII_ALPHA); } @Test @@ -412,7 +412,7 @@ private void testAsciiAlphaLowerCaseHelper(Character[] values, boolean expected) assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().asciiAlphaLowerCase()); } - verify(getMockVerification(), times(values.length)).check(expected, CharacterVerifier.MessageKeys.ASCII_ALPHA_LOWER_CASE); + verify(getMockVerification(), times(values.length)).report(expected, CharacterVerifier.MessageKeys.ASCII_ALPHA_LOWER_CASE); } @Test @@ -462,7 +462,7 @@ private void testAsciiAlphaUpperCaseHelper(Character[] values, boolean expected) assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().asciiAlphaUpperCase()); } - verify(getMockVerification(), times(values.length)).check(expected, CharacterVerifier.MessageKeys.ASCII_ALPHA_UPPER_CASE); + verify(getMockVerification(), times(values.length)).report(expected, CharacterVerifier.MessageKeys.ASCII_ALPHA_UPPER_CASE); } @Test @@ -512,7 +512,7 @@ private void testAsciiAlphanumericHelper(Character[] values, boolean expected) { assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().asciiAlphanumeric()); } - verify(getMockVerification(), times(values.length)).check(expected, CharacterVerifier.MessageKeys.ASCII_ALPHANUMERIC); + verify(getMockVerification(), times(values.length)).report(expected, CharacterVerifier.MessageKeys.ASCII_ALPHANUMERIC); } @Test @@ -562,7 +562,7 @@ private void testAsciiControlHelper(Character[] values, boolean expected) { assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().asciiControl()); } - verify(getMockVerification(), times(values.length)).check(expected, CharacterVerifier.MessageKeys.ASCII_CONTROL); + verify(getMockVerification(), times(values.length)).report(expected, CharacterVerifier.MessageKeys.ASCII_CONTROL); } @Test @@ -612,7 +612,7 @@ private void testAsciiNumericHelper(Character[] values, boolean expected) { assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().asciiNumeric()); } - verify(getMockVerification(), times(values.length)).check(expected, CharacterVerifier.MessageKeys.ASCII_NUMERIC); + verify(getMockVerification(), times(values.length)).report(expected, CharacterVerifier.MessageKeys.ASCII_NUMERIC); } @Test @@ -667,7 +667,7 @@ private void testAsciiPrintableHelper(Character[] values, boolean expected) { assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().asciiPrintable()); } - verify(getMockVerification(), times(values.length)).check(expected, CharacterVerifier.MessageKeys.ASCII_PRINTABLE); + verify(getMockVerification(), times(values.length)).report(expected, CharacterVerifier.MessageKeys.ASCII_PRINTABLE); } @Test @@ -722,7 +722,7 @@ private void testLowerCaseHelper(Character[] values, boolean expected) { assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().lowerCase()); } - verify(getMockVerification(), times(values.length)).check(expected, CharacterVerifier.MessageKeys.LOWER_CASE); + verify(getMockVerification(), times(values.length)).report(expected, CharacterVerifier.MessageKeys.LOWER_CASE); } @Test @@ -777,7 +777,7 @@ private void testNumericHelper(Character[] values, boolean expected) { assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().numeric()); } - verify(getMockVerification(), times(values.length)).check(expected, CharacterVerifier.MessageKeys.NUMERIC); + verify(getMockVerification(), times(values.length)).report(expected, CharacterVerifier.MessageKeys.NUMERIC); } @Test @@ -832,7 +832,7 @@ private void testUpperCaseHelper(Character[] values, boolean expected) { assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().upperCase()); } - verify(getMockVerification(), times(values.length)).check(expected, CharacterVerifier.MessageKeys.UPPER_CASE); + verify(getMockVerification(), times(values.length)).report(expected, CharacterVerifier.MessageKeys.UPPER_CASE); } @Test @@ -882,7 +882,7 @@ private void testWhitespaceHelper(Character[] values, boolean expected) { assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().whitespace()); } - verify(getMockVerification(), times(values.length)).check(expected, CharacterVerifier.MessageKeys.WHITESPACE); + verify(getMockVerification(), times(values.length)).report(expected, CharacterVerifier.MessageKeys.WHITESPACE); } @Override diff --git a/src/test/java/io/skelp/verifier/type/ClassVerifierTest.java b/src/test/java/io/skelp/verifier/type/ClassVerifierTest.java index 2e84d40..08b5acc 100644 --- a/src/test/java/io/skelp/verifier/type/ClassVerifierTest.java +++ b/src/test/java/io/skelp/verifier/type/ClassVerifierTest.java @@ -115,7 +115,7 @@ private void testAnnotatedHelper(Class value, boolean expected) { assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().annotated()); - verify(getMockVerification()).check(expected, ClassVerifier.MessageKeys.ANNOTATED); + verify(getMockVerification()).report(expected, ClassVerifier.MessageKeys.ANNOTATED); } @Test @@ -153,7 +153,7 @@ private void testAnnotatedWithHelper(Class value, Class assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().annotatedWith(type)); - verify(getMockVerification()).check(eq(expected), eq(ClassVerifier.MessageKeys.ANNOTATED_WITH), getArgsCaptor().capture()); + verify(getMockVerification()).report(eq(expected), eq(ClassVerifier.MessageKeys.ANNOTATED_WITH), getArgsCaptor().capture()); assertSame("Passes type for message formatting", type, getArgsCaptor().getValue()); } @@ -208,7 +208,7 @@ private void testAnnotatedWithAllHelper(Class value, Class value, Class value, boolean expected) { assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().annotation()); - verify(getMockVerification()).check(expected, ClassVerifier.MessageKeys.ANNOTATION); + verify(getMockVerification()).report(expected, ClassVerifier.MessageKeys.ANNOTATION); } @Test @@ -308,7 +308,7 @@ private void testAnonymousHelper(Class value, boolean expected) { assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().anonymous()); - verify(getMockVerification()).check(expected, ClassVerifier.MessageKeys.ANONYMOUS); + verify(getMockVerification()).report(expected, ClassVerifier.MessageKeys.ANONYMOUS); } @Test @@ -331,7 +331,7 @@ private void testArrayHelper(Class value, boolean expected) { assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().array()); - verify(getMockVerification()).check(expected, ClassVerifier.MessageKeys.ARRAY); + verify(getMockVerification()).report(expected, ClassVerifier.MessageKeys.ARRAY); } @Test @@ -364,7 +364,7 @@ private void testAssignableFromHelper(Class value, Class type, boolean exp assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().assignableFrom(type)); - verify(getMockVerification()).check(eq(expected), eq(ClassVerifier.MessageKeys.ASSIGNABLE_FROM), getArgsCaptor().capture()); + verify(getMockVerification()).report(eq(expected), eq(ClassVerifier.MessageKeys.ASSIGNABLE_FROM), getArgsCaptor().capture()); assertSame("Passes type for message formatting", type, getArgsCaptor().getValue()); } @@ -389,7 +389,7 @@ private void testEnumerationHelper(Class value, boolean expected) { assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().enumeration()); - verify(getMockVerification()).check(expected, ClassVerifier.MessageKeys.ENUMERATION); + verify(getMockVerification()).report(expected, ClassVerifier.MessageKeys.ENUMERATION); } @Test @@ -412,7 +412,7 @@ private void testInterfacingHelper(Class value, boolean expected) { assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().interfacing()); - verify(getMockVerification()).check(expected, ClassVerifier.MessageKeys.INTERFACING); + verify(getMockVerification()).report(expected, ClassVerifier.MessageKeys.INTERFACING); } @Test @@ -435,7 +435,7 @@ private void testNestedHelper(Class value, boolean expected) { assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().nested()); - verify(getMockVerification()).check(expected, ClassVerifier.MessageKeys.NESTED); + verify(getMockVerification()).report(expected, ClassVerifier.MessageKeys.NESTED); } @Test @@ -468,7 +468,7 @@ private void testPrimitiveHelper(Class[] values, boolean expected) { assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().primitive()); } - verify(getMockVerification(), times(values.length)).check(expected, ClassVerifier.MessageKeys.PRIMITIVE); + verify(getMockVerification(), times(values.length)).report(expected, ClassVerifier.MessageKeys.PRIMITIVE); } @Test @@ -498,7 +498,7 @@ private void testPrimitiveOrWrapperHelper(Class[] values, boolean expected) { assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().primitiveOrWrapper()); } - verify(getMockVerification(), times(values.length)).check(expected, ClassVerifier.MessageKeys.PRIMITIVE_OR_WRAPPER); + verify(getMockVerification(), times(values.length)).report(expected, ClassVerifier.MessageKeys.PRIMITIVE_OR_WRAPPER); } @Test @@ -531,7 +531,7 @@ private void testPrimitiveWrapperHelper(Class[] values, boolean expected) { assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().primitiveWrapper()); } - verify(getMockVerification(), times(values.length)).check(expected, ClassVerifier.MessageKeys.PRIMITIVE_WRAPPER); + verify(getMockVerification(), times(values.length)).report(expected, ClassVerifier.MessageKeys.PRIMITIVE_WRAPPER); } } diff --git a/src/test/java/io/skelp/verifier/type/LocaleVerifierTest.java b/src/test/java/io/skelp/verifier/type/LocaleVerifierTest.java index 4c6bb9f..c1bea7b 100644 --- a/src/test/java/io/skelp/verifier/type/LocaleVerifierTest.java +++ b/src/test/java/io/skelp/verifier/type/LocaleVerifierTest.java @@ -162,7 +162,7 @@ private void testAvailableHelper(Locale value, Locale[] availableLocales, boolea assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().available()); - verify(getMockVerification()).check(expected, LocaleVerifier.MessageKeys.AVAILABLE); + verify(getMockVerification()).report(expected, LocaleVerifier.MessageKeys.AVAILABLE); } @Test @@ -186,7 +186,7 @@ private void testDefaultingHelper(Locale value, Locale defaultLocale, boolean ex assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().defaulting()); - verify(getMockVerification()).check(expected, LocaleVerifier.MessageKeys.DEFAULTING); + verify(getMockVerification()).report(expected, LocaleVerifier.MessageKeys.DEFAULTING); } @Test @@ -209,7 +209,7 @@ private void testCountryHelper(Locale value, String country, boolean expected) { assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().country(country)); - verify(getMockVerification()).check(eq(expected), eq(LocaleVerifier.MessageKeys.COUNTRY), getArgsCaptor().capture()); + verify(getMockVerification()).report(eq(expected), eq(LocaleVerifier.MessageKeys.COUNTRY), getArgsCaptor().capture()); assertSame("Passes country for message formatting", country, getArgsCaptor().getValue()); } @@ -234,7 +234,7 @@ private void testLanguageHelper(Locale value, String language, boolean expected) assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().language(language)); - verify(getMockVerification()).check(eq(expected), eq(LocaleVerifier.MessageKeys.LANGUAGE), getArgsCaptor().capture()); + verify(getMockVerification()).report(eq(expected), eq(LocaleVerifier.MessageKeys.LANGUAGE), getArgsCaptor().capture()); assertSame("Passes language for message formatting", language, getArgsCaptor().getValue()); } @@ -263,7 +263,7 @@ private void testScriptHelper(Locale value, String script, boolean expected) { assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().script(script)); - verify(getMockVerification()).check(eq(expected), eq(LocaleVerifier.MessageKeys.SCRIPT), getArgsCaptor().capture()); + verify(getMockVerification()).report(eq(expected), eq(LocaleVerifier.MessageKeys.SCRIPT), getArgsCaptor().capture()); assertSame("Passes script for message formatting", script, getArgsCaptor().getValue()); } @@ -288,7 +288,7 @@ private void testVariantHelper(Locale value, String variant, boolean expected) { assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().variant(variant)); - verify(getMockVerification()).check(eq(expected), eq(LocaleVerifier.MessageKeys.VARIANT), getArgsCaptor().capture()); + verify(getMockVerification()).report(eq(expected), eq(LocaleVerifier.MessageKeys.VARIANT), getArgsCaptor().capture()); assertSame("Passes variant for message formatting", variant, getArgsCaptor().getValue()); } diff --git a/src/test/java/io/skelp/verifier/type/MapVerifierTest.java b/src/test/java/io/skelp/verifier/type/MapVerifierTest.java index a4fbd2b..c2a4a7a 100644 --- a/src/test/java/io/skelp/verifier/type/MapVerifierTest.java +++ b/src/test/java/io/skelp/verifier/type/MapVerifierTest.java @@ -176,7 +176,7 @@ private void testContainAllKeysHelper(Map value, String[] keys, assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().containAllKeys(keys)); - verify(getMockVerification()).check(expected, MapVerifier.MessageKeys.CONTAIN_ALL_KEYS, (Object) keys); + verify(getMockVerification()).report(expected, MapVerifier.MessageKeys.CONTAIN_ALL_KEYS, (Object) keys); } @Test @@ -229,7 +229,7 @@ private void testContainAnyKeyHelper(Map value, String[] keys, assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().containAnyKey(keys)); - verify(getMockVerification()).check(expected, MapVerifier.MessageKeys.CONTAIN_ANY_KEY, (Object) keys); + verify(getMockVerification()).report(expected, MapVerifier.MessageKeys.CONTAIN_ANY_KEY, (Object) keys); } @Test @@ -259,7 +259,7 @@ private void testContainKeyHelper(Map value, String key, boolea assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().containKey(key)); - verify(getMockVerification()).check(eq(expected), eq(MapVerifier.MessageKeys.CONTAIN_KEY), getArgsCaptor().capture()); + verify(getMockVerification()).report(eq(expected), eq(MapVerifier.MessageKeys.CONTAIN_KEY), getArgsCaptor().capture()); assertSame("Passes key for message formatting", key, getArgsCaptor().getValue()); } diff --git a/src/test/java/io/skelp/verifier/type/StringVerifierTest.java b/src/test/java/io/skelp/verifier/type/StringVerifierTest.java index ef7d26a..423d242 100644 --- a/src/test/java/io/skelp/verifier/type/StringVerifierTest.java +++ b/src/test/java/io/skelp/verifier/type/StringVerifierTest.java @@ -196,7 +196,7 @@ private void testAlphaHelper(String value, boolean expected) { assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().alpha()); - verify(getMockVerification()).check(expected, StringVerifier.MessageKeys.ALPHA); + verify(getMockVerification()).report(expected, StringVerifier.MessageKeys.ALPHA); } @Test @@ -244,7 +244,7 @@ private void testAlphaSpaceHelper(String value, boolean expected) { assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().alphaSpace()); - verify(getMockVerification()).check(expected, StringVerifier.MessageKeys.ALPHA_SPACE); + verify(getMockVerification()).report(expected, StringVerifier.MessageKeys.ALPHA_SPACE); } @Test @@ -302,7 +302,7 @@ private void testAlphanumericHelper(String value, boolean expected) { assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().alphanumeric()); - verify(getMockVerification()).check(expected, StringVerifier.MessageKeys.ALPHANUMERIC); + verify(getMockVerification()).report(expected, StringVerifier.MessageKeys.ALPHANUMERIC); } @Test @@ -360,7 +360,7 @@ private void testAlphanumericSpaceHelper(String value, boolean expected) { assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().alphanumericSpace()); - verify(getMockVerification()).check(expected, StringVerifier.MessageKeys.ALPHANUMERIC_SPACE); + verify(getMockVerification()).report(expected, StringVerifier.MessageKeys.ALPHANUMERIC_SPACE); } @Test @@ -398,7 +398,7 @@ private void testAsciiPrintableHelper(String value, boolean expected) { assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().asciiPrintable()); - verify(getMockVerification()).check(expected, StringVerifier.MessageKeys.ASCII_PRINTABLE); + verify(getMockVerification()).report(expected, StringVerifier.MessageKeys.ASCII_PRINTABLE); } @Test @@ -426,7 +426,7 @@ private void testBlankHelper(String value, boolean expected) { assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().blank()); - verify(getMockVerification()).check(expected, StringVerifier.MessageKeys.BLANK); + verify(getMockVerification()).report(expected, StringVerifier.MessageKeys.BLANK); } @Test @@ -494,7 +494,7 @@ private void testContainHelper(String value, CharSequence other, boolean expecte assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().contain(other)); - verify(getMockVerification()).check(eq(expected), eq(StringVerifier.MessageKeys.CONTAIN), getArgsCaptor().capture()); + verify(getMockVerification()).report(eq(expected), eq(StringVerifier.MessageKeys.CONTAIN), getArgsCaptor().capture()); assertSame("Passes other for message formatting", other, getArgsCaptor().getValue()); } @@ -594,7 +594,7 @@ private void testContainAllHelper(String value, CharSequence[] others, boolean e assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().containAll(others)); - verify(getMockVerification()).check(expected, StringVerifier.MessageKeys.CONTAIN_ALL, (Object) others); + verify(getMockVerification()).report(expected, StringVerifier.MessageKeys.CONTAIN_ALL, (Object) others); } @Test @@ -692,7 +692,7 @@ private void testContainAllIgnoreCaseHelper(String value, CharSequence[] others, assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().containAllIgnoreCase(others)); - verify(getMockVerification()).check(expected, StringVerifier.MessageKeys.CONTAIN_ALL_IGNORE_CASE, (Object) others); + verify(getMockVerification()).report(expected, StringVerifier.MessageKeys.CONTAIN_ALL_IGNORE_CASE, (Object) others); } @Test @@ -770,7 +770,7 @@ private void testContainAnyHelper(String value, CharSequence[] others, boolean e assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().containAny(others)); - verify(getMockVerification()).check(expected, StringVerifier.MessageKeys.CONTAIN_ANY, (Object) others); + verify(getMockVerification()).report(expected, StringVerifier.MessageKeys.CONTAIN_ANY, (Object) others); } @Test @@ -848,7 +848,7 @@ private void testContainAnyIgnoreCaseHelper(String value, CharSequence[] others, assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().containAnyIgnoreCase(others)); - verify(getMockVerification()).check(expected, StringVerifier.MessageKeys.CONTAIN_ANY_IGNORE_CASE, (Object) others); + verify(getMockVerification()).report(expected, StringVerifier.MessageKeys.CONTAIN_ANY_IGNORE_CASE, (Object) others); } @Test @@ -936,7 +936,7 @@ private void testContainIgnoreCaseHelper(String value, CharSequence other, boole assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().containIgnoreCase(other)); - verify(getMockVerification()).check(eq(expected), eq(StringVerifier.MessageKeys.CONTAIN_IGNORE_CASE), getArgsCaptor().capture()); + verify(getMockVerification()).report(eq(expected), eq(StringVerifier.MessageKeys.CONTAIN_IGNORE_CASE), getArgsCaptor().capture()); assertSame("Passes other for message formatting", other, getArgsCaptor().getValue()); } @@ -966,7 +966,7 @@ private void testEmptyHelper(String value, boolean expected) { assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().empty()); - verify(getMockVerification()).check(expected, StringVerifier.MessageKeys.EMPTY); + verify(getMockVerification()).report(expected, StringVerifier.MessageKeys.EMPTY); } @Test @@ -1039,7 +1039,7 @@ private void testEndWithHelper(String value, CharSequence other, boolean expecte assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().endWith(other)); - verify(getMockVerification()).check(eq(expected), eq(StringVerifier.MessageKeys.END_WITH), getArgsCaptor().capture()); + verify(getMockVerification()).report(eq(expected), eq(StringVerifier.MessageKeys.END_WITH), getArgsCaptor().capture()); assertSame("Passes other for message formatting", other, getArgsCaptor().getValue()); } @@ -1124,7 +1124,7 @@ private void testEndWithAnyHelper(String value, CharSequence[] others, boolean e assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().endWithAny(others)); - verify(getMockVerification()).check(expected, StringVerifier.MessageKeys.END_WITH_ANY, (Object) others); + verify(getMockVerification()).report(expected, StringVerifier.MessageKeys.END_WITH_ANY, (Object) others); } @Test @@ -1207,7 +1207,7 @@ private void testEndWithAnyIgnoreCaseHelper(String value, CharSequence[] others, assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().endWithAnyIgnoreCase(others)); - verify(getMockVerification()).check(expected, StringVerifier.MessageKeys.END_WITH_ANY_IGNORE_CASE, (Object) others); + verify(getMockVerification()).report(expected, StringVerifier.MessageKeys.END_WITH_ANY_IGNORE_CASE, (Object) others); } @Test @@ -1280,7 +1280,7 @@ private void testEndWithIgnoreCaseHelper(String value, CharSequence other, boole assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().endWithIgnoreCase(other)); - verify(getMockVerification()).check(eq(expected), eq(StringVerifier.MessageKeys.END_WITH_IGNORE_CASE), getArgsCaptor().capture()); + verify(getMockVerification()).report(eq(expected), eq(StringVerifier.MessageKeys.END_WITH_IGNORE_CASE), getArgsCaptor().capture()); assertSame("Passes other for message formatting", other, getArgsCaptor().getValue()); } @@ -1362,7 +1362,7 @@ private void testEqualToAnyIgnoreCaseHelper(String value, CharSequence[] others, assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().equalToAnyIgnoreCase(others)); - verify(getMockVerification()).check(expected, StringVerifier.MessageKeys.EQUAL_TO_ANY_IGNORE_CASE, (Object) others); + verify(getMockVerification()).report(expected, StringVerifier.MessageKeys.EQUAL_TO_ANY_IGNORE_CASE, (Object) others); } @Test @@ -1432,7 +1432,7 @@ private void testEqualToIgnoreCaseHelper(String value, CharSequence other, boole assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().equalToIgnoreCase(other)); - verify(getMockVerification()).check(eq(expected), eq(StringVerifier.MessageKeys.EQUAL_TO_IGNORE_CASE), getArgsCaptor().capture()); + verify(getMockVerification()).report(eq(expected), eq(StringVerifier.MessageKeys.EQUAL_TO_IGNORE_CASE), getArgsCaptor().capture()); assertSame("Passes other for message formatting", other, getArgsCaptor().getValue()); } @@ -1482,7 +1482,7 @@ private void testLowerCaseHelper(String value, boolean expected) { assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().lowerCase()); - verify(getMockVerification()).check(expected, StringVerifier.MessageKeys.LOWER_CASE); + verify(getMockVerification()).report(expected, StringVerifier.MessageKeys.LOWER_CASE); } @Test @@ -1530,7 +1530,7 @@ private void testMatchHelper(String value, CharSequence regex, boolean expected) assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().match(regex)); - verify(getMockVerification()).check(eq(expected), eq(StringVerifier.MessageKeys.MATCH), getArgsCaptor().capture()); + verify(getMockVerification()).report(eq(expected), eq(StringVerifier.MessageKeys.MATCH), getArgsCaptor().capture()); assertSame("Passes regex for message formatting", regex, getArgsCaptor().getValue()); } @@ -1570,7 +1570,7 @@ private void testMatchWithPatternHelper(String value, Pattern pattern, boolean e assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().match(pattern)); - verify(getMockVerification()).check(eq(expected), eq(StringVerifier.MessageKeys.MATCH), getArgsCaptor().capture()); + verify(getMockVerification()).report(eq(expected), eq(StringVerifier.MessageKeys.MATCH), getArgsCaptor().capture()); assertSame("Passes pattern for message formatting", pattern, getArgsCaptor().getValue()); } @@ -1620,7 +1620,7 @@ private void testNumericHelper(String value, boolean expected) { assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().numeric()); - verify(getMockVerification()).check(expected, StringVerifier.MessageKeys.NUMERIC); + verify(getMockVerification()).report(expected, StringVerifier.MessageKeys.NUMERIC); } @Test @@ -1668,7 +1668,7 @@ private void testNumericSpaceHelper(String value, boolean expected) { assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().numericSpace()); - verify(getMockVerification()).check(expected, StringVerifier.MessageKeys.NUMERIC_SPACE); + verify(getMockVerification()).report(expected, StringVerifier.MessageKeys.NUMERIC_SPACE); } @Test @@ -1706,7 +1706,7 @@ private void testSizeOfHelper(String value, int size, boolean expected) { assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().sizeOf(size)); - verify(getMockVerification()).check(eq(expected), eq(StringVerifier.MessageKeys.SIZE_OF), getArgsCaptor().capture()); + verify(getMockVerification()).report(eq(expected), eq(StringVerifier.MessageKeys.SIZE_OF), getArgsCaptor().capture()); assertSame("Passes size for message formatting", size, getArgsCaptor().getValue()); } @@ -1781,7 +1781,7 @@ private void testStartWithHelper(String value, CharSequence other, boolean expec assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().startWith(other)); - verify(getMockVerification()).check(eq(expected), eq(StringVerifier.MessageKeys.START_WITH), getArgsCaptor().capture()); + verify(getMockVerification()).report(eq(expected), eq(StringVerifier.MessageKeys.START_WITH), getArgsCaptor().capture()); assertSame("Passes other for message formatting", other, getArgsCaptor().getValue()); } @@ -1866,7 +1866,7 @@ private void testStartWithAnyHelper(String value, CharSequence[] others, boolean assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().startWithAny(others)); - verify(getMockVerification()).check(expected, StringVerifier.MessageKeys.START_WITH_ANY, (Object) others); + verify(getMockVerification()).report(expected, StringVerifier.MessageKeys.START_WITH_ANY, (Object) others); } @Test @@ -1949,7 +1949,7 @@ private void testStartWithAnyIgnoreCaseHelper(String value, CharSequence[] other assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().startWithAnyIgnoreCase(others)); - verify(getMockVerification()).check(expected, StringVerifier.MessageKeys.START_WITH_ANY_IGNORE_CASE, (Object) others); + verify(getMockVerification()).report(expected, StringVerifier.MessageKeys.START_WITH_ANY_IGNORE_CASE, (Object) others); } @Test @@ -2022,7 +2022,7 @@ private void testStartWithIgnoreCaseHelper(String value, CharSequence other, boo assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().startWithIgnoreCase(other)); - verify(getMockVerification()).check(eq(expected), eq(StringVerifier.MessageKeys.START_WITH_IGNORE_CASE), getArgsCaptor().capture()); + verify(getMockVerification()).report(eq(expected), eq(StringVerifier.MessageKeys.START_WITH_IGNORE_CASE), getArgsCaptor().capture()); assertSame("Passes other for message formatting", other, getArgsCaptor().getValue()); } @@ -2072,7 +2072,7 @@ private void testUpperCaseHelper(String value, boolean expected) { assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().upperCase()); - verify(getMockVerification()).check(expected, StringVerifier.MessageKeys.UPPER_CASE); + verify(getMockVerification()).report(expected, StringVerifier.MessageKeys.UPPER_CASE); } @Override diff --git a/src/test/java/io/skelp/verifier/type/ThrowableVerifierTest.java b/src/test/java/io/skelp/verifier/type/ThrowableVerifierTest.java index 4a71fd5..b01feaf 100644 --- a/src/test/java/io/skelp/verifier/type/ThrowableVerifierTest.java +++ b/src/test/java/io/skelp/verifier/type/ThrowableVerifierTest.java @@ -109,7 +109,7 @@ private void testCausedByHelper(Throwable value, Class type, boolean expected assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().causedBy(type)); - verify(getMockVerification()).check(eq(expected), eq(ThrowableVerifier.MessageKeys.CAUSED_BY), getArgsCaptor().capture()); + verify(getMockVerification()).report(eq(expected), eq(ThrowableVerifier.MessageKeys.CAUSED_BY), getArgsCaptor().capture()); assertSame("Passes type for message formatting", type, getArgsCaptor().getValue()); } @@ -155,7 +155,7 @@ private void testCausedByHelper(Throwable value, Throwable cause, boolean expect assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().causedBy(cause)); - verify(getMockVerification()).check(eq(expected), eq(ThrowableVerifier.MessageKeys.CAUSED_BY), getArgsCaptor().capture()); + verify(getMockVerification()).report(eq(expected), eq(ThrowableVerifier.MessageKeys.CAUSED_BY), getArgsCaptor().capture()); assertSame("Passes cause for message formatting", cause, getArgsCaptor().getValue()); } @@ -201,7 +201,7 @@ private void testCausedByHelper(Throwable value, Throwable cause, Object name, b assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().causedBy(cause, name)); - verify(getMockVerification()).check(eq(expected), eq(ThrowableVerifier.MessageKeys.CAUSED_BY), getArgsCaptor().capture()); + verify(getMockVerification()).report(eq(expected), eq(ThrowableVerifier.MessageKeys.CAUSED_BY), getArgsCaptor().capture()); assertSame("Passes name for message formatting", name, getArgsCaptor().getValue()); } @@ -226,7 +226,7 @@ private void testCheckedHelper(Throwable value, boolean expected) { assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().checked()); - verify(getMockVerification()).check(expected, ThrowableVerifier.MessageKeys.CHECKED); + verify(getMockVerification()).report(expected, ThrowableVerifier.MessageKeys.CHECKED); } @Test @@ -259,7 +259,7 @@ private void testMessageHelper(Throwable value, String message, boolean expected assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().message(message)); - verify(getMockVerification()).check(eq(expected), eq(ThrowableVerifier.MessageKeys.MESSAGE), getArgsCaptor().capture()); + verify(getMockVerification()).report(eq(expected), eq(ThrowableVerifier.MessageKeys.MESSAGE), getArgsCaptor().capture()); assertSame("Passes message for message formatting", message, getArgsCaptor().getValue()); } @@ -284,7 +284,7 @@ private void testUncheckedHelper(Throwable value, boolean expected) { assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().unchecked()); - verify(getMockVerification()).check(expected, ThrowableVerifier.MessageKeys.UNCHECKED); + verify(getMockVerification()).report(expected, ThrowableVerifier.MessageKeys.UNCHECKED); } @Override diff --git a/src/test/java/io/skelp/verifier/type/base/BaseCollectionVerifierTestCase.java b/src/test/java/io/skelp/verifier/type/base/BaseCollectionVerifierTestCase.java index e2f84e6..37051ae 100644 --- a/src/test/java/io/skelp/verifier/type/base/BaseCollectionVerifierTestCase.java +++ b/src/test/java/io/skelp/verifier/type/base/BaseCollectionVerifierTestCase.java @@ -79,7 +79,7 @@ private void testContainHelper(T value, E element, boolean expected) { assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().contain(element)); - verify(getMockVerification()).check(eq(expected), eq(BaseCollectionVerifier.MessageKeys.CONTAIN), getArgsCaptor().capture()); + verify(getMockVerification()).report(eq(expected), eq(BaseCollectionVerifier.MessageKeys.CONTAIN), getArgsCaptor().capture()); assertSame("Passes element for message formatting", element, getArgsCaptor().getValue()); } @@ -134,7 +134,7 @@ private void testContainAllHelper(T value, E[] elements, boolean expected) { assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().containAll(elements)); - verify(getMockVerification()).check(expected, BaseCollectionVerifier.MessageKeys.CONTAIN_ALL, (Object) elements); + verify(getMockVerification()).report(expected, BaseCollectionVerifier.MessageKeys.CONTAIN_ALL, (Object) elements); } @Test @@ -187,7 +187,7 @@ private void testContainAnyHelper(T value, E[] elements, boolean expected) { assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().containAny(elements)); - verify(getMockVerification()).check(expected, BaseCollectionVerifier.MessageKeys.CONTAIN_ANY, (Object) elements); + verify(getMockVerification()).report(expected, BaseCollectionVerifier.MessageKeys.CONTAIN_ANY, (Object) elements); } @Test @@ -210,7 +210,7 @@ private void testEmptyHelper(T value, boolean expected) { assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().empty()); - verify(getMockVerification()).check(expected, BaseCollectionVerifier.MessageKeys.EMPTY); + verify(getMockVerification()).report(expected, BaseCollectionVerifier.MessageKeys.EMPTY); } @Test @@ -248,7 +248,7 @@ private void testSizeOfHelper(T value, int size, boolean expected) { assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().sizeOf(size)); - verify(getMockVerification()).check(eq(expected), eq(BaseCollectionVerifier.MessageKeys.SIZE_OF), getArgsCaptor().capture()); + verify(getMockVerification()).report(eq(expected), eq(BaseCollectionVerifier.MessageKeys.SIZE_OF), getArgsCaptor().capture()); assertSame("Passes size for message formatting", size, getArgsCaptor().getValue()); } @@ -298,7 +298,7 @@ private void testThatAllHelper(T value, int assertionCalls, boolean expected) { assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().thatAll(mockAssertion)); - verify(getMockVerification()).check(expected, (String) null); + verify(getMockVerification()).report(expected, (String) null); verify(mockAssertion, times(assertionCalls)).verify(any(getElementClass())); } @@ -347,8 +347,8 @@ private void testThatAllInternalHelper(T value, int assertionCalls, boolean expe assertEquals("Matches elements correctly", expected, getCustomVerifier().thatAllInternal(mockAssertion)); - verify(getMockVerification(), never()).check(anyBoolean(), any(MessageKey.class), anyVararg()); - verify(getMockVerification(), never()).check(anyBoolean(), any(String.class), anyVararg()); + verify(getMockVerification(), never()).report(anyBoolean(), any(MessageKey.class), anyVararg()); + verify(getMockVerification(), never()).report(anyBoolean(), any(String.class), anyVararg()); verify(mockAssertion, times(assertionCalls)).verify(any(getElementClass())); } @@ -397,7 +397,7 @@ private void testThatAllHelper(T value, int assertionCalls, boolean expected, St assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().thatAll(mockAssertion, message, args)); - verify(getMockVerification()).check(eq(expected), eq(message), getArgsCaptor().capture()); + verify(getMockVerification()).report(eq(expected), eq(message), getArgsCaptor().capture()); verify(mockAssertion, times(assertionCalls)).verify(any(getElementClass())); assertEquals("Passes args for message formatting", Arrays.asList(args), getArgsCaptor().getAllValues()); @@ -448,7 +448,7 @@ private void testThatAllHelper(T value, int assertionCalls, boolean expected, Me assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().thatAll(mockAssertion, key, args)); - verify(getMockVerification()).check(eq(expected), eq(key), getArgsCaptor().capture()); + verify(getMockVerification()).report(eq(expected), eq(key), getArgsCaptor().capture()); verify(mockAssertion, times(assertionCalls)).verify(any(getElementClass())); assertEquals("Passes args for message formatting", Arrays.asList(args), getArgsCaptor().getAllValues()); @@ -499,7 +499,7 @@ private void testThatAnyHelper(T value, int assertionCalls, boolean expected) { assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().thatAny(mockAssertion)); - verify(getMockVerification()).check(expected, (String) null); + verify(getMockVerification()).report(expected, (String) null); verify(mockAssertion, times(assertionCalls)).verify(any(getElementClass())); } @@ -548,8 +548,8 @@ private void testThatAnyInternalHelper(T value, int assertionCalls, boolean expe assertEquals("Matches elements correctly", expected, getCustomVerifier().thatAnyInternal(mockAssertion)); - verify(getMockVerification(), never()).check(anyBoolean(), any(MessageKey.class), anyVararg()); - verify(getMockVerification(), never()).check(anyBoolean(), any(String.class), anyVararg()); + verify(getMockVerification(), never()).report(anyBoolean(), any(MessageKey.class), anyVararg()); + verify(getMockVerification(), never()).report(anyBoolean(), any(String.class), anyVararg()); verify(mockAssertion, times(assertionCalls)).verify(any(getElementClass())); } @@ -598,7 +598,7 @@ private void testThatAnyHelper(T value, int assertionCalls, boolean expected, St assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().thatAny(mockAssertion, message, args)); - verify(getMockVerification()).check(eq(expected), eq(message), getArgsCaptor().capture()); + verify(getMockVerification()).report(eq(expected), eq(message), getArgsCaptor().capture()); verify(mockAssertion, times(assertionCalls)).verify(any(getElementClass())); assertEquals("Passes args for message formatting", Arrays.asList(args), getArgsCaptor().getAllValues()); @@ -649,7 +649,7 @@ private void testThatAnyHelper(T value, int assertionCalls, boolean expected, Me assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().thatAny(mockAssertion, key, args)); - verify(getMockVerification()).check(eq(expected), eq(key), getArgsCaptor().capture()); + verify(getMockVerification()).report(eq(expected), eq(key), getArgsCaptor().capture()); verify(mockAssertion, times(assertionCalls)).verify(any(getElementClass())); assertEquals("Passes args for message formatting", Arrays.asList(args), getArgsCaptor().getAllValues()); diff --git a/src/test/java/io/skelp/verifier/type/base/BaseComparableVerifierTestCase.java b/src/test/java/io/skelp/verifier/type/base/BaseComparableVerifierTestCase.java index 8dea6f8..6bc0a9c 100644 --- a/src/test/java/io/skelp/verifier/type/base/BaseComparableVerifierTestCase.java +++ b/src/test/java/io/skelp/verifier/type/base/BaseComparableVerifierTestCase.java @@ -98,7 +98,7 @@ private void testBetweenHelper(T value, T start, T end, boolean expected) { assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().between(start, end)); - verify(getMockVerification()).check(eq(expected), eq(BaseComparableVerifier.MessageKeys.BETWEEN), getArgsCaptor().capture()); + verify(getMockVerification()).report(eq(expected), eq(BaseComparableVerifier.MessageKeys.BETWEEN), getArgsCaptor().capture()); assertArrayEquals("Passes start and end for message formatting", new Object[]{start, end}, getArgsCaptor().getAllValues().toArray()); } @@ -153,7 +153,7 @@ private void testBetweenHelper(T value, T start, T end, Object startName, Object assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().between(start, end, startName, endName)); - verify(getMockVerification()).check(eq(expected), eq(BaseComparableVerifier.MessageKeys.BETWEEN), getArgsCaptor().capture()); + verify(getMockVerification()).report(eq(expected), eq(BaseComparableVerifier.MessageKeys.BETWEEN), getArgsCaptor().capture()); assertArrayEquals("Passes start and end names for message formatting", new Object[]{startName, endName}, getArgsCaptor().getAllValues().toArray()); } @@ -208,7 +208,7 @@ private void testBetweenExclusiveHelper(T value, T start, T end, boolean expecte assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().betweenExclusive(start, end)); - verify(getMockVerification()).check(eq(expected), eq(BaseComparableVerifier.MessageKeys.BETWEEN_EXCLUSIVE), getArgsCaptor().capture()); + verify(getMockVerification()).report(eq(expected), eq(BaseComparableVerifier.MessageKeys.BETWEEN_EXCLUSIVE), getArgsCaptor().capture()); assertArrayEquals("Passes start and end for message formatting", new Object[]{start, end}, getArgsCaptor().getAllValues().toArray()); } @@ -263,7 +263,7 @@ private void testBetweenExclusiveHelper(T value, T start, T end, Object startNam assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().betweenExclusive(start, end, startName, endName)); - verify(getMockVerification()).check(eq(expected), eq(BaseComparableVerifier.MessageKeys.BETWEEN_EXCLUSIVE), getArgsCaptor().capture()); + verify(getMockVerification()).report(eq(expected), eq(BaseComparableVerifier.MessageKeys.BETWEEN_EXCLUSIVE), getArgsCaptor().capture()); assertArrayEquals("Passes start and end names for message formatting", new Object[]{startName, endName}, getArgsCaptor().getAllValues().toArray()); } @@ -303,7 +303,7 @@ private void testGreaterThanHelper(T value, T other, boolean expected) { assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().greaterThan(other)); - verify(getMockVerification()).check(eq(expected), eq(BaseComparableVerifier.MessageKeys.GREATER_THAN), getArgsCaptor().capture()); + verify(getMockVerification()).report(eq(expected), eq(BaseComparableVerifier.MessageKeys.GREATER_THAN), getArgsCaptor().capture()); assertSame("Passes other for message formatting", other, getArgsCaptor().getValue()); } @@ -343,7 +343,7 @@ private void testGreaterThanHelper(T value, T other, Object otherName, boolean e assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().greaterThan(other, otherName)); - verify(getMockVerification()).check(eq(expected), eq(BaseComparableVerifier.MessageKeys.GREATER_THAN), getArgsCaptor().capture()); + verify(getMockVerification()).report(eq(expected), eq(BaseComparableVerifier.MessageKeys.GREATER_THAN), getArgsCaptor().capture()); assertSame("Passes other name for message formatting", otherName, getArgsCaptor().getValue()); } @@ -383,7 +383,7 @@ private void testGreaterThanOrEqualToHelper(T value, T other, boolean expected) assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().greaterThanOrEqualTo(other)); - verify(getMockVerification()).check(eq(expected), eq(BaseComparableVerifier.MessageKeys.GREATER_THAN_OR_EQUAL_TO), getArgsCaptor().capture()); + verify(getMockVerification()).report(eq(expected), eq(BaseComparableVerifier.MessageKeys.GREATER_THAN_OR_EQUAL_TO), getArgsCaptor().capture()); assertSame("Passes other for message formatting", other, getArgsCaptor().getValue()); } @@ -423,7 +423,7 @@ private void testGreaterThanOrEqualToHelper(T value, T other, Object otherName, assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().greaterThanOrEqualTo(other, otherName)); - verify(getMockVerification()).check(eq(expected), eq(BaseComparableVerifier.MessageKeys.GREATER_THAN_OR_EQUAL_TO), getArgsCaptor().capture()); + verify(getMockVerification()).report(eq(expected), eq(BaseComparableVerifier.MessageKeys.GREATER_THAN_OR_EQUAL_TO), getArgsCaptor().capture()); assertSame("Passes other name for message formatting", otherName, getArgsCaptor().getValue()); } @@ -463,7 +463,7 @@ private void testLessThanHelper(T value, T other, boolean expected) { assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().lessThan(other)); - verify(getMockVerification()).check(eq(expected), eq(BaseComparableVerifier.MessageKeys.LESS_THAN), getArgsCaptor().capture()); + verify(getMockVerification()).report(eq(expected), eq(BaseComparableVerifier.MessageKeys.LESS_THAN), getArgsCaptor().capture()); assertSame("Passes other for message formatting", other, getArgsCaptor().getValue()); } @@ -503,7 +503,7 @@ private void testLessThanHelper(T value, T other, Object otherName, boolean expe assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().lessThan(other, otherName)); - verify(getMockVerification()).check(eq(expected), eq(BaseComparableVerifier.MessageKeys.LESS_THAN), getArgsCaptor().capture()); + verify(getMockVerification()).report(eq(expected), eq(BaseComparableVerifier.MessageKeys.LESS_THAN), getArgsCaptor().capture()); assertSame("Passes other name for message formatting", otherName, getArgsCaptor().getValue()); } @@ -543,7 +543,7 @@ private void testLessThanOrEqualToHelper(T value, T other, boolean expected) { assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().lessThanOrEqualTo(other)); - verify(getMockVerification()).check(eq(expected), eq(BaseComparableVerifier.MessageKeys.LESS_THAN_OR_EQUAL_TO), getArgsCaptor().capture()); + verify(getMockVerification()).report(eq(expected), eq(BaseComparableVerifier.MessageKeys.LESS_THAN_OR_EQUAL_TO), getArgsCaptor().capture()); assertSame("Passes other for message formatting", other, getArgsCaptor().getValue()); } @@ -583,7 +583,7 @@ private void testLessThanOrEqualToHelper(T value, T other, Object otherName, boo assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().lessThanOrEqualTo(other, otherName)); - verify(getMockVerification()).check(eq(expected), eq(BaseComparableVerifier.MessageKeys.LESS_THAN_OR_EQUAL_TO), getArgsCaptor().capture()); + verify(getMockVerification()).report(eq(expected), eq(BaseComparableVerifier.MessageKeys.LESS_THAN_OR_EQUAL_TO), getArgsCaptor().capture()); assertSame("Passes other name for message formatting", otherName, getArgsCaptor().getValue()); } diff --git a/src/test/java/io/skelp/verifier/type/base/BaseNumberVerifierTestCase.java b/src/test/java/io/skelp/verifier/type/base/BaseNumberVerifierTestCase.java index 4150ad9..c22532c 100644 --- a/src/test/java/io/skelp/verifier/type/base/BaseNumberVerifierTestCase.java +++ b/src/test/java/io/skelp/verifier/type/base/BaseNumberVerifierTestCase.java @@ -66,7 +66,7 @@ private void testEvenHelper(T value, boolean expected) { assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().even()); - verify(getMockVerification()).check(expected, BaseNumberVerifier.MessageKeys.EVEN); + verify(getMockVerification()).report(expected, BaseNumberVerifier.MessageKeys.EVEN); } @Test @@ -94,7 +94,7 @@ private void testNegativeHelper(T value, boolean expected) { assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().negative()); - verify(getMockVerification()).check(expected, BaseNumberVerifier.MessageKeys.NEGATIVE); + verify(getMockVerification()).report(expected, BaseNumberVerifier.MessageKeys.NEGATIVE); } @Test @@ -122,7 +122,7 @@ private void testOddHelper(T value, boolean expected) { assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().odd()); - verify(getMockVerification()).check(expected, BaseNumberVerifier.MessageKeys.ODD); + verify(getMockVerification()).report(expected, BaseNumberVerifier.MessageKeys.ODD); } @Test @@ -150,7 +150,7 @@ private void testOneHelper(T value, boolean expected) { assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().one()); - verify(getMockVerification()).check(expected, BaseNumberVerifier.MessageKeys.ONE); + verify(getMockVerification()).report(expected, BaseNumberVerifier.MessageKeys.ONE); } @Test @@ -178,7 +178,7 @@ private void testPositiveHelper(T value, boolean expected) { assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().positive()); - verify(getMockVerification()).check(expected, BaseNumberVerifier.MessageKeys.POSITIVE); + verify(getMockVerification()).report(expected, BaseNumberVerifier.MessageKeys.POSITIVE); } @Test @@ -206,7 +206,7 @@ private void testZeroHelper(T value, boolean expected) { assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().zero()); - verify(getMockVerification()).check(expected, BaseNumberVerifier.MessageKeys.ZERO); + verify(getMockVerification()).report(expected, BaseNumberVerifier.MessageKeys.ZERO); } /** diff --git a/src/test/java/io/skelp/verifier/type/base/BaseSortableCollectionVerifierTestCase.java b/src/test/java/io/skelp/verifier/type/base/BaseSortableCollectionVerifierTestCase.java index bc785b6..61568c2 100644 --- a/src/test/java/io/skelp/verifier/type/base/BaseSortableCollectionVerifierTestCase.java +++ b/src/test/java/io/skelp/verifier/type/base/BaseSortableCollectionVerifierTestCase.java @@ -86,7 +86,7 @@ private void testSortedByHelper(T value, Comparator comparator, boolean compa verify(comparator, comparatorUseExpected ? atLeastOnce() : never()).compare(any(getElementClass()), any(getElementClass())); - verify(getMockVerification()).check(eq(expected), eq(BaseSortableCollectionVerifier.MessageKeys.SORTED_BY), getArgsCaptor().capture()); + verify(getMockVerification()).report(eq(expected), eq(BaseSortableCollectionVerifier.MessageKeys.SORTED_BY), getArgsCaptor().capture()); assertSame("Passes comparator for message formatting", comparator, getArgsCaptor().getValue()); } @@ -133,7 +133,7 @@ private void testSortedByHelper(T value, Comparator comparator, Object name, verify(comparator, comparatorUseExpected ? atLeastOnce() : never()).compare(any(getElementClass()), any(getElementClass())); - verify(getMockVerification()).check(eq(expected), eq(BaseSortableCollectionVerifier.MessageKeys.SORTED_BY), getArgsCaptor().capture()); + verify(getMockVerification()).report(eq(expected), eq(BaseSortableCollectionVerifier.MessageKeys.SORTED_BY), getArgsCaptor().capture()); assertSame("Passes name for message formatting", name, getArgsCaptor().getValue()); } diff --git a/src/test/java/io/skelp/verifier/type/base/BaseTimeVerifierTestCase.java b/src/test/java/io/skelp/verifier/type/base/BaseTimeVerifierTestCase.java index a427e3c..85ea250 100644 --- a/src/test/java/io/skelp/verifier/type/base/BaseTimeVerifierTestCase.java +++ b/src/test/java/io/skelp/verifier/type/base/BaseTimeVerifierTestCase.java @@ -158,7 +158,7 @@ private void testSameDayAsHelper(Calendar valueCalendar, Calendar otherCalendar, assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().sameDayAs(other)); - verify(getMockVerification()).check(eq(expected), eq(BaseTimeVerifier.MessageKeys.SAME_DAY_AS), getArgsCaptor().capture()); + verify(getMockVerification()).report(eq(expected), eq(BaseTimeVerifier.MessageKeys.SAME_DAY_AS), getArgsCaptor().capture()); assertSame("Passes other for message formatting", other, getArgsCaptor().getValue()); } @@ -202,7 +202,7 @@ private void testSameEraAsHelper(Calendar valueCalendar, Calendar otherCalendar, assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().sameEraAs(other)); - verify(getMockVerification()).check(eq(expected), eq(BaseTimeVerifier.MessageKeys.SAME_ERA_AS), getArgsCaptor().capture()); + verify(getMockVerification()).report(eq(expected), eq(BaseTimeVerifier.MessageKeys.SAME_ERA_AS), getArgsCaptor().capture()); assertSame("Passes other for message formatting", other, getArgsCaptor().getValue()); } @@ -271,7 +271,7 @@ private void testSameHourAsHelper(Calendar valueCalendar, Calendar otherCalendar assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().sameHourAs(other)); - verify(getMockVerification()).check(eq(expected), eq(BaseTimeVerifier.MessageKeys.SAME_HOUR_AS), getArgsCaptor().capture()); + verify(getMockVerification()).report(eq(expected), eq(BaseTimeVerifier.MessageKeys.SAME_HOUR_AS), getArgsCaptor().capture()); assertSame("Passes other for message formatting", other, getArgsCaptor().getValue()); } @@ -347,7 +347,7 @@ private void testSameMinuteAsHelper(Calendar valueCalendar, Calendar otherCalend assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().sameMinuteAs(other)); - verify(getMockVerification()).check(eq(expected), eq(BaseTimeVerifier.MessageKeys.SAME_MINUTE_AS), getArgsCaptor().capture()); + verify(getMockVerification()).report(eq(expected), eq(BaseTimeVerifier.MessageKeys.SAME_MINUTE_AS), getArgsCaptor().capture()); assertSame("Passes other for message formatting", other, getArgsCaptor().getValue()); } @@ -407,7 +407,7 @@ private void testSameMonthAsHelper(Calendar valueCalendar, Calendar otherCalenda assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().sameMonthAs(other)); - verify(getMockVerification()).check(eq(expected), eq(BaseTimeVerifier.MessageKeys.SAME_MONTH_AS), getArgsCaptor().capture()); + verify(getMockVerification()).report(eq(expected), eq(BaseTimeVerifier.MessageKeys.SAME_MONTH_AS), getArgsCaptor().capture()); assertSame("Passes other for message formatting", other, getArgsCaptor().getValue()); } @@ -491,7 +491,7 @@ private void testSameSecondAsHelper(Calendar valueCalendar, Calendar otherCalend assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().sameSecondAs(other)); - verify(getMockVerification()).check(eq(expected), eq(BaseTimeVerifier.MessageKeys.SAME_SECOND_AS), getArgsCaptor().capture()); + verify(getMockVerification()).report(eq(expected), eq(BaseTimeVerifier.MessageKeys.SAME_SECOND_AS), getArgsCaptor().capture()); assertSame("Passes other for message formatting", other, getArgsCaptor().getValue()); } @@ -535,7 +535,7 @@ private void testSameTimeAsHelper(Calendar valueCalendar, Calendar otherCalendar assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().sameTimeAs(other)); - verify(getMockVerification()).check(eq(expected), eq(BaseTimeVerifier.MessageKeys.SAME_TIME_AS), getArgsCaptor().capture()); + verify(getMockVerification()).report(eq(expected), eq(BaseTimeVerifier.MessageKeys.SAME_TIME_AS), getArgsCaptor().capture()); assertSame("Passes other for message formatting", other, getArgsCaptor().getValue()); } @@ -595,7 +595,7 @@ private void testSameWeekAsHelper(Calendar valueCalendar, Calendar otherCalendar assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().sameWeekAs(other)); - verify(getMockVerification()).check(eq(expected), eq(BaseTimeVerifier.MessageKeys.SAME_WEEK_AS), getArgsCaptor().capture()); + verify(getMockVerification()).report(eq(expected), eq(BaseTimeVerifier.MessageKeys.SAME_WEEK_AS), getArgsCaptor().capture()); assertSame("Passes other for message formatting", other, getArgsCaptor().getValue()); } @@ -647,7 +647,7 @@ private void testSameYearAsHelper(Calendar valueCalendar, Calendar otherCalendar assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().sameYearAs(other)); - verify(getMockVerification()).check(eq(expected), eq(BaseTimeVerifier.MessageKeys.SAME_YEAR_AS), getArgsCaptor().capture()); + verify(getMockVerification()).report(eq(expected), eq(BaseTimeVerifier.MessageKeys.SAME_YEAR_AS), getArgsCaptor().capture()); assertSame("Passes other for message formatting", other, getArgsCaptor().getValue()); } diff --git a/src/test/java/io/skelp/verifier/type/base/BaseTruthVerifierTestCase.java b/src/test/java/io/skelp/verifier/type/base/BaseTruthVerifierTestCase.java index 30da361..d27c69f 100644 --- a/src/test/java/io/skelp/verifier/type/base/BaseTruthVerifierTestCase.java +++ b/src/test/java/io/skelp/verifier/type/base/BaseTruthVerifierTestCase.java @@ -63,7 +63,7 @@ private void testFalsyHelper(T[] values, boolean expected) { assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().falsy()); } - verify(getMockVerification(), times(values.length)).check(expected, BaseTruthVerifier.MessageKeys.FALSY); + verify(getMockVerification(), times(values.length)).report(expected, BaseTruthVerifier.MessageKeys.FALSY); } @Test @@ -88,7 +88,7 @@ private void testTruthyHelper(T[] values, boolean expected) { assertSame("Chains reference", getCustomVerifier(), getCustomVerifier().truthy()); } - verify(getMockVerification(), times(values.length)).check(expected, BaseTruthVerifier.MessageKeys.TRUTHY); + verify(getMockVerification(), times(values.length)).report(expected, BaseTruthVerifier.MessageKeys.TRUTHY); } /** diff --git a/src/test/java/io/skelp/verifier/verification/DefaultVerificationProviderTest.java b/src/test/java/io/skelp/verifier/verification/DefaultVerificationProviderTest.java index a6e13a5..171dde4 100644 --- a/src/test/java/io/skelp/verifier/verification/DefaultVerificationProviderTest.java +++ b/src/test/java/io/skelp/verifier/verification/DefaultVerificationProviderTest.java @@ -38,6 +38,9 @@ import io.skelp.verifier.message.locale.LocaleContextProvider; import io.skelp.verifier.message.locale.TestLocaleContextProvider; import io.skelp.verifier.service.Weighted; +import io.skelp.verifier.verification.report.ReportExecutor; +import io.skelp.verifier.verification.report.ReportExecutorProvider; +import io.skelp.verifier.verification.report.TestReportExecutorProvider; /** *

@@ -57,6 +60,10 @@ public class DefaultVerificationProviderTest { private MessageSource mockMessageSource; @Mock private MessageSourceProvider mockMessageSourceProvider; + @Mock + private ReportExecutor mockReportExecutor; + @Mock + private ReportExecutorProvider mockReportExecutorProvider; private DefaultVerificationProvider provider; @@ -64,9 +71,11 @@ public class DefaultVerificationProviderTest { public void setUp() { when(mockLocaleContextProvider.getLocaleContext()).thenReturn(mockLocaleContext); when(mockMessageSourceProvider.getMessageSource()).thenReturn(mockMessageSource); + when(mockReportExecutorProvider.getReportExecutor()).thenReturn(mockReportExecutor); TestLocaleContextProvider.setDelegate(mockLocaleContextProvider); TestMessageSourceProvider.setDelegate(mockMessageSourceProvider); + TestReportExecutorProvider.setDelegate(mockReportExecutorProvider); provider = new DefaultVerificationProvider(); } @@ -75,6 +84,7 @@ public void setUp() { public void tearDown() { TestLocaleContextProvider.setDelegate(null); TestMessageSourceProvider.setDelegate(null); + TestReportExecutorProvider.setDelegate(null); } @Test @@ -85,6 +95,7 @@ public void testGetVerification() { assertTrue("Returns instance of SimpleVerification", verification instanceof SimpleVerification); assertSame("Passed LocaleContext from provider", mockLocaleContext, verification.getLocaleContext()); assertSame("Passed MessageSource from provider", mockMessageSource, verification.getMessageSource()); + assertSame("Passed ReportExecutor from provider", mockReportExecutor, verification.getReportExecutor()); assertEquals("Passed name", "foo", verification.getName()); assertEquals("Passed value", Integer.valueOf(123), verification.getValue()); } diff --git a/src/test/java/io/skelp/verifier/verification/SimpleVerificationTest.java b/src/test/java/io/skelp/verifier/verification/SimpleVerificationTest.java index 67b1631..140f019 100644 --- a/src/test/java/io/skelp/verifier/verification/SimpleVerificationTest.java +++ b/src/test/java/io/skelp/verifier/verification/SimpleVerificationTest.java @@ -22,13 +22,15 @@ package io.skelp.verifier.verification; import static org.junit.Assert.*; +import static org.mockito.AdditionalMatchers.*; import static org.mockito.Mockito.*; +import static org.mockito.Mockito.eq; -import org.junit.Rule; +import org.junit.Before; import org.junit.Test; -import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; -import org.mockito.Matchers; +import org.mockito.ArgumentCaptor; +import org.mockito.Captor; import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; @@ -36,6 +38,8 @@ import io.skelp.verifier.message.MessageKey; import io.skelp.verifier.message.MessageSource; import io.skelp.verifier.message.locale.LocaleContext; +import io.skelp.verifier.verification.report.MessageHolder; +import io.skelp.verifier.verification.report.ReportExecutor; /** *

@@ -47,149 +51,113 @@ @RunWith(MockitoJUnitRunner.class) public class SimpleVerificationTest { - @Rule - public ExpectedException thrown = ExpectedException.none(); + private static final Object TEST_NAME = "foo"; + private static final Object TEST_VALUE = 123; + @Captor + private ArgumentCaptor messageHolderCaptor; @Mock private LocaleContext mockLocaleContext; @Mock private MessageSource mockMessageSource; + @Mock + private ReportExecutor mockReportExecutor; - @Test - public void testCheckWithMessageWhenResultIsBad() { - thrown.expect(VerifierException.class); - thrown.expectMessage("i am expected"); - - SimpleVerification verification = new SimpleVerification<>(mockLocaleContext, mockMessageSource, null, null); - - when(mockMessageSource.getMessage(same(verification), eq("test"), Matchers.anyVararg())).thenReturn("i am expected"); + private SimpleVerification verification; - try { - verification.check(false, "test", "foo", "bar"); - fail("VerifierException expected"); - } catch (VerifierException e) { - assertFalse("Still not negated", verification.isNegated()); - throw e; - } + @Before + public void setUp() { + verification = new SimpleVerification<>(mockLocaleContext, mockMessageSource, mockReportExecutor, TEST_VALUE, TEST_NAME); } @Test - public void testCheckWithMessageWhenResultIsBadAndIsNegated() { - SimpleVerification verification = new SimpleVerification<>(mockLocaleContext, mockMessageSource, null, null); + public void testReportWithMessage() { verification.setNegated(true); - assertSame("Chains reference", verification, verification.check(false, "test", "foo", "bar")); - assertFalse("No longer negated", verification.isNegated()); - } + verification.report(false, "test", "foo", "bar"); - @Test - public void testCheckWithMessageWhenResultIsGood() { - SimpleVerification verification = new SimpleVerification<>(mockLocaleContext, mockMessageSource, null, null); + assertFalse("Negated state is reset", verification.isNegated()); - assertSame("Chains reference", verification, verification.check(true, "test", "foo", "bar")); - assertFalse("Still not negated", verification.isNegated()); - } + verify(mockReportExecutor).execute(eq(verification), eq(false), messageHolderCaptor.capture()); - @Test - public void testCheckWithMessageWhenResultIsGoodAndIsNegated() { - thrown.expect(VerifierException.class); - thrown.expectMessage("i am expected"); + MessageHolder messageHolder = messageHolderCaptor.getValue(); - SimpleVerification verification = new SimpleVerification<>(mockLocaleContext, mockMessageSource, null, null); - verification.setNegated(true); + assertNotNull("Message holder is never null", messageHolder); - when(mockMessageSource.getMessage(same(verification), eq("test"), Matchers.anyVararg())).thenReturn("i am expected"); + messageHolder.getMessage(verification); - try { - verification.check(true, "test", "foo", "bar"); - fail("VerifierException expected"); - } catch (VerifierException e) { - assertFalse("No longer negated", verification.isNegated()); - throw e; - } + verify(mockMessageSource).getMessage(eq(verification), eq("test"), aryEq(new Object[]{"foo", "bar"})); } - @Test - public void testCheckWithMessageKeyWhenResultIsBad() { - thrown.expect(VerifierException.class); - thrown.expectMessage("i am expected"); + @Test(expected = VerifierException.class) + public void testReportWithMessageWhenReportExecutorThrows() { + doThrow(new VerifierException()).when(mockReportExecutor).execute(eq(verification), eq(true), isA(MessageHolder.class)); - MessageKey key = () -> "test"; - SimpleVerification verification = new SimpleVerification<>(mockLocaleContext, mockMessageSource, null, null); - - when(mockMessageSource.getMessage(same(verification), same(key), Matchers.anyVararg())).thenReturn("i am expected"); + verification.setNegated(true); try { - verification.check(false, key, "foo", "bar"); - fail("VerifierException expected"); - } catch (VerifierException e) { - assertFalse("Still not negated", verification.isNegated()); - throw e; + verification.report(true, "test", "foo", "bar"); + } finally { + assertFalse("Negated state is reset", verification.isNegated()); } } @Test - public void testCheckWithMessageKeyWhenResultIsBadAndIsNegated() { - SimpleVerification verification = new SimpleVerification<>(mockLocaleContext, mockMessageSource, null, null); + public void testReportWithMessageKey() { + MessageKey key = () -> "test"; + verification.setNegated(true); - assertSame("Chains reference", verification, verification.check(false, () -> "test", "foo", "bar")); - assertFalse("No longer negated", verification.isNegated()); - } + verification.report(false, key, "foo", "bar"); - @Test - public void testCheckWithMessageKeyWhenResultIsGood() { - SimpleVerification verification = new SimpleVerification<>(mockLocaleContext, mockMessageSource, null, null); + assertFalse("Negated state is reset", verification.isNegated()); + + verify(mockReportExecutor).execute(eq(verification), eq(false), messageHolderCaptor.capture()); + + MessageHolder messageHolder = messageHolderCaptor.getValue(); - assertSame("Chains reference", verification, verification.check(true, () -> "test", "foo", "bar")); - assertFalse("Still not negated", verification.isNegated()); + assertNotNull("Message holder is never null", messageHolder); + + messageHolder.getMessage(verification); + + verify(mockMessageSource).getMessage(eq(verification), eq(key), aryEq(new Object[]{"foo", "bar"})); } - @Test - public void testCheckWithMessageKeyWhenResultIsGoodAndIsNegated() { - thrown.expect(VerifierException.class); - thrown.expectMessage("i am expected"); + @Test(expected = VerifierException.class) + public void testReportWithMessageKeyWhenReportExecutorThrows() { + doThrow(new VerifierException()).when(mockReportExecutor).execute(eq(verification), eq(true), isA(MessageHolder.class)); - MessageKey key = () -> "test"; - SimpleVerification verification = new SimpleVerification<>(mockLocaleContext, mockMessageSource, null, null); verification.setNegated(true); - when(mockMessageSource.getMessage(same(verification), same(key), Matchers.anyVararg())).thenReturn("i am expected"); - try { - verification.check(true, key, "foo", "bar"); - fail("VerifierException expected"); - } catch (VerifierException e) { - assertFalse("No longer negated", verification.isNegated()); - throw e; + verification.report(true, () -> "test", "foo", "bar"); + } finally { + assertFalse("Negated state is reset", verification.isNegated()); } } @Test public void testLocaleContext() { - SimpleVerification verification = new SimpleVerification<>(mockLocaleContext, null, null, null); - assertEquals("LocaleContext property is readable", mockLocaleContext, verification.getLocaleContext()); } @Test public void testMessageSource() { - SimpleVerification verification = new SimpleVerification<>(null, mockMessageSource, null, null); - assertEquals("MessageSource property is readable", mockMessageSource, verification.getMessageSource()); } @Test - public void testName() { - SimpleVerification verification = new SimpleVerification<>(null, null, null, "foo"); + public void testReportExecutor() { + assertEquals("ReportExecutor property is readable", mockReportExecutor, verification.getReportExecutor()); + } - assertEquals("Name property is readable", "foo", verification.getName()); + @Test + public void testName() { + assertEquals("Name property is readable", TEST_NAME, verification.getName()); } @Test public void testNegated() { - SimpleVerification verification = new SimpleVerification<>(null, null, null, null); - assertFalse("Negated property is readable and is false by default", verification.isNegated()); verification.setNegated(true); @@ -199,8 +167,6 @@ public void testNegated() { @Test public void testValue() { - SimpleVerification verification = new SimpleVerification<>(null, null, 123, null); - - assertEquals("Value property is readable", 123, verification.getValue()); + assertEquals("Value property is readable", TEST_VALUE, verification.getValue()); } } diff --git a/src/test/java/io/skelp/verifier/verification/report/AbstractReportExecutorTestCase.java b/src/test/java/io/skelp/verifier/verification/report/AbstractReportExecutorTestCase.java new file mode 100644 index 0000000..e6f500c --- /dev/null +++ b/src/test/java/io/skelp/verifier/verification/report/AbstractReportExecutorTestCase.java @@ -0,0 +1,154 @@ +/* + * Copyright (C) 2017 Alasdair Mercer, Skelp + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package io.skelp.verifier.verification.report; + +import static org.junit.Assert.*; +import static org.mockito.Mockito.*; + +import java.util.Arrays; +import java.util.List; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.experimental.theories.DataPoints; +import org.junit.experimental.theories.Theories; +import org.junit.experimental.theories.Theory; +import org.junit.rules.ExpectedException; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +import io.skelp.verifier.VerifierException; +import io.skelp.verifier.verification.Verification; + +/** + *

+ * Test case for {@link AbstractReportExecutor} implementation classes. + *

+ * + * @param + * the type of the {@link AbstractReportExecutor} being tested + * @author Alasdair Mercer + */ +@RunWith(Theories.class) +public abstract class AbstractReportExecutorTestCase { + + @DataPoints + public static final boolean[] DATA_POINTS = {true, false}; + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Mock + private MessageHolder mockMessageHolder; + @Mock + private Reporter mockReporter1; + @Mock + private Reporter mockReporter2; + @Mock + private Reporter mockReporter3; + @Mock + private Verification mockVerification; + + private List reporters; + + private T reportExecutor; + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + + reporters = Arrays.asList(mockReporter1, mockReporter2, mockReporter3); + + reportExecutor = createReportExecutor(reporters); + } + + @Theory + public void testExecute(boolean result) { + when(mockReporter1.report(mockVerification, result, mockMessageHolder)).thenReturn(true); + when(mockReporter2.report(mockVerification, result, mockMessageHolder)).thenReturn(true); + when(mockReporter3.report(mockVerification, result, mockMessageHolder)).thenReturn(true); + + reportExecutor.execute(mockVerification, result, mockMessageHolder); + + verify(mockReporter1).report(mockVerification, result, mockMessageHolder); + verify(mockReporter2).report(mockVerification, result, mockMessageHolder); + verify(mockReporter3).report(mockVerification, result, mockMessageHolder); + } + + @Theory + public void testExecuteWhenReporterBlocksNext(boolean result) { + when(mockReporter1.report(mockVerification, result, mockMessageHolder)).thenReturn(true); + when(mockReporter2.report(mockVerification, result, mockMessageHolder)).thenReturn(false); + when(mockReporter3.report(mockVerification, result, mockMessageHolder)).thenReturn(true); + + reportExecutor.execute(mockVerification, result, mockMessageHolder); + + verify(mockReporter1).report(mockVerification, result, mockMessageHolder); + verify(mockReporter2).report(mockVerification, result, mockMessageHolder); + verify(mockReporter3, never()).report(mockVerification, result, mockMessageHolder); + } + + @Theory + public void testExecuteWhenReporterThrows(boolean result) { + thrown.expect(VerifierException.class); + + when(mockReporter1.report(mockVerification, result, mockMessageHolder)).thenReturn(true); + when(mockReporter2.report(mockVerification, result, mockMessageHolder)).thenThrow(new VerifierException()); + when(mockReporter3.report(mockVerification, result, mockMessageHolder)).thenReturn(true); + + try { + reportExecutor.execute(mockVerification, result, mockMessageHolder); + } finally { + verify(mockReporter1).report(mockVerification, result, mockMessageHolder); + verify(mockReporter2).report(mockVerification, result, mockMessageHolder); + verify(mockReporter3, never()).report(mockVerification, result, mockMessageHolder); + } + } + + @Test + public void testGetReporters() { + assertEquals("Has correct list of reporters", reporters, reportExecutor.getReporters()); + } + + /** + *

+ * Creates an instance of the reporter executor test subject to be tested using the {@code reporters} provided. + *

+ * + * @param reporters + * the {@link Reporter Reporters} to be used + * @return The {@link AbstractReportExecutor} to be tested.F + */ + protected abstract T createReportExecutor(List reporters); + + /** + *

+ * Returns the reporters being used to test the subject. + *

+ * + * @return The {@code List} of {@link Reporter Reporters}. + */ + protected List getReporters() { + return reporters; + } +} diff --git a/src/test/java/io/skelp/verifier/verification/report/AssertionReporterTest.java b/src/test/java/io/skelp/verifier/verification/report/AssertionReporterTest.java new file mode 100644 index 0000000..91558a3 --- /dev/null +++ b/src/test/java/io/skelp/verifier/verification/report/AssertionReporterTest.java @@ -0,0 +1,103 @@ +/* + * Copyright (C) 2017 Alasdair Mercer, Skelp + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package io.skelp.verifier.verification.report; + +import static org.junit.Assert.*; +import static org.mockito.Mockito.*; + +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; + +import io.skelp.verifier.VerifierException; +import io.skelp.verifier.service.Weighted; +import io.skelp.verifier.verification.Verification; + +/** + *

+ * Tests for the {@link AssertionReporter} class. + *

+ * + * @author Alasdair Mercer + */ +@RunWith(MockitoJUnitRunner.class) +public class AssertionReporterTest { + + private static final String TEST_MESSAGE = "i am expected"; + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Mock + private MessageHolder mockMessageHolder; + @Mock + private Verification mockVerification; + + private AssertionReporter reporter; + + @Before + public void setUp() { + when(mockMessageHolder.getMessage(mockVerification)).thenReturn(TEST_MESSAGE); + + reporter = new AssertionReporter(); + } + + @Test + public void testReportWhenResultIsFalse() { + testReportHelper(false, false, true); + } + + @Test + public void testReportWhenResultIsFalseAndVerificationIsNegated() { + testReportHelper(true, false, false); + } + + @Test + public void testReportWhenResultIsTrue() { + testReportHelper(false, true, false); + } + + @Test + public void testReportWhenResultIsTrueAndVerificationIsNegated() { + testReportHelper(true, true, true); + } + + private void testReportHelper(boolean negated, boolean result, boolean exceptionExpected) { + if (exceptionExpected) { + thrown.expect(VerifierException.class); + thrown.expectMessage(TEST_MESSAGE); + } + + when(mockVerification.isNegated()).thenReturn(negated); + + assertTrue("Never returns false", reporter.report(mockVerification, result, mockMessageHolder)); + } + + @Test + public void testGetWeight() { + assertEquals("Has default implementation weight", Weighted.DEFAULT_IMPLEMENTATION_WEIGHT, reporter.getWeight()); + } +} diff --git a/src/test/java/io/skelp/verifier/verification/report/DefaultReportExecutorProviderTest.java b/src/test/java/io/skelp/verifier/verification/report/DefaultReportExecutorProviderTest.java new file mode 100644 index 0000000..d66bfec --- /dev/null +++ b/src/test/java/io/skelp/verifier/verification/report/DefaultReportExecutorProviderTest.java @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2017 Alasdair Mercer, Skelp + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package io.skelp.verifier.verification.report; + +import static org.junit.Assert.*; + +import java.util.List; +import org.junit.Before; +import org.junit.Test; + +import io.skelp.verifier.service.Weighted; + +/** + *

+ * Tests for the {@link DefaultReportExecutorProvider} class. + *

+ * + * @author Alasdair Mercer + */ +public class DefaultReportExecutorProviderTest { + + private static void assertReporters(ReportExecutor reportExecutor, Class[] reporterClasses) { + List reporters = reportExecutor.getReporters(); + + assertNotNull("Has reporters", reporters); + assertEquals("Has correct number of reporters", reporterClasses.length, reporters.size()); + + for (int i = 0; i < reporterClasses.length; i++) { + Reporter reporter = reporters.get(i); + Class reporterClass = reporterClasses[i]; + + assertNotNull("Reporter[" + i + "] is never null", reporter); + assertTrue("Reporter[" + i + "] is of expected type", reporterClass.isInstance(reporter)); + } + } + + private DefaultReportExecutorProvider provider; + + @Before + public void setUp() { + provider = new DefaultReportExecutorProvider(); + } + + @Test + public void testGetReportExecutor() { + ReportExecutor reportExecutor = provider.getReportExecutor(); + + assertNotNull("Never returns null", reportExecutor); + assertTrue("Returns instance of SimpleReportExecutor", reportExecutor instanceof SimpleReportExecutor); + + assertReporters(reportExecutor, new Class[]{AssertionReporter.class}); + } + + @Test + public void testGetWeight() { + assertEquals("Has default implementation weight", Weighted.DEFAULT_IMPLEMENTATION_WEIGHT, provider.getWeight()); + } +} diff --git a/src/test/java/io/skelp/verifier/verification/report/KeyMessageHolderTest.java b/src/test/java/io/skelp/verifier/verification/report/KeyMessageHolderTest.java new file mode 100644 index 0000000..720f2a7 --- /dev/null +++ b/src/test/java/io/skelp/verifier/verification/report/KeyMessageHolderTest.java @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2017 Alasdair Mercer, Skelp + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package io.skelp.verifier.verification.report; + +import static org.junit.Assert.*; +import static org.mockito.Mockito.*; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; + +import io.skelp.verifier.message.MessageKey; +import io.skelp.verifier.message.MessageSource; +import io.skelp.verifier.verification.Verification; + +/** + *

+ * Tests for the {@link KeyMessageHolder} class. + *

+ * + * @author Alasdair Mercer + */ +@RunWith(MockitoJUnitRunner.class) +public class KeyMessageHolderTest { + + @Mock + private MessageSource mockMessageSource; + @Mock + private Verification mockVerification; + + @Before + public void setUp() { + when(mockVerification.getMessageSource()).thenReturn(mockMessageSource); + } + + @Test + public void testGetMessage() { + String expected = "i am expected"; + MessageKey key = () -> "test"; + Object[] args = new Object[]{"foo", "bar"}; + + when(mockMessageSource.getMessage(mockVerification, key, args)).thenReturn(expected); + + KeyMessageHolder holder = new KeyMessageHolder(key, args); + assertEquals("Uses message source to return message", expected, holder.getMessage(mockVerification)); + } +} diff --git a/src/test/java/io/skelp/verifier/verification/report/SimpleReportExecutorTest.java b/src/test/java/io/skelp/verifier/verification/report/SimpleReportExecutorTest.java new file mode 100644 index 0000000..f5502d6 --- /dev/null +++ b/src/test/java/io/skelp/verifier/verification/report/SimpleReportExecutorTest.java @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2017 Alasdair Mercer, Skelp + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package io.skelp.verifier.verification.report; + +import java.util.List; + +/** + *

+ * Tests for the {@link SimpleReportExecutor} class. + *

+ * + * @author Alasdair Mercer + */ +public class SimpleReportExecutorTest extends AbstractReportExecutorTestCase { + + @Override + protected SimpleReportExecutor createReportExecutor(List reporters) { + return new SimpleReportExecutor(reporters); + } +} diff --git a/src/test/java/io/skelp/verifier/verification/report/StringMessageHolderTest.java b/src/test/java/io/skelp/verifier/verification/report/StringMessageHolderTest.java new file mode 100644 index 0000000..ec1cc5c --- /dev/null +++ b/src/test/java/io/skelp/verifier/verification/report/StringMessageHolderTest.java @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2017 Alasdair Mercer, Skelp + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package io.skelp.verifier.verification.report; + +import static org.junit.Assert.*; +import static org.mockito.Mockito.*; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; + +import io.skelp.verifier.message.MessageSource; +import io.skelp.verifier.verification.Verification; + +/** + *

+ * Tests for the {@link StringMessageHolder} class. + *

+ * + * @author Alasdair Mercer + */ +@RunWith(MockitoJUnitRunner.class) +public class StringMessageHolderTest { + + @Mock + private MessageSource mockMessageSource; + @Mock + private Verification mockVerification; + + @Before + public void setUp() { + when(mockVerification.getMessageSource()).thenReturn(mockMessageSource); + } + + @Test + public void testGetMessage() { + String expected = "i am expected"; + String message = "test"; + Object[] args = new Object[]{"foo", "bar"}; + + when(mockMessageSource.getMessage(mockVerification, message, args)).thenReturn(expected); + + StringMessageHolder holder = new StringMessageHolder(message, args); + assertEquals("Uses message source to return message", expected, holder.getMessage(mockVerification)); + } +} diff --git a/src/test/java/io/skelp/verifier/verification/report/TestReportExecutorProvider.java b/src/test/java/io/skelp/verifier/verification/report/TestReportExecutorProvider.java new file mode 100644 index 0000000..f2965e8 --- /dev/null +++ b/src/test/java/io/skelp/verifier/verification/report/TestReportExecutorProvider.java @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2017 Alasdair Mercer, Skelp + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package io.skelp.verifier.verification.report; + +/** + *

+ * An implementation of {@link ReportExecutorProvider} that is intended to be used for test purposes only by allowing + * tests to register a delegate (normally a mock). + *

+ *

+ * Individual tests are also responsible for ensuring that the delegate is cleared in their tear down to avoid + * potentially affecting other unit tests. + *

+ * + * @author Alasdair Mercer + */ +public final class TestReportExecutorProvider implements ReportExecutorProvider { + + private static ReportExecutorProvider delegate; + + /** + *

+ * Returns the delegate for this {@link TestReportExecutorProvider}. + *

+ * + * @return The delegate {@link ReportExecutorProvider} or {@literal null} if none has been specified. + */ + public static ReportExecutorProvider getDelegate() { + return delegate; + } + + /** + *

+ * Sets the delegate for this {@link TestReportExecutorProvider} to {@code delegate}. + *

+ * + * @param delegate + * the delegate {@link ReportExecutorProvider} to be set (may be {@literal null}) + */ + public static void setDelegate(ReportExecutorProvider delegate) { + TestReportExecutorProvider.delegate = delegate; + } + + @Override + public ReportExecutor getReportExecutor() { + return delegate != null ? delegate.getReportExecutor() : null; + } + + @Override + public int getWeight() { + return 0; + } +} diff --git a/src/test/resources/META-INF/services/io.skelp.verifier.verification.report.ReportExecutorProvider b/src/test/resources/META-INF/services/io.skelp.verifier.verification.report.ReportExecutorProvider new file mode 100644 index 0000000..c114787 --- /dev/null +++ b/src/test/resources/META-INF/services/io.skelp.verifier.verification.report.ReportExecutorProvider @@ -0,0 +1,2 @@ +io.skelp.verifier.verification.report.DefaultReportExecutorProvider +io.skelp.verifier.verification.report.TestReportExecutorProvider