/**
 * Copyright (C) 2015 Sandor Nemeth (sandor.nemeth.1986@gmail.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.sandornemeth.metrics.spring.autoconfigure;

import org.hamcrest.Matchers;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.springframework.context.annotation.Configuration;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;

public class CsvReporterConfigurationTest extends AbstractMetricsAutoconfigurationTestSupport {

  @Rule public TemporaryFolder temporaryFolder = new TemporaryFolder();

  @Test
  public void shouldNotLoadACsvReporterIfNoneConfigured() {
    this.load(CsvReporterTestConfiguration.class);
  }

  @Test public void shouldLoadACsvReporter() throws InterruptedException {
    String[] contents = temporaryFolder.getRoot().list();
    assertThat(contents.length, is(0));
    this.load(CsvReporterTestConfiguration.class, "spring.metrics.reporters.csv.enabled=true",
              "spring.metrics.reporters.csv.formatFor=US",
              "spring.metrics.reporters.csv.reportFolder=" + temporaryFolder.getRoot()
                  .getAbsolutePath());
    Thread.sleep(2000);
    String[] loggedContents = temporaryFolder.getRoot().list((f, name) -> name.endsWith(".csv"));
    assertThat(loggedContents.length, Matchers.greaterThan(0));
  }

  @Configuration
  protected static class CsvReporterTestConfiguration {
  }

}

@@ -133,19 +133,16 @@
 cense%22);
-%0A *
  you may
@@ -166,16 +166,19 @@
 e except
+%0A *
  in comp
@@ -201,19 +201,16 @@
 License.
-%0A *
  You may
@@ -247,24 +247,16 @@
 at%0A *%0A *
-        
  http://
@@ -364,19 +364,16 @@
 software
-%0A *
  distrib
@@ -394,16 +394,19 @@
  License
+%0A *
  is dist
@@ -433,19 +433,16 @@
 %22 BASIS,
-%0A *
  WITHOUT
@@ -494,16 +494,19 @@
  express
+%0A *
  or impl
@@ -509,19 +509,16 @@
 implied.
-%0A *
  See the
@@ -577,19 +577,16 @@
 ions and
-%0A *
  limitat
@@ -591,24 +591,27 @@
 ations under
+%0A *
  the License
@@ -1042,16 +1042,18 @@
 %0A  @Rule
+%0A 
  public 
@@ -1241,16 +1241,18 @@
 %0A  @Test
+%0A 
  public 
@@ -1260,30 +1260,51 @@
 oid 
-shouldLoadACsvReporter
+csvReporterShouldBeActivatedOnConfiguration
 () t
@@ -1709,16 +1709,85 @@
 Path());
+%0A%0A    // sleep a little bit and verify if report files are generated.
 %0A    Thr
@@ -2043,15 +2043,16 @@
 ation %7B%0A
+%0A
   %7D%0A%0A%7D%0A

reformat of CsvReporterConfigurationTest