Source Code Cross Referenced for FileUtilsFileNewerTestCase.java in  » Library » apache-common-IO » org » apache » commons » io » 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 » Library » apache common IO » org.apache.commons.io 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         * 
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         * 
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:        package org.apache.commons.io;
018:
019:        import java.io.File;
020:        import java.util.Date;
021:
022:        import org.apache.commons.io.testtools.*;
023:
024:        /**
025:         * This is used to test FileUtils for correctness.
026:         *
027:         * @author <a href="mailto:alban.peignier@free.fr">Alban Peignier</a>
028:         */
029:        public class FileUtilsFileNewerTestCase extends FileBasedTestCase {
030:
031:            // Test data
032:            private static final int FILE1_SIZE = 1;
033:            private static final int FILE2_SIZE = 1024 * 4 + 1;
034:
035:            private File m_testFile1;
036:            private File m_testFile2;
037:
038:            public FileUtilsFileNewerTestCase(String name) {
039:                super (name);
040:
041:                m_testFile1 = new File(getTestDirectory(), "file1-test.txt");
042:                m_testFile2 = new File(getTestDirectory(), "file2-test.txt");
043:            }
044:
045:            /** @see junit.framework.TestCase#setUp() */
046:            protected void setUp() throws Exception {
047:                getTestDirectory().mkdirs();
048:                createFile(m_testFile1, FILE1_SIZE);
049:                createFile(m_testFile2, FILE2_SIZE);
050:            }
051:
052:            /** @see junit.framework.TestCase#tearDown() */
053:            protected void tearDown() throws Exception {
054:                m_testFile1.delete();
055:                m_testFile2.delete();
056:            }
057:
058:            /**
059:             * Tests the <code>isFileNewer(File, *)</code> methods which a "normal" file.
060:             *
061:             * @see FileUtils#isFileNewer(File, long)
062:             * @see FileUtils#isFileNewer(File, Date)
063:             * @see FileUtils#isFileNewer(File, File)
064:             */
065:            public void testIsFileNewer() {
066:                if (!m_testFile1.exists())
067:                    throw new IllegalStateException(
068:                            "The m_testFile1 should exist");
069:
070:                long fileLastModified = m_testFile1.lastModified();
071:                final long TWO_SECOND = 2000;
072:
073:                testIsFileNewer("two second earlier is not newer", m_testFile1,
074:                        fileLastModified + TWO_SECOND, false);
075:                testIsFileNewer("same time is not newer", m_testFile1,
076:                        fileLastModified, false);
077:                testIsFileNewer("two second later is newer", m_testFile1,
078:                        fileLastModified - TWO_SECOND, true);
079:            }
080:
081:            /**
082:             * Tests the <code>isFileNewer(File, *)</code> methods which a not existing file.
083:             *
084:             * @see FileUtils#isFileNewer(File, long)
085:             * @see FileUtils#isFileNewer(File, Date)
086:             * @see FileUtils#isFileNewer(File, File)
087:             */
088:            public void testIsFileNewerImaginaryFile() {
089:                File imaginaryFile = new File(getTestDirectory(),
090:                        "imaginaryFile");
091:                if (imaginaryFile.exists())
092:                    throw new IllegalStateException("The imaginary File exists");
093:
094:                testIsFileNewer("imaginary file can be newer", imaginaryFile,
095:                        m_testFile2.lastModified(), false);
096:            }
097:
098:            /**
099:             * Tests the <code>isFileNewer(File, *)</code> methods which the specified conditions.
100:             * <p/>
101:             * Creates :
102:             * <ul>
103:             * <li>a <code>Date</code> which represents the time reference</li>
104:             * <li>a temporary file with the same last modification date than the time reference</li>
105:             * </ul>
106:             * Then compares (with the needed <code>isFileNewer</code> method) the last modification date of 
107:             * the specified file with the specified time reference, the created <code>Date</code> and the temporary 
108:             * file.
109:             * <br/>
110:             * The test is successfull if the three comparaisons return the specified wanted result.
111:             *
112:             * @param description describes the tested situation
113:             * @param file the file of which the last modification date is compared
114:             * @param timeMillis the time reference measured in milliseconds since the epoch 
115:             *
116:             * @see FileUtils#isFileNewer(File, long)
117:             * @see FileUtils#isFileNewer(File, Date)
118:             * @see FileUtils#isFileNewer(File, File)
119:             */
120:            protected void testIsFileNewer(String description, File file,
121:                    long time, boolean wantedResult) {
122:                assertEquals(description + " - time", wantedResult, FileUtils
123:                        .isFileNewer(file, time));
124:                assertEquals(description + " - date", wantedResult, FileUtils
125:                        .isFileNewer(file, new Date(time)));
126:
127:                File temporaryFile = m_testFile2;
128:
129:                temporaryFile.setLastModified(time);
130:                assertEquals(
131:                        "The temporary file hasn't the right last modification date",
132:                        time, temporaryFile.lastModified());
133:                assertEquals(description + " - file", wantedResult, FileUtils
134:                        .isFileNewer(file, temporaryFile));
135:            }
136:
137:            /**
138:             * Tests the <code>isFileNewer(File, long)</code> method without specifying a <code>File</code>.
139:             * <br/>
140:             * The test is successfull if the method throws an <code>IllegalArgumentException</code>. 
141:             */
142:            public void testIsFileNewerNoFile() {
143:                try {
144:                    FileUtils.isFileNewer(null, 0);
145:                    fail("File not specified");
146:                } catch (IllegalArgumentException e) {
147:                }
148:            }
149:
150:            /**
151:             * Tests the <code>isFileNewer(File, Date)</code> method without specifying a <code>Date</code>.
152:             * <br/>
153:             * The test is successfull if the method throws an <code>IllegalArgumentException</code>. 
154:             */
155:            public void testIsFileNewerNoDate() {
156:                try {
157:                    FileUtils.isFileNewer(m_testFile1, (Date) null);
158:                    fail("Date not specified");
159:                } catch (IllegalArgumentException e) {
160:                }
161:            }
162:
163:            /**
164:             * Tests the <code>isFileNewer(File, File)</code> method without specifying a reference <code>File</code>.
165:             * <br/>
166:             * The test is successfull if the method throws an <code>IllegalArgumentException</code>. 
167:             */
168:            public void testIsFileNewerNoFileReference() {
169:                try {
170:                    FileUtils.isFileNewer(m_testFile1, (File) null);
171:                    fail("Reference file not specified");
172:                } catch (IllegalArgumentException e) {
173:                }
174:            }
175:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.