001: /*BEGIN_COPYRIGHT_BLOCK
002: *
003: * Copyright (c) 2001-2007, JavaPLT group at Rice University (javaplt@rice.edu)
004: * All rights reserved.
005: *
006: * Redistribution and use in source and binary forms, with or without
007: * modification, are permitted provided that the following conditions are met:
008: * * Redistributions of source code must retain the above copyright
009: * notice, this list of conditions and the following disclaimer.
010: * * Redistributions in binary form must reproduce the above copyright
011: * notice, this list of conditions and the following disclaimer in the
012: * documentation and/or other materials provided with the distribution.
013: * * Neither the names of DrJava, the JavaPLT group, Rice University, nor the
014: * names of its contributors may be used to endorse or promote products
015: * derived from this software without specific prior written permission.
016: *
017: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
018: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
019: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
020: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
021: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
022: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
023: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
024: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
025: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
026: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
027: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
028: *
029: * This software is Open Source Initiative approved Open Source Software.
030: * Open Source Initative Approved is a trademark of the Open Source Initiative.
031: *
032: * This file is part of DrJava. Download the current version of this project
033: * from http://www.drjava.org/ or http://sourceforge.net/projects/drjava/
034: *
035: * END_COPYRIGHT_BLOCK*/
036:
037: package edu.rice.cs.drjava.config;
038:
039: import edu.rice.cs.drjava.DrJavaTestCase;
040:
041: import java.util.Vector;
042:
043: /** Class according to the JUnit protocol. Tests the proper functionality of the class VectorOption.
044: * @version $Id: VectorOptionTest.java 4255 2007-08-28 19:17:37Z mgricken $
045: */
046: public final class VectorOptionTest extends DrJavaTestCase {
047: private VectorOption<Integer> _ivo;
048: private VectorOption<Boolean> _bvo;
049:
050: public void setUp() throws Exception {
051: super .setUp();
052: // name fields are irrelevant at this point.
053: _ivo = new VectorOption<Integer>("whatever", new IntegerOption(
054: "", null), (Vector<Integer>) null);
055: _bvo = new VectorOption<Boolean>("everwhat", new BooleanOption(
056: "", null), (Vector<Boolean>) null);
057: }
058:
059: public void testGetName() {
060: assertEquals("whatever", _ivo.getName());
061: assertEquals("everwhat", _bvo.getName());
062: }
063:
064: public void testParse() {
065: assertTrue(_ivo.parse("[]").isEmpty());
066: assertTrue(_bvo.parse("[]").isEmpty());
067:
068: try {
069: _ivo.parse("[,]");
070: fail("Comma at beginning.");
071: } catch (OptionParseException e) {
072: }
073:
074: try {
075: _ivo.parse("[11");
076: fail("Missing footer.");
077: } catch (OptionParseException e) {
078: }
079: try {
080: _ivo.parse("[11,]");
081: fail("Comma w/o following list element.");
082: } catch (OptionParseException e) {
083: }
084:
085: try {
086: _ivo.parse("11]");
087: fail("Missing header.");
088: } catch (OptionParseException e) {
089: }
090:
091: try {
092: _ivo.parse("[11,,22]");
093: fail("Missing list element.");
094: } catch (OptionParseException e) {
095: }
096:
097: try {
098: _ivo.parse("{11,22}");
099: fail("Illegal header and footer.");
100: } catch (OptionParseException e) {
101: }
102:
103: try {
104: _ivo.parse("[11;22]");
105: fail("Illegal delimiter.");
106: } catch (OptionParseException e) {
107: }
108:
109: Vector<Boolean> bv = _bvo.parse("[true]");
110:
111: assertEquals(1, bv.size());
112: assertEquals(Boolean.TRUE, bv.get(0));
113:
114: bv = _bvo.parse("[true,false,true,true]");
115:
116: assertEquals(4, bv.size());
117: assertEquals(Boolean.TRUE, bv.get(0));
118: assertEquals(Boolean.FALSE, bv.get(1));
119: assertEquals(Boolean.TRUE, bv.get(2));
120: assertEquals(Boolean.TRUE, bv.get(3));
121:
122: try {
123: _bvo.parse("[11]");
124: fail("Number instead of boolean.");
125: } catch (OptionParseException e) {
126: }
127: }
128:
129: public void testFormat() {
130: Vector<Integer> iv = new Vector<Integer>();
131: assertEquals("[]", _ivo.format(iv));
132:
133: iv.add(new Integer(-33));
134: assertEquals("[-33]", _ivo.format(iv));
135:
136: iv.add(new Integer(2));
137: assertEquals("[-33,2]", _ivo.format(iv));
138:
139: iv.add(new Integer(0));
140: assertEquals("[-33,2,0]", _ivo.format(iv));
141: }
142: }
|