// Path: cfg4j-core/src/main/java/org/cfg4j/source/SourceCommunicationException.java
// public class SourceCommunicationException extends RuntimeException {
// 
//   /**
//    * Indicates problem when communicating with {@link ConfigurationSource}.
//    *
//    * @param msg the detail message
//    * @param e   the cause
//    */
//   public SourceCommunicationException(String msg, Exception e) {
//     super("Unable to communicate with configuration source: " + msg, e);
//   }
// }
// 
// 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.SourceCommunicationException;
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 java.nio.file.Path;
/*
 * 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.git;




class GitConfigurationSourceIntegrationTest {

  private static final String DEFAULT_BRANCH = "master";
  private static final String TEST_ENV_BRANCH = "testEnvBranch";

  private TempConfigurationGitRepo remoteRepo;

  @BeforeEach
  void setUp() throws Exception {
    remoteRepo = new TempConfigurationGitRepo("org.cfg4j-test-repo.git");
    remoteRepo.changeProperty(Paths.get("application.properties"), "some.setting", "masterValue");
    remoteRepo.changeProperty(Paths.get("otherConfig.properties"), "otherConfig.setting", "masterValue");
    remoteRepo.changeProperty(Paths.get("malformed.properties"), "otherConfig.setting", "\\uzzzzz");
    remoteRepo.changeProperty(Paths.get("otherApplicationConfigs/application.properties"), "some.setting", "otherAppSetting");

    remoteRepo.changeBranchTo(TEST_ENV_BRANCH);
    remoteRepo.changeProperty(Paths.get("application.properties"), "some.setting", "testValue");

    remoteRepo.changeBranchTo(DEFAULT_BRANCH);
  }

  @AfterEach
  void tearDown() {
// Path: cfg4j-core/src/main/java/org/cfg4j/source/SourceCommunicationException.java
// public class SourceCommunicationException extends RuntimeException {
// 
//   /**
//    * Indicates problem when communicating with {@link ConfigurationSource}.
//    *
//    * @param msg the detail message
//    * @param e   the cause
//    */
//   public SourceCommunicationException(String msg, Exception e) {
//     super("Unable to communicate with configuration source: " + msg, e);
//   }
// }
// 
// 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-git/src/test/java/org/cfg4j/source/git/GitConfigurationSourceIntegrationTest.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.SourceCommunicationException;
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 java.nio.file.Path;

/*
 * 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.git;




class GitConfigurationSourceIntegrationTest {

  private static final String DEFAULT_BRANCH = "master";
  private static final String TEST_ENV_BRANCH = "testEnvBranch";

  private TempConfigurationGitRepo remoteRepo;

  @BeforeEach
  void setUp() throws Exception {
    remoteRepo = new TempConfigurationGitRepo("org.cfg4j-test-repo.git");
    remoteRepo.changeProperty(Paths.get("application.properties"), "some.setting", "masterValue");
    remoteRepo.changeProperty(Paths.get("otherConfig.properties"), "otherConfig.setting", "masterValue");
    remoteRepo.changeProperty(Paths.get("malformed.properties"), "otherConfig.setting", "\\uzzzzz");
    remoteRepo.changeProperty(Paths.get("otherApplicationConfigs/application.properties"), "some.setting", "otherAppSetting");

    remoteRepo.changeBranchTo(TEST_ENV_BRANCH);
    remoteRepo.changeProperty(Paths.get("application.properties"), "some.setting", "testValue");

    remoteRepo.changeBranchTo(DEFAULT_BRANCH);
  }

  @AfterEach
  void tearDown() {
    remoteRepo.remove();