|
| 1 | +/* |
| 2 | + * Copyright 2023 webtau maintainers |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package org.testingisdocumenting.webtau.expectation.equality; |
| 18 | + |
| 19 | +import org.testingisdocumenting.webtau.data.ValuePath; |
| 20 | +import org.testingisdocumenting.webtau.data.render.PrettyPrintable; |
| 21 | +import org.testingisdocumenting.webtau.data.render.PrettyPrinter; |
| 22 | +import org.testingisdocumenting.webtau.expectation.ValueMatcher; |
| 23 | +import org.testingisdocumenting.webtau.reporter.TokenizedMessage; |
| 24 | + |
| 25 | +import static org.testingisdocumenting.webtau.WebTauCore.*; |
| 26 | + |
| 27 | +public class AnyValueMatcher implements ValueMatcher, PrettyPrintable { |
| 28 | + @Override |
| 29 | + public TokenizedMessage matchingTokenizedMessage(ValuePath actualPath, Object actual) { |
| 30 | + return tokenizedMessage().matcher("to match any value"); |
| 31 | + } |
| 32 | + |
| 33 | + @Override |
| 34 | + public TokenizedMessage matchedTokenizedMessage(ValuePath actualPath, Object actual) { |
| 35 | + return tokenizedMessage().matcher("matches every value"); |
| 36 | + } |
| 37 | + |
| 38 | + @Override |
| 39 | + public TokenizedMessage mismatchedTokenizedMessage(ValuePath actualPath, Object actual) { |
| 40 | + throw new IllegalStateException(); |
| 41 | + } |
| 42 | + |
| 43 | + @Override |
| 44 | + public boolean matches(ValuePath actualPath, Object actual) { |
| 45 | + return true; |
| 46 | + } |
| 47 | + |
| 48 | + @Override |
| 49 | + public TokenizedMessage negativeMatchingTokenizedMessage(ValuePath actualPath, Object actual) { |
| 50 | + return tokenizedMessage().matcher("to mismatch any value"); |
| 51 | + } |
| 52 | + |
| 53 | + @Override |
| 54 | + public TokenizedMessage negativeMatchedTokenizedMessage(ValuePath actualPath, Object actual) { |
| 55 | + throw new IllegalStateException(); |
| 56 | + } |
| 57 | + |
| 58 | + @Override |
| 59 | + public TokenizedMessage negativeMismatchedTokenizedMessage(ValuePath actualPath, Object actual) { |
| 60 | + return tokenizedMessage().id("anyValue").matcher("matches every value"); |
| 61 | + } |
| 62 | + |
| 63 | + @Override |
| 64 | + public boolean negativeMatches(ValuePath actualPath, Object actual) { |
| 65 | + return false; |
| 66 | + } |
| 67 | + |
| 68 | + @Override |
| 69 | + public void prettyPrint(PrettyPrinter printer) { |
| 70 | + printer.printDelimiter("<"); |
| 71 | + printer.print(PrettyPrinter.CLASSIFIER_COLOR, "any value"); |
| 72 | + printer.printDelimiter(">"); |
| 73 | + } |
| 74 | + |
| 75 | + @Override |
| 76 | + public String toString() { |
| 77 | + return PrettyPrinter.renderAsTextWithoutColors(this); |
| 78 | + } |
| 79 | +} |
0 commit comments