View Javadoc
1   /*
2    * Licensed under the GPL License. You may not use this file except in compliance with the License.
3    * You may obtain a copy of the License at
4    *
5    *   https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
6    *
7    * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
8    * WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
9    * PURPOSE.
10   */
11  package psiprobe.tools.logging.jdk;
12  
13  import java.io.File;
14  import java.io.IOException;
15  import java.nio.file.Files;
16  import java.nio.file.Path;
17  import java.util.logging.FileHandler;
18  
19  import org.assertj.core.api.Assertions;
20  import org.junit.jupiter.api.Test;
21  
22  import psiprobe.model.Application;
23  
24  /**
25   * The Class Jdk14FileHandlerAccessorTest.
26   */
27  class Jdk14FileHandlerAccessorTest {
28  
29    /**
30     * Gets the file.
31     *
32     * @throws IOException Signals that an I/O exception has occurred.
33     */
34    @Test
35    void getFile() throws IOException {
36      Jdk14FileHandlerAccessor handlerAccessor = new Jdk14FileHandlerAccessor();
37      handlerAccessor.setLoggerAccessor(new Jdk14LoggerAccessor());
38  
39      Path testPath = Files.createTempDirectory("psi-probe");
40      testPath.toFile().deleteOnExit();
41      FileHandler target = new FileHandler(testPath.toString() + "test-%g.log", 1024, 3);
42  
43      handlerAccessor.setTarget(target);
44      handlerAccessor.setIndex(Integer.toString(0));
45      Application testApplication = new Application();
46      handlerAccessor.setApplication(testApplication);
47  
48      File file = handlerAccessor.getFile();
49  
50      Assertions.assertThat(file.getAbsolutePath()).isEqualTo(testPath + "test-0.log");
51  
52    }
53  
54  }