001: /*
002: * @(#)AssertConstructorUTest.java
003: *
004: * Copyright (C) 2002-2003 Matt Albrecht
005: * groboclown@users.sourceforge.net
006: * http://groboutils.sourceforge.net
007: *
008: * Permission is hereby granted, free of charge, to any person obtaining a
009: * copy of this software and associated documentation files (the "Software"),
010: * to deal in the Software without restriction, including without limitation
011: * the rights to use, copy, modify, merge, publish, distribute, sublicense,
012: * and/or sell copies of the Software, and to permit persons to whom the
013: * Software is furnished to do so, subject to the following conditions:
014: *
015: * The above copyright notice and this permission notice shall be included in
016: * all copies or substantial portions of the Software.
017: *
018: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
019: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
020: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
021: * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
022: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
023: * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
024: * DEALINGS IN THE SOFTWARE.
025: */
026:
027: package net.sourceforge.groboutils.junit.v1;
028:
029: import org.easymock.EasyMock;
030: import org.easymock.MockControl;
031: import junit.framework.Test;
032: import junit.framework.TestCase;
033: import junit.framework.TestSuite;
034: import junit.framework.AssertionFailedError;
035:
036: /**
037: * Tests the AssertConstructor class.
038: *
039: * @author Matt Albrecht <a href="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
040: * @since March 1, 2002
041: * @version $Date: 2003/02/10 22:52:22 $
042: */
043: public class AssertConstructorUTest extends TestCase {
044: //-------------------------------------------------------------------------
045: // Standard JUnit Class-specific declarations
046:
047: private static final Class THIS_CLASS = AssertConstructorUTest.class;
048:
049: public AssertConstructorUTest(String name) {
050: super (name);
051: }
052:
053: //-------------------------------------------------------------------------
054: // Tests
055:
056: public void testAssertHasDefaultConstructor1() {
057: AssertConstructor.assertHasDefaultConstructor(Object.class);
058: }
059:
060: public void testAssertHasDefaultConstructor2() {
061: boolean failed = true;
062: try {
063: AssertConstructor
064: .assertHasDefaultConstructor(Integer.class);
065: } catch (AssertionFailedError e) {
066: failed = false;
067: }
068: if (failed) {
069: fail("Did not cause an assertion failure.");
070: }
071: }
072:
073: public void testAssertHasDefaultConstructor3() {
074: AssertConstructor.assertHasDefaultConstructor(new Object());
075: }
076:
077: public void testAssertHasDefaultConstructor4() {
078: boolean failed = true;
079: try {
080: AssertConstructor
081: .assertHasDefaultConstructor(new Integer(1));
082: } catch (AssertionFailedError e) {
083: failed = false;
084: }
085: if (failed) {
086: fail("Did not cause an assertion failure.");
087: }
088: }
089:
090: public void testAssertHasDefaultConstructor1a() {
091: AssertConstructor
092: .assertHasDefaultConstructor("A", Object.class);
093: }
094:
095: public void testAssertHasDefaultConstructor2a() {
096: boolean failed = true;
097: try {
098: AssertConstructor.assertHasDefaultConstructor(":A:",
099: Integer.class);
100: } catch (AssertionFailedError e) {
101: assertTrue("Did not throw an error with the message text.",
102: e.getMessage().indexOf(":A:") >= 0);
103: failed = false;
104: }
105: if (failed) {
106: fail("Did not cause an assertion failure.");
107: }
108: }
109:
110: public void testAssertHasDefaultConstructor3a() {
111: AssertConstructor
112: .assertHasDefaultConstructor("A", new Object());
113: }
114:
115: public void testAssertHasDefaultConstructor4a() {
116: boolean failed = true;
117: try {
118: AssertConstructor.assertHasDefaultConstructor(":A:",
119: new Integer(1));
120: } catch (AssertionFailedError e) {
121: assertTrue("Did not throw an error with the message text.",
122: e.getMessage().indexOf(":A:") >= 0);
123: failed = false;
124: }
125: if (failed) {
126: fail("Did not cause an assertion failure.");
127: }
128: }
129:
130: public void testAssertHasConstructor1() {
131: AssertConstructor.assertHasConstructor(Object.class,
132: new Class[0], AssertConstructor.ANY_PROTECTION);
133: }
134:
135: public void testAssertHasConstructor2() {
136: boolean failed = true;
137: try {
138: AssertConstructor.assertHasConstructor(Object.class,
139: new Class[0], AssertConstructor.PRIVATE);
140: } catch (AssertionFailedError e) {
141: failed = false;
142: }
143: if (failed) {
144: fail("Did not cause an assertion failure.");
145: }
146: }
147:
148: public void testAssertHasConstructor3() {
149: AssertConstructor.assertHasConstructor(Integer.class,
150: new Class[] { Integer.TYPE }, AssertConstructor.PUBLIC);
151: }
152:
153: //-------------------------------------------------------------------------
154: // Standard JUnit declarations
155:
156: public static Test suite() {
157: TestSuite suite = new TestSuite(THIS_CLASS);
158:
159: return suite;
160: }
161:
162: public static void main(String[] args) {
163: String[] name = { THIS_CLASS.getName() };
164:
165: // junit.textui.TestRunner.main( name );
166: // junit.swingui.TestRunner.main( name );
167:
168: junit.textui.TestRunner.main(name);
169: }
170:
171: /**
172: *
173: * @exception Exception thrown under any exceptional condition.
174: */
175: protected void setUp() throws Exception {
176: super .setUp();
177:
178: // set ourself up
179: }
180:
181: /**
182: *
183: * @exception Exception thrown under any exceptional condition.
184: */
185: protected void tearDown() throws Exception {
186: // tear ourself down
187:
188: super.tearDown();
189: }
190: }
|