001/** 002 * Logback: the reliable, generic, fast and flexible logging framework. 003 * Copyright (C) 1999-2015, QOS.ch. All rights reserved. 004 * 005 * This program and the accompanying materials are dual-licensed under 006 * either the terms of the Eclipse Public License v1.0 as published by 007 * the Eclipse Foundation 008 * 009 * or (per the licensee's choosing) 010 * 011 * under the terms of the GNU Lesser General Public License version 2.1 012 * as published by the Free Software Foundation. 013 */ 014package ch.qos.logback.core.util; 015 016import static org.junit.Assert.assertEquals; 017 018import org.junit.Test; 019 020public class FileSizeTest { 021 022 static long KB_CO = 1024; 023 static long MB_CO = 1024 * 1024; 024 static long GB_CO = 1024 * MB_CO; 025 026 @Test 027 public void testValueOf() { 028 { 029 FileSize fs = FileSize.valueOf("8"); 030 assertEquals(8, fs.getSize()); 031 } 032 033 { 034 FileSize fs = FileSize.valueOf("8 kbs"); 035 assertEquals(8 * KB_CO, fs.getSize()); 036 } 037 038 { 039 FileSize fs = FileSize.valueOf("8 kb"); 040 assertEquals(8 * KB_CO, fs.getSize()); 041 } 042 043 { 044 FileSize fs = FileSize.valueOf("12 mb"); 045 assertEquals(12 * MB_CO, fs.getSize()); 046 } 047 048 { 049 FileSize fs = FileSize.valueOf("5 GBs"); 050 assertEquals(5 * GB_CO, fs.getSize()); 051 } 052 } 053 054 055 @Test 056 public void testToString() { 057 { 058 FileSize fs = new FileSize(8); 059 assertEquals("8 Bytes", fs.toString()); 060 } 061 062 { 063 FileSize fs = new FileSize(8*1024+3); 064 assertEquals("8 KB", fs.toString()); 065 } 066 067 { 068 FileSize fs = new FileSize(8*1024*1024+3*1024); 069 assertEquals("8 MB", fs.toString()); 070 } 071 072 { 073 FileSize fs = new FileSize(8*1024*1024*1024L); 074 assertEquals("8 GB", fs.toString()); 075 } 076 } 077}