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.util.swing;
038:
039: import junit.framework.TestCase;
040:
041: import java.util.Collection;
042: import java.util.Arrays;
043:
044: import javax.swing.JOptionPane;
045:
046: /**
047: * A JUnit test case class that tests {@link ScrollableListDialog}.
048: *
049: * @author Chris Warrington
050: * @version $Id$
051: * @since 2007-03-06
052: */
053: public class ScrollableListDialogTest extends TestCase {
054: private static final String TITLE = "DIALOG TITLE";
055: private static final String LEADER = "DIALOG LEADER";
056: private static final Collection<String> DATA = Arrays.asList(
057: "hello", "there");
058:
059: /**
060: * Tests that all the valid message types are accepted and that they
061: * are the only message types accepted.
062: */
063: public void testValidMessageTypes() {
064: try {
065: new ScrollableListDialog(null, TITLE, LEADER, DATA,
066: JOptionPane.ERROR_MESSAGE);
067: } catch (IllegalArgumentException e) {
068: fail("JOptionPane.ERROR_MESSAGE is a valid message type");
069: }
070:
071: try {
072: new ScrollableListDialog(null, TITLE, LEADER, DATA,
073: JOptionPane.INFORMATION_MESSAGE);
074: } catch (IllegalArgumentException e) {
075: fail("JOptionPane.INFORMATION_MESSAGE is a valid message type");
076: }
077:
078: try {
079: new ScrollableListDialog(null, TITLE, LEADER, DATA,
080: JOptionPane.WARNING_MESSAGE);
081: } catch (IllegalArgumentException e) {
082: fail("JOptionPane.WARNING_MESSAGE is a valid message type");
083: }
084:
085: try {
086: new ScrollableListDialog(null, TITLE, LEADER, DATA,
087: JOptionPane.QUESTION_MESSAGE);
088: } catch (IllegalArgumentException e) {
089: fail("JOptionPane.QUESTION_MESSAGE is a valid message type");
090: }
091:
092: try {
093: new ScrollableListDialog(null, TITLE, LEADER, DATA,
094: JOptionPane.PLAIN_MESSAGE);
095: } catch (IllegalArgumentException e) {
096: fail("JOptionPane.PLAIN_MESSAGE is a valid message type");
097: }
098:
099: try {
100: new ScrollableListDialog(null, TITLE, LEADER, DATA, -128);
101: fail("-128 is not a valid message type");
102: } catch (IllegalArgumentException e) {
103: //we're good
104: }
105:
106: try {
107: new ScrollableListDialog(null, TITLE, LEADER, DATA, 42);
108: fail("42 is not a valid message type");
109: } catch (IllegalArgumentException e) {
110: //we're good
111: }
112: }
113:
114: public void testNullData() {
115: try {
116: new ScrollableListDialog(null, TITLE, LEADER, DATA);
117: } catch (IllegalArgumentException e) {
118: fail("Data was non-null, so it should have been accepted.");
119: }
120:
121: try {
122: new ScrollableListDialog(null, TITLE, LEADER, null);
123: fail("Data was null, so it shouldn't have been accepted.");
124: } catch (IllegalArgumentException e) {
125: //we're good
126: }
127: }
128: }
|