01: /*******************************************************************************
02: * Copyright (c) 2007 IBM Corporation 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: * IBM Corporation - initial API and implementation
10: ******************************************************************************/package org.eclipse.core.tests.internal.databinding.conversion;
11:
12: import java.util.Collections;
13: import java.util.LinkedList;
14: import java.util.List;
15: import java.util.StringTokenizer;
16:
17: import junit.framework.TestCase;
18: import junit.framework.TestResult;
19:
20: import org.eclipse.core.internal.databinding.BindingMessages;
21: import org.eclipse.core.internal.databinding.conversion.StringToBooleanConverter;
22:
23: /**
24: * @since 1.1
25: */
26: public class StringToBooleanConverterTest extends TestCase {
27: private StringToBooleanConverter converter;
28:
29: private List trueValues;
30:
31: private List falseValues;
32:
33: /*
34: * (non-Javadoc)
35: *
36: * @see junit.framework.TestCase#run(junit.framework.TestResult)
37: */
38: public void run(TestResult result) {
39: trueValues = Collections.unmodifiableList(toValues(
40: BindingMessages.getString("ValueDelimiter"),
41: BindingMessages.getString("TrueStringValues")));
42: falseValues = Collections.unmodifiableList(toValues(
43: BindingMessages.getString("ValueDelimiter"),
44: BindingMessages.getString("FalseStringValues")));
45:
46: super .run(result);
47: }
48:
49: private List toValues(String delimiter, String values) {
50: StringTokenizer tokenizer = new StringTokenizer(values,
51: delimiter);
52: List result = new LinkedList();
53:
54: while (tokenizer.hasMoreTokens()) {
55: result.add(tokenizer.nextToken());
56: }
57:
58: return result;
59: }
60:
61: /*
62: * (non-Javadoc)
63: *
64: * @see junit.framework.TestCase#setUp()
65: */
66: protected void setUp() throws Exception {
67: super .setUp();
68:
69: converter = new StringToBooleanConverter();
70: assertTrue(trueValues.size() > 0);
71: assertTrue(falseValues.size() > 0);
72: }
73:
74: public void testConvertsToTrue() throws Exception {
75: Boolean result = (Boolean) converter.convert(trueValues.get(0));
76: assertTrue(result.booleanValue());
77: }
78:
79: public void testConvertsToFalse() throws Exception {
80: Boolean result = (Boolean) converter
81: .convert(falseValues.get(0));
82: assertFalse(result.booleanValue());
83: }
84:
85: public void testUpperCaseStringConvertsToTrue() throws Exception {
86: Boolean result = (Boolean) converter
87: .convert(((String) trueValues.get(0)).toUpperCase());
88: assertTrue(result.booleanValue());
89: }
90:
91: public void testUpperCaseStringConvertsToFalse() throws Exception {
92: Boolean result = (Boolean) converter
93: .convert(((String) falseValues.get(0)).toUpperCase());
94: assertFalse(result.booleanValue());
95: }
96: }
|