001: /*
002: * Copyright (c) 2003-2007 JGoodies Karsten Lentzsch. All Rights Reserved.
003: *
004: * Redistribution and use in source and binary forms, with or without
005: * modification, are permitted provided that the following conditions are met:
006: *
007: * o Redistributions of source code must retain the above copyright notice,
008: * this list of conditions and the following disclaimer.
009: *
010: * o Redistributions in binary form must reproduce the above copyright notice,
011: * this list of conditions and the following disclaimer in the documentation
012: * and/or other materials provided with the distribution.
013: *
014: * o Neither the name of JGoodies Karsten Lentzsch nor the names of
015: * its contributors may be used to endorse or promote products derived
016: * from this software without specific prior written permission.
017: *
018: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
019: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
020: * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
021: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
022: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
023: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
024: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
025: * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
026: * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
027: * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
028: * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
029: */
030:
031: package com.jgoodies.validation.tests;
032:
033: import com.jgoodies.validation.Severity;
034: import com.jgoodies.validation.ValidationMessage;
035: import com.jgoodies.validation.ValidationResult;
036: import com.jgoodies.validation.message.SimpleValidationMessage;
037:
038: /**
039: * Consists only of static fields for prepared ValidationResults
040: * used by different Validation test cases. The result names
041: * are an encoded form of their content:
042: * <code>E1</code> is a result with just error1,
043: * <code>E1W2</code> is a result with error1 and warning2,
044: * <code>E1E2W1</code> is a result error1, error2 and warning1.
045: *
046: * @author Karsten Lentzsch
047: * @version $Revision: 1.3 $
048: */
049: public final class ValidationResults {
050:
051: public static final Object KEY1;
052: public static final Object KEY2;
053: public static final Object KEY3;
054:
055: public static final ValidationResult E1;
056: public static final ValidationResult E2;
057: public static final ValidationResult W1;
058: public static final ValidationResult W2;
059:
060: public static final ValidationResult E1E1;
061: public static final ValidationResult E1E2;
062: public static final ValidationResult E1W1;
063: public static final ValidationResult E1W2;
064:
065: public static final ValidationResult E2E1;
066: public static final ValidationResult E2E2;
067: public static final ValidationResult E2W1;
068: public static final ValidationResult E2W2;
069:
070: public static final ValidationResult W1E1;
071: public static final ValidationResult W1E2;
072: public static final ValidationResult W1W1;
073: public static final ValidationResult W1W2;
074:
075: public static final ValidationResult W2E1;
076: public static final ValidationResult W2E2;
077: public static final ValidationResult W2W1;
078: public static final ValidationResult W2W2;
079:
080: public static final ValidationResult E1E1E1;
081: public static final ValidationResult E1E1W1;
082: public static final ValidationResult E1W1E1;
083: public static final ValidationResult E1W1W1;
084: public static final ValidationResult W1E1E1;
085: public static final ValidationResult W1E1W1;
086: public static final ValidationResult W1W1E1;
087: public static final ValidationResult W1W1W1;
088:
089: public static final ValidationResult E1E2E3;
090:
091: // Initialization *********************************************************
092:
093: static {
094: KEY1 = "key1";
095: KEY2 = "key2";
096: KEY3 = "key3";
097:
098: ValidationMessage error1 = new SimpleValidationMessage(
099: "Validation error1", Severity.ERROR, KEY1);
100: ValidationMessage error2 = new SimpleValidationMessage(
101: "Validation error2", Severity.ERROR, KEY2);
102: ValidationMessage error3 = new SimpleValidationMessage(
103: "Validation error3", Severity.ERROR, KEY3);
104: ValidationMessage warning1 = new SimpleValidationMessage(
105: "Validation warning1", Severity.WARNING, KEY1);
106: ValidationMessage warning2 = new SimpleValidationMessage(
107: "Validation warning2", Severity.WARNING, KEY2);
108:
109: E1 = createUnmodifiableResult(error1);
110: E2 = createUnmodifiableResult(error2);
111: W1 = createUnmodifiableResult(warning1);
112: W2 = createUnmodifiableResult(warning2);
113:
114: // ---------------------------------
115:
116: E1E1 = createUnmodifiableResult(error1, error1);
117: E1E2 = createUnmodifiableResult(error1, error2);
118: E1W1 = createUnmodifiableResult(error1, warning1);
119: E1W2 = createUnmodifiableResult(error1, warning2);
120:
121: E2E1 = createUnmodifiableResult(error2, error1);
122: E2E2 = createUnmodifiableResult(error2, error2);
123: E2W1 = createUnmodifiableResult(error2, warning1);
124: E2W2 = createUnmodifiableResult(error2, warning2);
125:
126: W1E1 = createUnmodifiableResult(warning1, error1);
127: W1E2 = createUnmodifiableResult(warning1, error2);
128: W1W1 = createUnmodifiableResult(warning1, warning1);
129: W1W2 = createUnmodifiableResult(warning1, warning2);
130:
131: W2E1 = createUnmodifiableResult(warning2, error1);
132: W2E2 = createUnmodifiableResult(warning2, error2);
133: W2W1 = createUnmodifiableResult(warning2, warning1);
134: W2W2 = createUnmodifiableResult(warning2, warning2);
135:
136: // ----------------------------------
137:
138: E1E1E1 = createUnmodifiableResult(error1, error1, error1);
139: E1E1W1 = createUnmodifiableResult(error1, error1, warning1);
140: E1W1E1 = createUnmodifiableResult(error1, warning1, error1);
141: E1W1W1 = createUnmodifiableResult(error1, warning1, warning1);
142: W1E1E1 = createUnmodifiableResult(warning1, error1, error1);
143: W1E1W1 = createUnmodifiableResult(warning1, error1, warning1);
144: W1W1E1 = createUnmodifiableResult(warning1, warning1, error1);
145: W1W1W1 = createUnmodifiableResult(warning1, warning1, warning1);
146:
147: E1E2E3 = createUnmodifiableResult(error1, error2, error3);
148: }
149:
150: // Overridden Constructor *************************************************
151:
152: private ValidationResults() {
153: // Override default constructor; prevents instantiation.
154: }
155:
156: // Helper Code ************************************************************
157:
158: private static ValidationResult createUnmodifiableResult(
159: ValidationMessage message) {
160: ValidationResult result = new ValidationResult();
161: result.add(message);
162: return ValidationResult.unmodifiableResult(result);
163: }
164:
165: private static ValidationResult createUnmodifiableResult(
166: ValidationMessage message1, ValidationMessage message2) {
167: ValidationResult result = new ValidationResult();
168: result.add(message1);
169: result.add(message2);
170: return ValidationResult.unmodifiableResult(result);
171: }
172:
173: private static ValidationResult createUnmodifiableResult(
174: ValidationMessage message1, ValidationMessage message2,
175: ValidationMessage message3) {
176: ValidationResult result = new ValidationResult();
177: result.add(message1);
178: result.add(message2);
179: result.add(message3);
180: return ValidationResult.unmodifiableResult(result);
181: }
182:
183: }
|