01: /*******************************************************************************
02: * Copyright (c) 2007 Brad Reynolds and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * Brad Reynolds - initial API and implementation
10: ******************************************************************************/package org.eclipse.core.tests.internal.databinding.validation;
11:
12: import junit.framework.TestCase;
13:
14: import org.eclipse.core.databinding.conversion.StringToNumberConverter;
15: import org.eclipse.core.internal.databinding.validation.AbstractStringToNumberValidator;
16: import org.eclipse.core.internal.databinding.validation.NumberFormatConverter;
17: import org.eclipse.core.runtime.IStatus;
18:
19: /**
20: * Tests for AbstractStringToNumberValidator. Most tests should be included in
21: * StringToNumberValidatorTestHarness. This class is for the edge cases.
22: *
23: * @since 3.2
24: */
25: public class AbstractStringToNumberValidatorTest extends TestCase {
26: /**
27: * Test for bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=194353.
28: *
29: * @throws Exception
30: */
31: public void testErrorMessagesAreNotCached() throws Exception {
32: NumberFormatConverter c = StringToNumberConverter
33: .toInteger(false);
34: ValidatorStub v = new ValidatorStub(c);
35:
36: IStatus status1 = v.validate("1a");
37: assertEquals(IStatus.ERROR, status1.getSeverity());
38:
39: IStatus status2 = v.validate("2b");
40: assertEquals(IStatus.ERROR, status2.getSeverity());
41:
42: assertFalse("messages should not be equal", status1
43: .getMessage().equals(status2.getMessage()));
44: }
45:
46: static class ValidatorStub extends AbstractStringToNumberValidator {
47: ValidatorStub(NumberFormatConverter c) {
48: super (c, new Integer(Integer.MIN_VALUE), new Integer(
49: Integer.MAX_VALUE));
50: }
51:
52: protected boolean isInRange(Number number) {
53: return true;
54: }
55: }
56: }
|