1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.codehaus.gmavenplus.util;
18
19 import org.junit.Test;
20
21 import java.io.*;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.mockito.Mockito.doThrow;
25 import static org.mockito.Mockito.mock;
26
27
28
29
30
31
32
33 public class FileUtilsTest {
34 private static final IOException ioException = new IOException("Intentionally blowing up.");
35
36 @Test
37 public void testGetFileExtension() {
38 assertEquals("gz", FileUtils.getFileExtension("foo.tar.gz"));
39 }
40
41 @Test
42 public void testGetNameWithoutExtension() {
43 assertEquals("foo.tar", FileUtils.getNameWithoutExtension("foo.tar.gz"));
44 }
45
46 @Test
47 public void testCloseInputStreamQuietly() throws Exception {
48 InputStream inputStream = mock(InputStream.class);
49 doThrow(ioException).when(inputStream).close();
50 FileUtils.closeQuietly(inputStream);
51 }
52
53 @Test
54 public void testCloseOutputStreamQuietly() throws Exception {
55 OutputStream outputStream = mock(OutputStream.class);
56 doThrow(ioException).when(outputStream).close();
57 FileUtils.closeQuietly(outputStream);
58 }
59
60 @Test
61 public void testCloseReaderQuietly() throws Exception {
62 Reader reader = mock(Reader.class);
63 doThrow(ioException).when(reader).close();
64 FileUtils.closeQuietly(reader);
65 }
66
67 @Test
68 public void testCloseWriterQuietly() throws Exception {
69 Writer writer = mock(Writer.class);
70 doThrow(ioException).when(writer).close();
71 FileUtils.closeQuietly(writer);
72 }
73
74 }