commit | author | age
|
88598b
|
1 |
/*
|
JM |
2 |
* Copyright 2011 gitblit.com.
|
|
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 |
package com.gitblit.tests;
|
|
17 |
|
7e8873
|
18 |
import static org.junit.Assert.assertEquals;
|
JM |
19 |
import static org.junit.Assert.assertTrue;
|
|
20 |
|
88598b
|
21 |
import java.io.File;
|
JM |
22 |
|
7e8873
|
23 |
import org.junit.Test;
|
88598b
|
24 |
|
671c19
|
25 |
import com.gitblit.utils.FileUtils;
|
JM |
26 |
|
7e8873
|
27 |
public class FileUtilsTest {
|
88598b
|
28 |
|
7e8873
|
29 |
@Test
|
88598b
|
30 |
public void testReadContent() throws Exception {
|
JM |
31 |
File dir = new File(System.getProperty("user.dir"));
|
|
32 |
String rawContent = FileUtils.readContent(new File(dir, "LICENSE"), "\n");
|
|
33 |
assertTrue(rawContent.trim().startsWith("Apache License"));
|
|
34 |
}
|
7e8873
|
35 |
|
JM |
36 |
@Test
|
143fc9
|
37 |
public void testWriteContent() throws Exception {
|
JM |
38 |
String contentA = "this is a test";
|
|
39 |
File tmp = File.createTempFile("gitblit-", ".test");
|
|
40 |
FileUtils.writeContent(tmp, contentA);
|
|
41 |
String contentB = FileUtils.readContent(tmp, "\n").trim();
|
|
42 |
assertEquals(contentA, contentB);
|
|
43 |
}
|
88598b
|
44 |
|
7e8873
|
45 |
@Test
|
88598b
|
46 |
public void testFolderSize() throws Exception {
|
JM |
47 |
assertEquals(-1, FileUtils.folderSize(null));
|
|
48 |
assertEquals(-1, FileUtils.folderSize(new File(System.getProperty("user.dir"), "pretend")));
|
|
49 |
|
|
50 |
File dir = new File(System.getProperty("user.dir"), "distrib");
|
|
51 |
long size = FileUtils.folderSize(dir);
|
|
52 |
assertTrue("size is actually " + size, size >= 470000L);
|
|
53 |
|
|
54 |
File file = new File(System.getProperty("user.dir"), "LICENSE");
|
|
55 |
size = FileUtils.folderSize(file);
|
7e8873
|
56 |
assertEquals("size is actually " + size, 11556L, size);
|
88598b
|
57 |
}
|
JM |
58 |
} |