// Path: cfg4j-core/src/main/java/org/cfg4j/source/context/environment/DefaultEnvironment.java
// public class DefaultEnvironment extends ImmutableEnvironment {
//   /**
//    * Constructs environment named "" (empty string).
//    */
//   public DefaultEnvironment() {
//     super("");
//   }
// 
//   @Override
//   public String toString() {
//     return "DefaultEnvironment{}";
//   }
// }
// 
// Path: cfg4j-core/src/main/java/org/cfg4j/source/context/environment/Environment.java
// public interface Environment {
// 
//   /**
//    * Name of the environment. Should not be null.
//    *
//    * @return environment name. Not null.
//    */
//   String getName();
// 
// }
// 
// Path: cfg4j-core/src/main/java/org/cfg4j/source/context/environment/ImmutableEnvironment.java
// public class ImmutableEnvironment implements Environment {
// 
//   private final String envName;
// 
//   /**
//    * Construct environment named {@code envName}. This name never changes.
//    *
//    * @param envName environment name to use
//    */
//   public ImmutableEnvironment(String envName) {
//     this.envName = requireNonNull(envName);
//   }
// 
//   @Override
//   public String getName() {
//     return envName;
//   }
// 
//   @Override
//   public String toString() {
//     return "ImmutableEnvironment{" +
//         "envName='" + envName + '\'' +
//         '}';
//   }
// }
// 
// Path: cfg4j-core/src/main/java/org/cfg4j/source/context/environment/MissingEnvironmentException.java
// public class MissingEnvironmentException extends RuntimeException {
// 
//   private static final String MISSING_ENV_MSG = "Missing environment: ";
// 
//   /**
//    * Environment named {@code envName} is missing.
//    *
//    * @param envName environment name
//    */
//   public MissingEnvironmentException(String envName) {
//     super(MISSING_ENV_MSG + envName);
//   }
// 
//   /**
//    * Environment named {@code envName} is missing.
//    *
//    * @param envName environment name
//    * @param cause root cause
//    */
//   public MissingEnvironmentException(String envName, Throwable cause) {
//     super(MISSING_ENV_MSG + envName, cause);
//   }
// }
// 
// Path: cfg4j-core/src/main/java/org/cfg4j/source/context/filesprovider/ConfigFilesProvider.java
// public interface ConfigFilesProvider {
// 
//   /**
//    * Provide a list of configuration files to use.
//    * @return {@link Iterable} of configuration {@link File}s to use
//    */
//   Iterable<Path> getConfigFiles();
// 
// }


import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Collections;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import org.assertj.core.data.MapEntry;
import org.cfg4j.source.context.environment.DefaultEnvironment;
import org.cfg4j.source.context.environment.Environment;
import org.cfg4j.source.context.environment.ImmutableEnvironment;
import org.cfg4j.source.context.environment.MissingEnvironmentException;
import org.cfg4j.source.context.filesprovider.ConfigFilesProvider;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension;
/*
 * Copyright 2015-2018 Norbert Potocki (norbert.potocki@nort.pl)
 *
 * 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 org.cfg4j.source.classpath;





@ExtendWith(MockitoExtension.class)
class ClasspathConfigurationSourceTest {

  private TempConfigurationClasspathRepo classpathRepo;
  private ConfigFilesProvider configFilesProvider;
  private ClasspathConfigurationSource source;

  @BeforeEach
  void setUp() {
    classpathRepo = new TempConfigurationClasspathRepo();

    source = new ClasspathConfigurationSource();
    source.init();
  }

  @AfterEach
  void tearDown() throws Exception {
    classpathRepo.close();
  }

  @Test
  void getConfigurationReadsFromGivenPath() {
    Environment environment = new ImmutableEnvironment("otherApplicationConfigs");

    assertThat(source.getConfiguration(environment)).containsOnly(MapEntry.entry("some.setting", "otherAppSetting"));
  }

  @Test
  void getConfigurationDisallowsLeadingSlashInClasspathLocation() {
    Environment environment = new ImmutableEnvironment("/otherApplicationConfigs");

// Path: cfg4j-core/src/main/java/org/cfg4j/source/context/environment/DefaultEnvironment.java
// public class DefaultEnvironment extends ImmutableEnvironment {
//   /**
//    * Constructs environment named "" (empty string).
//    */
//   public DefaultEnvironment() {
//     super("");
//   }
// 
//   @Override
//   public String toString() {
//     return "DefaultEnvironment{}";
//   }
// }
// 
// Path: cfg4j-core/src/main/java/org/cfg4j/source/context/environment/Environment.java
// public interface Environment {
// 
//   /**
//    * Name of the environment. Should not be null.
//    *
//    * @return environment name. Not null.
//    */
//   String getName();
// 
// }
// 
// Path: cfg4j-core/src/main/java/org/cfg4j/source/context/environment/ImmutableEnvironment.java
// public class ImmutableEnvironment implements Environment {
// 
//   private final String envName;
// 
//   /**
//    * Construct environment named {@code envName}. This name never changes.
//    *
//    * @param envName environment name to use
//    */
//   public ImmutableEnvironment(String envName) {
//     this.envName = requireNonNull(envName);
//   }
// 
//   @Override
//   public String getName() {
//     return envName;
//   }
// 
//   @Override
//   public String toString() {
//     return "ImmutableEnvironment{" +
//         "envName='" + envName + '\'' +
//         '}';
//   }
// }
// 
// Path: cfg4j-core/src/main/java/org/cfg4j/source/context/environment/MissingEnvironmentException.java
// public class MissingEnvironmentException extends RuntimeException {
// 
//   private static final String MISSING_ENV_MSG = "Missing environment: ";
// 
//   /**
//    * Environment named {@code envName} is missing.
//    *
//    * @param envName environment name
//    */
//   public MissingEnvironmentException(String envName) {
//     super(MISSING_ENV_MSG + envName);
//   }
// 
//   /**
//    * Environment named {@code envName} is missing.
//    *
//    * @param envName environment name
//    * @param cause root cause
//    */
//   public MissingEnvironmentException(String envName, Throwable cause) {
//     super(MISSING_ENV_MSG + envName, cause);
//   }
// }
// 
// Path: cfg4j-core/src/main/java/org/cfg4j/source/context/filesprovider/ConfigFilesProvider.java
// public interface ConfigFilesProvider {
// 
//   /**
//    * Provide a list of configuration files to use.
//    * @return {@link Iterable} of configuration {@link File}s to use
//    */
//   Iterable<Path> getConfigFiles();
// 
// }


// Path: cfg4j-core/src/test/java/org/cfg4j/source/classpath/ClasspathConfigurationSourceTest.java
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Collections;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import org.assertj.core.data.MapEntry;
import org.cfg4j.source.context.environment.DefaultEnvironment;
import org.cfg4j.source.context.environment.Environment;
import org.cfg4j.source.context.environment.ImmutableEnvironment;
import org.cfg4j.source.context.environment.MissingEnvironmentException;
import org.cfg4j.source.context.filesprovider.ConfigFilesProvider;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension;

/*
 * Copyright 2015-2018 Norbert Potocki (norbert.potocki@nort.pl)
 *
 * 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 org.cfg4j.source.classpath;





@ExtendWith(MockitoExtension.class)
class ClasspathConfigurationSourceTest {

  private TempConfigurationClasspathRepo classpathRepo;
  private ConfigFilesProvider configFilesProvider;
  private ClasspathConfigurationSource source;

  @BeforeEach
  void setUp() {
    classpathRepo = new TempConfigurationClasspathRepo();

    source = new ClasspathConfigurationSource();
    source.init();
  }

  @AfterEach
  void tearDown() throws Exception {
    classpathRepo.close();
  }

  @Test
  void getConfigurationReadsFromGivenPath() {
    Environment environment = new ImmutableEnvironment("otherApplicationConfigs");

    assertThat(source.getConfiguration(environment)).containsOnly(MapEntry.entry("some.setting", "otherAppSetting"));
  }

  @Test
  void getConfigurationDisallowsLeadingSlashInClasspathLocation() {
    Environment environment = new ImmutableEnvironment("/otherApplicationConfigs");

    assertThatThrownBy(() -> source.getConfiguration(environment)).isExactlyInstanceOf(MissingEnvironmentException.class);