KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > util > FileCopyUtilTests


1 /*
2  * Copyright 2002-2005 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.springframework.util;
18
19 import java.io.ByteArrayInputStream JavaDoc;
20 import java.io.ByteArrayOutputStream JavaDoc;
21 import java.io.IOException JavaDoc;
22 import java.io.StringReader JavaDoc;
23 import java.io.StringWriter JavaDoc;
24 import java.util.Arrays JavaDoc;
25
26 import junit.framework.TestCase;
27
28 /**
29  * @author Juergen Hoeller
30  * @since 12.03.2005
31  */

32 public class FileCopyUtilTests extends TestCase {
33
34     public void testCopyFromInputStream() throws IOException JavaDoc {
35         byte[] content = "content".getBytes();
36         ByteArrayInputStream JavaDoc in = new ByteArrayInputStream JavaDoc(content);
37         ByteArrayOutputStream JavaDoc out = new ByteArrayOutputStream JavaDoc(content.length);
38         int count = FileCopyUtils.copy(in, out);
39         assertEquals(content.length, count);
40         assertTrue(Arrays.equals(content, out.toByteArray()));
41     }
42
43     public void testCopyFromByteArray() throws IOException JavaDoc {
44         byte[] content = "content".getBytes();
45         ByteArrayOutputStream JavaDoc out = new ByteArrayOutputStream JavaDoc(content.length);
46         FileCopyUtils.copy(content, out);
47         assertTrue(Arrays.equals(content, out.toByteArray()));
48     }
49
50     public void testCopyToByteArray() throws IOException JavaDoc {
51         byte[] content = "content".getBytes();
52         ByteArrayInputStream JavaDoc in = new ByteArrayInputStream JavaDoc(content);
53         byte[] result = FileCopyUtils.copyToByteArray(in);
54         assertTrue(Arrays.equals(content, result));
55     }
56
57     public void testCopyFromReader() throws IOException JavaDoc {
58         String JavaDoc content = "content";
59         StringReader JavaDoc in = new StringReader JavaDoc(content);
60         StringWriter JavaDoc out = new StringWriter JavaDoc();
61         int count = FileCopyUtils.copy(in, out);
62         assertEquals(content.length(), count);
63         assertEquals(content, out.toString());
64     }
65
66     public void testCopyFromString() throws IOException JavaDoc {
67         String JavaDoc content = "content";
68         StringWriter JavaDoc out = new StringWriter JavaDoc();
69         FileCopyUtils.copy(content, out);
70         assertEquals(content, out.toString());
71     }
72
73     public void testCopyToString() throws IOException JavaDoc {
74         String JavaDoc content = "content";
75         StringReader JavaDoc in = new StringReader JavaDoc(content);
76         String JavaDoc result = FileCopyUtils.copyToString(in);
77         assertEquals(content, result);
78     }
79
80 }
81
Popular Tags