Search in sources :

Example 91 with FileReader

use of java.io.FileReader in project spring-boot by spring-projects.

the class ApplicationPidFileWriterTests method overridePidFileWithSpring.

@Test
public void overridePidFileWithSpring() throws Exception {
    File file = this.temporaryFolder.newFile();
    SpringApplicationEvent event = createPreparedEvent("spring.pid.file", file.getAbsolutePath());
    ApplicationPidFileWriter listener = new ApplicationPidFileWriter();
    listener.onApplicationEvent(event);
    assertThat(FileCopyUtils.copyToString(new FileReader(file))).isNotEmpty();
}
Also used : SpringApplicationEvent(org.springframework.boot.context.event.SpringApplicationEvent) FileReader(java.io.FileReader) File(java.io.File) Test(org.junit.Test)

Example 92 with FileReader

use of java.io.FileReader in project spring-boot by spring-projects.

the class ApplicationPidFileWriterTests method withNoEnvironment.

@Test
public void withNoEnvironment() throws Exception {
    File file = this.temporaryFolder.newFile();
    ApplicationPidFileWriter listener = new ApplicationPidFileWriter(file);
    listener.setTriggerEventType(ApplicationStartingEvent.class);
    listener.onApplicationEvent(new ApplicationStartingEvent(new SpringApplication(), new String[] {}));
    assertThat(FileCopyUtils.copyToString(new FileReader(file))).isNotEmpty();
}
Also used : SpringApplication(org.springframework.boot.SpringApplication) FileReader(java.io.FileReader) ApplicationStartingEvent(org.springframework.boot.context.event.ApplicationStartingEvent) File(java.io.File) Test(org.junit.Test)

Example 93 with FileReader

use of java.io.FileReader in project spring-boot by spring-projects.

the class ApplicationPidFileWriterTests method tryEnvironmentPreparedEvent.

@Test
public void tryEnvironmentPreparedEvent() throws Exception {
    File file = this.temporaryFolder.newFile();
    SpringApplicationEvent event = createEnvironmentPreparedEvent("spring.pid.file", file.getAbsolutePath());
    ApplicationPidFileWriter listener = new ApplicationPidFileWriter();
    listener.onApplicationEvent(event);
    assertThat(FileCopyUtils.copyToString(new FileReader(file))).isEmpty();
    listener.setTriggerEventType(ApplicationEnvironmentPreparedEvent.class);
    listener.onApplicationEvent(event);
    assertThat(FileCopyUtils.copyToString(new FileReader(file))).isNotEmpty();
}
Also used : SpringApplicationEvent(org.springframework.boot.context.event.SpringApplicationEvent) FileReader(java.io.FileReader) File(java.io.File) Test(org.junit.Test)

Example 94 with FileReader

use of java.io.FileReader in project spring-boot by spring-projects.

the class ApplicationPidFileWriterTests method tryReadyEvent.

@Test
public void tryReadyEvent() throws Exception {
    File file = this.temporaryFolder.newFile();
    SpringApplicationEvent event = createReadyEvent("spring.pid.file", file.getAbsolutePath());
    ApplicationPidFileWriter listener = new ApplicationPidFileWriter();
    listener.onApplicationEvent(event);
    assertThat(FileCopyUtils.copyToString(new FileReader(file))).isEmpty();
    listener.setTriggerEventType(ApplicationReadyEvent.class);
    listener.onApplicationEvent(event);
    assertThat(FileCopyUtils.copyToString(new FileReader(file))).isNotEmpty();
}
Also used : SpringApplicationEvent(org.springframework.boot.context.event.SpringApplicationEvent) FileReader(java.io.FileReader) File(java.io.File) Test(org.junit.Test)

Example 95 with FileReader

use of java.io.FileReader in project spring-boot by spring-projects.

the class Log4J2LoggingSystemTests method exceptionsIncludeClassPackaging.

@Test
public void exceptionsIncludeClassPackaging() throws Exception {
    this.loggingSystem.beforeInitialize();
    this.loggingSystem.initialize(null, null, getLogFile(null, tmpDir()));
    Matcher<String> expectedOutput = containsString("[junit-");
    this.output.expect(expectedOutput);
    this.logger.warn("Expected exception", new RuntimeException("Expected"));
    String fileContents = FileCopyUtils.copyToString(new FileReader(new File(tmpDir() + "/spring.log")));
    assertThat(fileContents).is(Matched.by(expectedOutput));
}
Also used : FileReader(java.io.FileReader) Matchers.containsString(org.hamcrest.Matchers.containsString) File(java.io.File) Test(org.junit.Test)

Aggregations

FileReader (java.io.FileReader)1873 BufferedReader (java.io.BufferedReader)1289 IOException (java.io.IOException)893 File (java.io.File)811 FileNotFoundException (java.io.FileNotFoundException)304 ArrayList (java.util.ArrayList)274 Test (org.junit.Test)197 FileWriter (java.io.FileWriter)148 HashMap (java.util.HashMap)116 Reader (java.io.Reader)99 BufferedWriter (java.io.BufferedWriter)98 Properties (java.util.Properties)66 InputStreamReader (java.io.InputStreamReader)64 LineNumberReader (java.io.LineNumberReader)61 Matcher (java.util.regex.Matcher)61 Map (java.util.Map)59 List (java.util.List)56 PrintWriter (java.io.PrintWriter)51 StringTokenizer (java.util.StringTokenizer)51 HashSet (java.util.HashSet)50