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.ui.config;
038:
039: import edu.rice.cs.drjava.DrJava;
040: import edu.rice.cs.drjava.DrJavaTestCase;
041: import edu.rice.cs.drjava.config.OptionConstants;
042: import edu.rice.cs.util.swing.Utilities;
043:
044: import java.awt.*;
045: import java.io.File;
046: import java.util.Vector;
047:
048: /** Tests functionality of this OptionComponent */
049: public final class VectorFileOptionComponentTest extends DrJavaTestCase {
050: private static VectorFileOptionComponent _option;
051:
052: protected void setUp() throws Exception {
053: super .setUp();
054: _option = new VectorFileOptionComponent(
055: OptionConstants.EXTRA_CLASSPATH, "Extra Classpath",
056: new Frame());
057: DrJava.getConfig().resetToDefaults();
058: }
059:
060: public void testCancelDoesNotChangeConfig() {
061: Vector<File> testVector = new Vector<File>();
062: testVector.addElement(new File("test"));
063:
064: _option.setValue(testVector);
065: _option.resetToCurrent(); // should reset to the original.
066: _option.updateConfig(); // should update with original values therefore no change.
067:
068: Utilities.clearEventQueue();
069:
070: assertTrue(
071: "Cancel (resetToCurrent) should not change the config",
072: vectorEquals(OptionConstants.EXTRA_CLASSPATH
073: .getDefault(), DrJava.getConfig().getSetting(
074: OptionConstants.EXTRA_CLASSPATH)));
075: }
076:
077: public void testApplyDoesChangeConfig() {
078: Vector<File> testVector = new Vector<File>();
079: testVector.addElement(new File("blah"));
080:
081: _option.setValue(testVector);
082: _option.updateConfig();
083:
084: Utilities.clearEventQueue();
085: assertTrue("Apply (updateConfig) should write change to file",
086: vectorEquals(testVector, DrJava.getConfig().getSetting(
087: OptionConstants.EXTRA_CLASSPATH)));
088: }
089:
090: public void testApplyThenResetDefault() {
091: Vector<File> testVector = new Vector<File>();
092: testVector.addElement(new File("blah"));
093:
094: _option.setValue(testVector);
095: _option.updateConfig();
096: Utilities.clearEventQueue();
097:
098: _option.resetToDefault(); // resets to default
099: _option.updateConfig();
100: Utilities.clearEventQueue();
101:
102: assertTrue("Apply (updateConfig) should write change to file",
103: vectorEquals(OptionConstants.EXTRA_CLASSPATH
104: .getDefault(), DrJava.getConfig().getSetting(
105: OptionConstants.EXTRA_CLASSPATH)));
106: }
107:
108: /**
109: * The equals method for a parameterized Vector.
110: *
111: * @param v1 the first Vector<File>
112: * @param v2 the Vector<File> to compare with
113: * @return <code>true</code> iff the two vectors are equal
114: */
115: public boolean vectorEquals(Vector<File> v1, Vector<File> v2) {
116: if (v1.size() == v2.size()) {
117: for (int i = 0; i < v1.size(); i++) {
118: if (!v1.elementAt(i).equals(v2.elementAt(i))) {
119: return false;
120: }
121: }
122: return true;
123: } else { // different sizes
124: return false;
125: }
126: }
127: }
|