| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| CodeEq |
|
| 0.0;0 |
| 1 | // Copyright 2006 The Apache Software Foundation | |
| 2 | // | |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); | |
| 4 | // you may not use this file except in compliance with the License. | |
| 5 | // You may obtain a copy of the License at | |
| 6 | // | |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 | |
| 8 | // | |
| 9 | // Unless required by applicable law or agreed to in writing, software | |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, | |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 12 | // See the License for the specific language governing permissions and | |
| 13 | // limitations under the License. | |
| 14 | ||
| 15 | package org.apache.tapestry5.internal.test; | |
| 16 | ||
| 17 | import static org.easymock.EasyMock.reportMatcher; | |
| 18 | import org.easymock.IArgumentMatcher; | |
| 19 | ||
| 20 | /** | |
| 21 | * Special version of string equality used to compare two snippets of code. This is somewhat simpleminded (it certainly | |
| 22 | * doesn't understand about literal strings in quotes). It works by eliminating unecessary whitespace around curly | |
| 23 | * braces, then reducing all whitespace to a single space. | |
| 24 | */ | |
| 25 | public class CodeEq implements IArgumentMatcher | |
| 26 | { | |
| 27 | private final String code; | |
| 28 | ||
| 29 | public CodeEq(String input) | |
| 30 | 10 | { |
| 31 | 10 | code = strip(input); |
| 32 | 10 | } |
| 33 | ||
| 34 | public boolean matches(Object argument) | |
| 35 | { | |
| 36 | 10 | String string = (String) argument; |
| 37 | 10 | String stripped = strip(string); |
| 38 | ||
| 39 | 10 | return code.equals(stripped); |
| 40 | } | |
| 41 | ||
| 42 | public void appendTo(StringBuffer buffer) | |
| 43 | { | |
| 44 | 0 | buffer.append("codeEq("); |
| 45 | 0 | buffer.append(code); |
| 46 | 0 | buffer.append(")"); |
| 47 | 0 | } |
| 48 | ||
| 49 | public static String codeEq(String input) | |
| 50 | { | |
| 51 | 10 | reportMatcher(new CodeEq(input)); |
| 52 | ||
| 53 | 10 | return null; |
| 54 | } | |
| 55 | ||
| 56 | static String strip(String input) | |
| 57 | { | |
| 58 | 20 | return input.trim().replaceAll("\\s*\\{\\s*", "{").replaceAll("\\s*\\}\\s*", "}") |
| 59 | .replaceAll("\\s+", " "); | |
| 60 | } | |
| 61 | } |