blob: ac70b9ad2b59b0a3e4cce762d509c46e534f7e35 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.log;
import org.junit.Test;
import org.junit.After;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNot.not;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
/**
* @author lulf
* @since 5.1
*/
public class FileLogTargetTest {
@Test(expected = RuntimeException.class)
public void requireThatExceptionIsThrowIfFileNotFound() throws IOException {
File file = new File("mydir1");
file.delete();
assertTrue(file.mkdir());
new FileLogTarget(file).open();
}
@After
public void cleanup() { new File("mydir1").delete(); }
@Test
public void requireThatFileCanOpened() throws IOException {
FileLogTarget logTarget = new FileLogTarget(File.createTempFile("logfile", ".log"));
assertNotNull(logTarget.open());
}
@Test
public void requireThatFileIsReopened() throws IOException {
FileLogTarget logTarget = new FileLogTarget(File.createTempFile("logfile", ".log"));
OutputStream out1 = logTarget.open();
assertNotNull(out1);
OutputStream out2 = logTarget.open();
assertNotNull(out2);
assertThat(out1, is(not(out2)));
}
}
|