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 org.junit.jupiter.api.Test;
17  
18  import static org.junit.jupiter.api.Assertions.assertEquals;
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      @Test
55      public void testToString() {
56          {
57              FileSize fs = new FileSize(8);
58              assertEquals("8 Bytes", fs.toString());
59          }
60  
61          {
62              FileSize fs = new FileSize(8 * 1024 + 3);
63              assertEquals("8 KB", fs.toString());
64          }
65  
66          {
67              FileSize fs = new FileSize(8 * 1024 * 1024 + 3 * 1024);
68              assertEquals("8 MB", fs.toString());
69          }
70  
71          {
72              FileSize fs = new FileSize(8 * 1024 * 1024 * 1024L);
73              assertEquals("8 GB", fs.toString());
74          }
75      }
76  }