View Javadoc
1   /**
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2015, QOS.ch. All rights reserved.
4    *
5    * This program and the accompanying materials are dual-licensed under
6    * either the terms of the Eclipse Public License v1.0 as published by
7    * the Eclipse Foundation
8    *
9    *   or (per the licensee's choosing)
10   *
11   * under the terms of the GNU Lesser General Public License version 2.1
12   * as published by the Free Software Foundation.
13   */
14  package ch.qos.logback.core.util;
15  
16  import static org.junit.Assert.assertEquals;
17  
18  import org.junit.Test;
19  
20  public class FileSizeTest {
21  
22      static long KB_CO = 1024;
23      static long MB_CO = 1024 * 1024;
24      static long GB_CO = 1024 * MB_CO;
25  
26      @Test
27      public void testValueOf() {
28          {
29              FileSize fs = FileSize.valueOf("8");
30              assertEquals(8, fs.getSize());
31          }
32  
33          {
34              FileSize fs = FileSize.valueOf("8 kbs");
35              assertEquals(8 * KB_CO, fs.getSize());
36          }
37  
38          {
39              FileSize fs = FileSize.valueOf("8 kb");
40              assertEquals(8 * KB_CO, fs.getSize());
41          }
42  
43          {
44              FileSize fs = FileSize.valueOf("12 mb");
45              assertEquals(12 * MB_CO, fs.getSize());
46          }
47  
48          {
49              FileSize fs = FileSize.valueOf("5 GBs");
50              assertEquals(5 * GB_CO, fs.getSize());
51          }
52      }
53      
54      
55      @Test 
56      public void testToString() {
57          {
58              FileSize fs = new FileSize(8);
59              assertEquals("8 Bytes", fs.toString());
60          }
61          
62          {
63              FileSize fs = new FileSize(8*1024+3);
64              assertEquals("8 KB", fs.toString());
65          }
66          
67          {
68              FileSize fs = new FileSize(8*1024*1024+3*1024);
69              assertEquals("8 MB", fs.toString());
70          }
71          
72          {
73              FileSize fs = new FileSize(8*1024*1024*1024L);
74              assertEquals("8 GB", fs.toString());
75          }
76      }
77  }