001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.xtest.plugin.ide.test;
043:
044: import org.netbeans.junit.NbTestCase;
045: import org.netbeans.junit.NbTestSuite;
046: import org.openide.ErrorManager;
047:
048: /** Test of XTestErrorManager which should log error messages from IDE
049: * and report them as test errors.
050: */
051: public class XTestErrorManagerTest extends NbTestCase {
052:
053: /** Need to be defined because of JUnit */
054: public XTestErrorManagerTest(String name) {
055: super (name);
056: }
057:
058: /** Create suite. */
059: public static NbTestSuite suite() {
060: NbTestSuite suite = new NbTestSuite();
061: suite.addTest(new XTestErrorManagerTest("testInformational"));
062: suite.addTest(new XTestErrorManagerTest("testException"));
063: suite.addTest(new XTestErrorManagerTest("testError"));
064: suite.addTest(new XTestErrorManagerTest("testErrorInTest"));
065: suite.addTest(new XTestErrorManagerTest(
066: "testErrorInTestExceptionRemembered"));
067: suite.addTest(new XTestErrorManagerTest("testErrorWithFail"));
068: return suite;
069: }
070:
071: /** Set up. */
072: public void setUp() {
073: System.out.println("######## " + getName() + " #######");
074: }
075:
076: /** Test informational messages are not reported. */
077: public void testInformational() {
078: ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL,
079: new Exception("testInformational"));
080: }
081:
082: /** Test exception severity messages are reported as error. */
083: public void testException() {
084: ErrorManager.getDefault().notify(ErrorManager.EXCEPTION,
085: new Exception("testException"));
086: }
087:
088: /** Test error severity messages are reported as error. */
089: public void testError() {
090: ErrorManager.getDefault().notify(ErrorManager.ERROR,
091: new Exception("testError"));
092: }
093:
094: /** Test error in the test precede exception from IDE. */
095: public void testErrorInTest() {
096: ErrorManager.getDefault().notify(ErrorManager.ERROR,
097: new Exception("testErrorInTest"));
098: System.out.println("testError should add error");
099: // this causes error in test which should be reported instead of above errors
100: int i = 9 / 0;
101: }
102:
103: /** Test exception from IDE should be remembered if cannot be logged in previous test case. */
104: public void testErrorInTestExceptionRemembered() {
105: }
106:
107: /** Test exception from IDE precede failure in test. */
108: public void testErrorWithFail() {
109: ErrorManager.getDefault().notify(ErrorManager.ERROR,
110: new Exception("testErrorWithFail1"));
111: ErrorManager.getDefault().notify(ErrorManager.ERROR,
112: new Exception("testErrorWithFail2"));
113: fail("Should report first error instead of this fail.");
114: }
115: }
|