File D:\maven-qcr-plugin-testsunitaires\qcr4java\jenkins-master\target\site\qc\core\src\test\java\hudson\util\io\ReopenableRotatingFileOutputStreamTest.java.html

1 package hudson.util.io;
2
3 import hudson.FilePath;
4 import junit.framework.TestCase;
5
6 import java.io.File;
7 import java.io.IOException;
8 import java.io.PrintWriter;
9
10 /**
11 * @author Kohsuke Kawaguchi
12 */
13 public class ReopenableRotatingFileOutputStreamTest extends TestCase {
14 public void testRotation() throws IOException {
15 File base = File.createTempFile("test", "log");
16 ReopenableRotatingFileOutputStream os = new ReopenableRotatingFileOutputStream(base,3);
17 PrintWriter w = new PrintWriter(os,true);
18 for (int i=0; i<=4; i++) {
19 w.println("Content"+i);
20 os.rewind();
21 }
22 w.println("Content5");
23 w.close();
24
25 assertEquals("Content5", new FilePath(base).readToString().trim());
26 assertEquals("Content4", new FilePath(new File(base.getPath() + ".1")).readToString().trim());
27 assertEquals("Content3", new FilePath(new File(base.getPath() + ".2")).readToString().trim());
28 assertEquals("Content2", new FilePath(new File(base.getPath() + ".3")).readToString().trim());
29 assertFalse(new File(base.getPath() + ".4").exists());
30
31 os.deleteAll();
32 }
33 }
34