Source Code Cross Referenced for PaddingStringBufferTest.java in  » Web-Crawler » heritrix » org » archive » util » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Web Crawler » heritrix » org.archive.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* PaddingStringBufferTest
002:         *
003:         * $Id: PaddingStringBufferTest.java 4644 2006-09-20 22:40:21Z paul_jack $
004:         *
005:         * Created Tue Jan 20 14:17:59 PST 2004
006:         *
007:         * Copyright (C) 2004 Internet Archive.
008:         *
009:         * This file is part of the Heritrix web crawler (crawler.archive.org).
010:         *
011:         * Heritrix is free software; you can redistribute it and/or modify
012:         * it under the terms of the GNU Lesser Public License as published by
013:         * the Free Software Foundation; either version 2.1 of the License, or
014:         * any later version.
015:         *
016:         * Heritrix is distributed in the hope that it will be useful,
017:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
018:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
019:         * GNU Lesser Public License for more details.
020:         *
021:         * You should have received a copy of the GNU Lesser Public License
022:         * along with Heritrix; if not, write to the Free Software
023:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
024:         */
025:
026:        package org.archive.util;
027:
028:        import junit.framework.Test;
029:        import junit.framework.TestCase;
030:        import junit.framework.TestSuite;
031:
032:        /**
033:         * JUnit test suite for PaddingStringBuffer
034:         *
035:         * @author <a href="mailto:me@jamesc.net">James Casey</a>
036:         * @version $Id: PaddingStringBufferTest.java 4644 2006-09-20 22:40:21Z paul_jack $
037:         */
038:        public class PaddingStringBufferTest extends TestCase {
039:            /**
040:             * Create a new PaddingStringBufferTest object
041:             *
042:             * @param testName the name of the test
043:             */
044:            public PaddingStringBufferTest(final String testName) {
045:                super (testName);
046:            }
047:
048:            /**
049:             * run all the tests for PaddingStringBufferTest
050:             *
051:             * @param argv the command line arguments
052:             */
053:            public static void main(String argv[]) {
054:                junit.textui.TestRunner.run(suite());
055:            }
056:
057:            /**
058:             * return the suite of tests for PaddingStringBufferTest
059:             *
060:             * @return the suite of test
061:             */
062:            public static Test suite() {
063:                return new TestSuite(PaddingStringBufferTest.class);
064:            }
065:
066:            public void setUp() {
067:                buf = new PaddingStringBuffer();
068:            }
069:
070:            /** first check that padTo works ok, since all depends on it */
071:            public void testPadTo() {
072:                PaddingStringBuffer retBuf;
073:                assertEquals("nothing in buffer", "", buf.toString());
074:                retBuf = buf.padTo(5);
075:                assertEquals("retBuf same as buf", retBuf, buf);
076:                assertEquals("5 spaces", "     ", buf.toString());
077:
078:                // now do a smaller value - nothing should happen
079:                buf.padTo(4);
080:                assertEquals("5 spaces", "     ", buf.toString());
081:
082:                // now pad tro a greater length
083:                buf.padTo(10);
084:                assertEquals("10 spaces", "          ", buf.toString());
085:            }
086:
087:            /** test that append(String) works correctly */
088:            public void testAppendString() {
089:                // a buf to hold the return buffer
090:                PaddingStringBuffer retBuf;
091:                assertEquals("nothing in buffer", "", buf.toString());
092:                retBuf = buf.append("foo");
093:                assertEquals("foo in buffer", "foo", buf.toString());
094:                assertEquals("retBuf good", retBuf.toString(), buf.toString());
095:                retBuf = buf.append("bar");
096:                assertEquals("foobar in buffer", "foobar", buf.toString());
097:                assertEquals("retBuf good", retBuf.toString(), buf.toString());
098:            }
099:
100:            /** check the reset method clears the buffer */
101:            public void testReset() {
102:                // append something into the buffer
103:                assertEquals("nothing in buffer", "", buf.toString());
104:                buf.append("foo");
105:                assertEquals("buffer is 'foo'", "foo", buf.toString());
106:                buf.reset();
107:                assertEquals("nothing in buffer after reset", "", buf
108:                        .toString());
109:            }
110:
111:            /** test the raAppend(String) works in the simple cases */
112:            public void testRaAppend() {
113:                // a buf to hold the return buffer
114:                PaddingStringBuffer retBuf;
115:                assertEquals("nothing in buffer", "", buf.toString());
116:                retBuf = buf.raAppend(5, "foo");
117:                assertEquals("foo in buffer", "  foo", buf.toString());
118:                assertEquals("retBuf good", retBuf.toString(), buf.toString());
119:                retBuf = buf.raAppend(9, "bar");
120:                assertEquals("foobar in buffer", "  foo bar", buf.toString());
121:                assertEquals("retBuf good", retBuf.toString(), buf.toString());
122:
123:                // now check with out-of-range columns - should just append
124:                buf = new PaddingStringBuffer();
125:                buf.raAppend(-1, "foo");
126:                assertEquals("no padding for -1", "foo", buf.toString());
127:                buf = new PaddingStringBuffer();
128:                buf.raAppend(0, "foo");
129:                assertEquals("no padding for 0", "foo", buf.toString());
130:
131:            }
132:
133:            /** test the newline() */
134:            public void testNewline() {
135:                assertEquals("nothing should be in the buffer", "", buf
136:                        .toString());
137:                buf.newline();
138:                assertTrue("should contain newline", buf.toString().indexOf(
139:                        '\n') != -1);
140:                assertEquals("line position should be 0", 0, buf.linePos);
141:            }
142:
143:            /** check what happens when we right append, but the string is longer
144:             * than the space */
145:            public void testRaAppendWithTooLongString() {
146:                buf.raAppend(3, "foobar");
147:                assertEquals(
148:                        "no padding when padding col less than string length",
149:                        "foobar", buf.toString());
150:                buf.reset();
151:            }
152:
153:            /** check it all works with the length == the length of the string */
154:            public void testRaAppendWithExactLengthString() {
155:                buf.raAppend(6, "foobar");
156:                buf.raAppend(12, "foobar");
157:                assertEquals("no padding with exact length string",
158:                        "foobarfoobar", buf.toString());
159:            }
160:
161:            /** check that append(int) works */
162:            public void testAppendInt() {
163:                buf.append((int) 1);
164:                assertEquals("buffer is '1'", "1", buf.toString());
165:                buf.append((int) 234);
166:                assertEquals("buffer is '1234'", "1234", buf.toString());
167:            }
168:
169:            /** check that raAppend(int) works */
170:            public void testRaAppendInt() {
171:                // right-append '1' to column 5
172:                buf.raAppend(5, (int) 1);
173:                assertEquals("buf is '    1'", "    1", buf.toString());
174:                // try appending a too-long int
175:
176:                buf.raAppend(6, (int) 123);
177:                assertEquals("'123' appended", "    1123", buf.toString());
178:            }
179:
180:            /** check that  append(long) works */
181:            public void testAppendLong() {
182:                buf.append((long) 1);
183:                assertEquals("buffer is '1'", "1", buf.toString());
184:                buf.append((long) 234);
185:                assertEquals("buffer is '1234'", "1234", buf.toString());
186:            }
187:
188:            /** check that raAppend(long) works */
189:            public void testRaAppendLong() {
190:                // right-append '1' to column 5
191:                buf.raAppend(5, (long) 1);
192:                assertEquals("buf is '    1'", "    1", buf.toString());
193:                // try appending a too-long int
194:
195:                buf.raAppend(6, (long) 123);
196:                assertEquals("'123' appended", "    1123", buf.toString());
197:            }
198:
199:            /** a temp buffer for testing with */
200:            private PaddingStringBuffer buf;
201:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.