James Moger
2011-10-27 8e40cd53b6b1579e383bd5e993cb3c35ce4583c4
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
18 import java.io.File;
19
20 import junit.framework.TestCase;
21
671c19 22 import com.gitblit.utils.FileUtils;
JM 23
88598b 24 public class FileUtilsTest extends TestCase {
JM 25
26     public void testReadContent() throws Exception {
27         File dir = new File(System.getProperty("user.dir"));
28         String rawContent = FileUtils.readContent(new File(dir, "LICENSE"), "\n");
29         assertTrue(rawContent.trim().startsWith("Apache License"));
30     }
31
32     public void testFolderSize() throws Exception {
33         assertEquals(-1, FileUtils.folderSize(null));
34         assertEquals(-1, FileUtils.folderSize(new File(System.getProperty("user.dir"), "pretend")));
35
36         File dir = new File(System.getProperty("user.dir"), "distrib");
37         long size = FileUtils.folderSize(dir);
38         assertTrue("size is actually " + size, size >= 470000L);
39
40         File file = new File(System.getProperty("user.dir"), "LICENSE");
41         size = FileUtils.folderSize(file);
42         assertTrue("size is actually " + size, size == 11556L);
43
44     }
45 }