Source Code Cross Referenced for FileAsserts.java in  » Testing » DbUnit » org » dbunit » 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 » Testing » DbUnit » org.dbunit.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.dbunit.util;
002:
003:        import org.slf4j.Logger;
004:        import org.slf4j.LoggerFactory;
005:
006:        /*
007:         * From  "Dale E Martin" <dmartin@c..>
008:         * Date  Thursday, March 14, 2002 2:42 pm
009:         * To  junit@yahoogroups.com
010:         * Subject  [junit] file assert, a starting point
011:         *
012:         * OK, this isn't rocket science or anything but it's working for me.  What it
013:         * is is a couple of assert methods that compare files, so your expected
014:         * results can be located in a file.
015:         *
016:         * I did not use the diff library as the docs are in French, which I have not
017:         * studied for about 15 years and am not ready to pick back up ;-)
018:         *
019:         * I declare this code to be open to the public domain and anyone may do
020:         * anything they like with it.  Before inclusion in JUnit I'm sure you'll need
021:         * to tweak it some, but it's working for my needs and maybe it will help
022:         * someone else.
023:         *
024:         * Later,
025:         *       Dale
026:         *
027:         */
028:
029:        import junit.framework.Assert;
030:
031:        import java.io.*;
032:
033:        public class FileAsserts {
034:
035:            /**
036:             * Logger for this class
037:             */
038:            private static final Logger logger = LoggerFactory
039:                    .getLogger(FileAsserts.class);
040:
041:            private static String processOneLine(int lineNumber,
042:                    BufferedReader expectedData, BufferedReader actualData)
043:                    throws IOException {
044:                logger.debug("processOneLine(lineNumber=" + lineNumber
045:                        + ", expectedData=" + expectedData + ", actualData="
046:                        + actualData + ") - start");
047:
048:                String problem = null;
049:                String expectedLine = expectedData.readLine();
050:                if (!actualData.ready()) {
051:                    problem = "at line "
052:                            + lineNumber
053:                            + ", expected:\n"
054:                            + expectedLine
055:                            + "\n"
056:                            + "but actual file was not ready for reading at this line.";
057:                } else {
058:                    String actualLine = actualData.readLine();
059:                    if (!expectedLine.equals(actualLine)) {
060:                        // Uh oh, they did not match.
061:                        problem = "at line " + lineNumber
062:                                + " there was a mismatch.  Expected:\n";
063:                        int maxLen = expectedLine.length();
064:                        if (expectedLine.length() > actualLine.length()) {
065:                            maxLen = actualLine.length();
066:                        }
067:                        int startOffset = 0;
068:                        for (int i = 0; i < maxLen; i++) {
069:                            if (expectedLine.charAt(i) != actualLine.charAt(i)) {
070:                                startOffset = i;
071:                                break;
072:                            }
073:                        }
074:                        problem += expectedLine.substring(startOffset) + "\n"
075:                                + "actual was:\n"
076:                                + actualLine.substring(startOffset) + "\n";
077:                    }
078:                }
079:                return problem;
080:            }
081:
082:            public static void assertEquals(BufferedReader expected,
083:                    BufferedReader actual) throws Exception {
084:                logger.debug("assertEquals(expected=" + expected + ", actual="
085:                        + actual + ") - start");
086:
087:                Assert.assertNotNull(expected);
088:                Assert.assertNotNull(actual);
089:
090:                String problem = null;
091:                try {
092:                    int lineCounter = 0;
093:                    while (expected.ready() && problem == null) {
094:                        problem = processOneLine(lineCounter, expected, actual);
095:                        lineCounter++;
096:                    }
097:                } finally {
098:                    expected.close();
099:                    actual.close();
100:                }
101:
102:                if (problem != null) {
103:                    Assert.fail(problem);
104:                }
105:            }
106:
107:            public static void assertEquals(InputStream expected, File actual)
108:                    throws Exception {
109:                logger.debug("assertEquals(expected=" + expected + ", actual="
110:                        + actual + ") - start");
111:
112:                Assert.assertNotNull(expected);
113:                Assert.assertNotNull(actual);
114:
115:                Assert.assertTrue(actual.canRead());
116:
117:                BufferedReader expectedData = new BufferedReader(
118:                        new InputStreamReader(expected));
119:
120:                BufferedReader actualData = new BufferedReader(
121:                        new InputStreamReader(new FileInputStream(actual)));
122:                assertEquals(expectedData, actualData);
123:            }
124:
125:            public static void assertEquals(File expected, File actual)
126:                    throws Exception {
127:                logger.debug("assertEquals(expected=" + expected + ", actual="
128:                        + actual + ") - start");
129:
130:                Assert.assertNotNull(expected);
131:                Assert.assertNotNull(actual);
132:
133:                Assert.assertTrue(expected.canRead());
134:                Assert.assertTrue(actual.canRead());
135:
136:                BufferedReader expectedData = new BufferedReader(
137:                        new InputStreamReader(new FileInputStream(expected)));
138:                BufferedReader actualData = new BufferedReader(
139:                        new InputStreamReader(new FileInputStream(actual)));
140:                assertEquals(expectedData, actualData);
141:            }
142:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.