001: /*
002: * @(#)ReadUtilUTest.java
003: *
004: * Copyright (C) 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.codecoverage.v2.datastore;
028:
029: import java.io.IOException;
030: import java.io.Reader;
031: import java.io.StringReader;
032:
033: import junit.framework.Test;
034: import junit.framework.TestCase;
035: import junit.framework.TestSuite;
036: import net.sourceforge.groboutils.autodoc.v1.AutoDoc;
037:
038: /**
039: * Tests the ReadUtil class.
040: *
041: * @author Matt Albrecht <a href="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
042: * @version $Date: 2004/04/15 05:48:28 $
043: * @since January 22, 2003
044: */
045: public class ReadUtilUTest extends TestCase {
046: //-------------------------------------------------------------------------
047: // Standard JUnit Class-specific declarations
048:
049: private static final Class THIS_CLASS = ReadUtilUTest.class;
050: private static final AutoDoc DOC = new AutoDoc(THIS_CLASS);
051:
052: public ReadUtilUTest(String name) {
053: super (name);
054: }
055:
056: //-------------------------------------------------------------------------
057: // Tests
058:
059: public void testReadTo1() {
060: Reader r = new StringReader("");
061: try {
062: ReadUtil.readTo(r, 'c');
063: } catch (IOException ex) {
064: assertTrue("Did not reference 'c'.", ex.getMessage()
065: .indexOf("'c'") >= 0);
066: }
067: }
068:
069: public void testReadTo2() throws Exception {
070: Reader r = new StringReader("c");
071: String s = ReadUtil.readTo(r, 'c');
072: assertEquals("Didn't read correct string.", "", s);
073: }
074:
075: public void testReadTo3() throws Exception {
076: Reader r = new StringReader("ccc");
077: String s = ReadUtil.readTo(r, 'c');
078: assertEquals("Didn't read correct string.", "", s);
079: }
080:
081: public void testReadTo4() throws Exception {
082: Reader r = new StringReader("abc");
083: String s = ReadUtil.readTo(r, 'c');
084: assertEquals("Didn't read correct string.", "ab", s);
085: }
086:
087: public void testReadCount1() {
088: Reader r = new StringReader("");
089: try {
090: ReadUtil.readCount(r, 1);
091: } catch (IOException ex) {
092: assertTrue("Didn't reference count.", ex.getMessage()
093: .indexOf(" 1 ") >= 0);
094: }
095: }
096:
097: public void testReadCount2() throws Exception {
098: Reader r = new StringReader("a");
099: try {
100: ReadUtil.readCount(r, 4);
101: } catch (IOException ex) {
102: assertTrue("Didn't reference count.", ex.getMessage()
103: .indexOf(" 3 ") >= 0);
104: }
105: }
106:
107: public void testReadCount3() throws Exception {
108: Reader r = new StringReader("");
109: String s = ReadUtil.readCount(r, 0);
110: assertEquals("Did not return expected string.", "", s);
111: }
112:
113: public void testReadCount4() throws Exception {
114: Reader r = new StringReader("a");
115: String s = ReadUtil.readCount(r, 1);
116: assertEquals("Did not return expected string.", "a", s);
117: }
118:
119: public void testReadCount5() throws Exception {
120: Reader r = new StringReader("abc");
121: String s = ReadUtil.readCount(r, 1);
122: assertEquals("Did not return expected string.", "a", s);
123: }
124:
125: public void testReadCount6() throws Exception {
126: Reader r = new StringReader("abc");
127: String s = ReadUtil.readCount(r, 3);
128: assertEquals("Did not return expected string.", "abc", s);
129: }
130:
131: public void testToInt1() throws Exception {
132: assertEquals("Didn't convert right.", -1, ReadUtil.toInt("-1"));
133: }
134:
135: public void testToInt2() throws Exception {
136: assertEquals("Didn't convert right.", 0, ReadUtil.toInt("0"));
137: }
138:
139: public void testToInt3() {
140: try {
141: ReadUtil.toInt("");
142: } catch (IOException ex) {
143: // test exception
144: }
145: }
146:
147: public void testToInt4() {
148: try {
149: ReadUtil.toInt(null);
150: } catch (IOException ex) {
151: // test exception
152: }
153: }
154:
155: public void testToInt5() {
156: try {
157: ReadUtil.toInt("ab");
158: } catch (IOException ex) {
159: // test exception
160: }
161: }
162:
163: public void testToLong1() throws Exception {
164: assertEquals("Didn't convert right.", -1L, ReadUtil
165: .toLong("-1"));
166: }
167:
168: public void testToLong2() throws Exception {
169: assertEquals("Didn't convert right.", 0L, ReadUtil.toLong("0"));
170: }
171:
172: public void testToLong3() {
173: try {
174: ReadUtil.toLong("");
175: } catch (IOException ex) {
176: // test exception
177: }
178: }
179:
180: public void testToLong4() {
181: try {
182: ReadUtil.toLong(null);
183: } catch (IOException ex) {
184: // test exception
185: }
186: }
187:
188: public void testToLong5() {
189: try {
190: ReadUtil.toLong("ab");
191: } catch (IOException ex) {
192: // test exception
193: }
194: }
195:
196: //-------------------------------------------------------------------------
197: // Helpers
198:
199: //-------------------------------------------------------------------------
200: // Standard JUnit declarations
201:
202: public static Test suite() {
203: TestSuite suite = new TestSuite(THIS_CLASS);
204:
205: return suite;
206: }
207:
208: public static void main(String[] args) {
209: String[] name = { THIS_CLASS.getName() };
210:
211: // junit.textui.TestRunner.main( name );
212: // junit.swingui.TestRunner.main( name );
213:
214: junit.textui.TestRunner.main(name);
215: }
216:
217: /**
218: *
219: * @exception Exception thrown under any exceptional condition.
220: */
221: protected void setUp() throws Exception {
222: super .setUp();
223:
224: // set ourself up
225: }
226:
227: /**
228: *
229: * @exception Exception thrown under any exceptional condition.
230: */
231: protected void tearDown() throws Exception {
232: // tear ourself down
233:
234: super.tearDown();
235: }
236: }
|