// Path: src/main/java/org/echocat/gradle/plugins/golang/vcs/VcsReference.java
// public class VcsReference extends BaseVcsReference {
// 
//     @Nullable
//     private final String _subPath;
// 
//     public static VcsReference vcsReference(@Nonnull VcsType type, @Nonnull String name, @Nonnull String plainUri, @Nullable String ref, @Nullable String subPath) throws VcsValidationException {
//         return new VcsReference(type, name, plainUri, ref, subPath);
//     }
// 
//     public VcsReference(@Nonnull VcsType type, @Nonnull String id, @Nonnull String plain, @Nullable String ref, @Nullable String subPath) throws VcsValidationException {
//         super(type, id, URI.create(plain), ref, defaultUpdatePolicy());
//         //noinspection ConstantConditions
//         if (type == null) {
//             throw new VcsValidationException("Empty type provided.");
//         }
//         if (isEmpty(plain)) {
//             throw new VcsValidationException("Empty uri provided.");
//         }
//         _subPath = subPath;
//     }
// 
//     public VcsReference(@Nonnull VcsType type, @Nonnull String id, @Nonnull URI uri, @Nullable String ref, @Nonnull UpdatePolicy updatePolicy, @Nullable String subPath) {
//         super(type, id, uri, ref, updatePolicy);
//         //noinspection ConstantConditions
//         if (type == null) {
//             throw new NullPointerException("type is null");
//         }
//         //noinspection ConstantConditions
//         if (uri == null) {
//             throw new NullPointerException("uri is null");
//         }
//         _subPath = subPath;
//     }
// 
//     @Nonnull
//     @Override
//     public VcsType getType() {
//         //noinspection ConstantConditions
//         return super.getType();
//     }
// 
//     @Override
//     @Nonnull
//     public URI getUri() {
//         //noinspection ConstantConditions
//         return super.getUri();
//     }
// 
//     @Nullable
//     public String getSubPath() {
//         return _subPath;
//     }
// }
// 
// Path: src/main/java/org/echocat/gradle/plugins/golang/vcs/VcsValidationException.java
// public class VcsValidationException extends VcsException {
// 
//     public VcsValidationException(String message) {
//         super(message);
//     }
// 
//     public VcsValidationException(String message, Throwable cause) {
//         super(message, cause);
//     }
// 
//     public VcsValidationException(Throwable cause) {
//         super(cause);
//     }
// 
// }
// 
// Path: src/main/java/org/echocat/gradle/plugins/golang/vcs/VcsReference.java
// public static VcsReference vcsReference(@Nonnull VcsType type, @Nonnull String name, @Nonnull String plainUri, @Nullable String ref, @Nullable String subPath) throws VcsValidationException {
//     return new VcsReference(type, name, plainUri, ref, subPath);
// }


import org.echocat.gradle.plugins.golang.vcs.VcsReference;
import org.echocat.gradle.plugins.golang.vcs.VcsValidationException;
import org.junit.Test;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.nio.file.Paths;
import static org.echocat.gradle.plugins.golang.vcs.VcsReference.vcsReference;
import static org.echocat.gradle.plugins.golang.vcs.VcsType.git;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.junit.Assert.assertThat;
package org.echocat.gradle.plugins.golang.vcs.git;




public class GitVcsRepositoryExternalTest {

    private static final String NAME = "github.com/echocat/caretakerd";
    private static final String URI = "https://github.com/echocat/caretakerd.git";

    @SuppressWarnings("ConstantConditions")
    @Test
    public void test() throws Exception {
        new GitVcsRepository(referenceFor("refs/tags/v0.1.12")).updateIfRequired(Paths.get("build/test/123"));

        assertThat(new GitVcsRepository(referenceFor(null)).resolveRemoteRef().getName(), equalTo("HEAD"));
        assertThat(new GitVcsRepository(referenceFor("master")).resolveRemoteRef().getName(), equalTo("refs/heads/master"));
        assertThat(new GitVcsRepository(referenceFor("refs/master")).resolveRemoteRef(), nullValue());
        assertThat(new GitVcsRepository(referenceFor("refs/heads/master")).resolveRemoteRef().getName(), equalTo("refs/heads/master"));
        assertThat(new GitVcsRepository(referenceFor("v0.1.12")).resolveRemoteRef().getName(), equalTo("refs/tags/v0.1.12"));
        assertThat(new GitVcsRepository(referenceFor("refs/v0.1.12")).resolveRemoteRef(), nullValue());
        assertThat(new GitVcsRepository(referenceFor("refs/tags/v0.1.12")).resolveRemoteRef().getName(), equalTo("refs/tags/v0.1.12"));

    }

    @Nonnull
    protected VcsReference referenceFor(@Nullable String ref) throws VcsValidationException {
// Path: src/main/java/org/echocat/gradle/plugins/golang/vcs/VcsReference.java
// public class VcsReference extends BaseVcsReference {
// 
//     @Nullable
//     private final String _subPath;
// 
//     public static VcsReference vcsReference(@Nonnull VcsType type, @Nonnull String name, @Nonnull String plainUri, @Nullable String ref, @Nullable String subPath) throws VcsValidationException {
//         return new VcsReference(type, name, plainUri, ref, subPath);
//     }
// 
//     public VcsReference(@Nonnull VcsType type, @Nonnull String id, @Nonnull String plain, @Nullable String ref, @Nullable String subPath) throws VcsValidationException {
//         super(type, id, URI.create(plain), ref, defaultUpdatePolicy());
//         //noinspection ConstantConditions
//         if (type == null) {
//             throw new VcsValidationException("Empty type provided.");
//         }
//         if (isEmpty(plain)) {
//             throw new VcsValidationException("Empty uri provided.");
//         }
//         _subPath = subPath;
//     }
// 
//     public VcsReference(@Nonnull VcsType type, @Nonnull String id, @Nonnull URI uri, @Nullable String ref, @Nonnull UpdatePolicy updatePolicy, @Nullable String subPath) {
//         super(type, id, uri, ref, updatePolicy);
//         //noinspection ConstantConditions
//         if (type == null) {
//             throw new NullPointerException("type is null");
//         }
//         //noinspection ConstantConditions
//         if (uri == null) {
//             throw new NullPointerException("uri is null");
//         }
//         _subPath = subPath;
//     }
// 
//     @Nonnull
//     @Override
//     public VcsType getType() {
//         //noinspection ConstantConditions
//         return super.getType();
//     }
// 
//     @Override
//     @Nonnull
//     public URI getUri() {
//         //noinspection ConstantConditions
//         return super.getUri();
//     }
// 
//     @Nullable
//     public String getSubPath() {
//         return _subPath;
//     }
// }
// 
// Path: src/main/java/org/echocat/gradle/plugins/golang/vcs/VcsValidationException.java
// public class VcsValidationException extends VcsException {
// 
//     public VcsValidationException(String message) {
//         super(message);
//     }
// 
//     public VcsValidationException(String message, Throwable cause) {
//         super(message, cause);
//     }
// 
//     public VcsValidationException(Throwable cause) {
//         super(cause);
//     }
// 
// }
// 
// Path: src/main/java/org/echocat/gradle/plugins/golang/vcs/VcsReference.java
// public static VcsReference vcsReference(@Nonnull VcsType type, @Nonnull String name, @Nonnull String plainUri, @Nullable String ref, @Nullable String subPath) throws VcsValidationException {
//     return new VcsReference(type, name, plainUri, ref, subPath);
// }


// Path: src/test/java/org/echocat/gradle/plugins/golang/vcs/git/GitVcsRepositoryExternalTest.java
import org.echocat.gradle.plugins.golang.vcs.VcsReference;
import org.echocat.gradle.plugins.golang.vcs.VcsValidationException;
import org.junit.Test;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.nio.file.Paths;
import static org.echocat.gradle.plugins.golang.vcs.VcsReference.vcsReference;
import static org.echocat.gradle.plugins.golang.vcs.VcsType.git;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.junit.Assert.assertThat;

package org.echocat.gradle.plugins.golang.vcs.git;




public class GitVcsRepositoryExternalTest {

    private static final String NAME = "github.com/echocat/caretakerd";
    private static final String URI = "https://github.com/echocat/caretakerd.git";

    @SuppressWarnings("ConstantConditions")
    @Test
    public void test() throws Exception {
        new GitVcsRepository(referenceFor("refs/tags/v0.1.12")).updateIfRequired(Paths.get("build/test/123"));

        assertThat(new GitVcsRepository(referenceFor(null)).resolveRemoteRef().getName(), equalTo("HEAD"));
        assertThat(new GitVcsRepository(referenceFor("master")).resolveRemoteRef().getName(), equalTo("refs/heads/master"));
        assertThat(new GitVcsRepository(referenceFor("refs/master")).resolveRemoteRef(), nullValue());
        assertThat(new GitVcsRepository(referenceFor("refs/heads/master")).resolveRemoteRef().getName(), equalTo("refs/heads/master"));
        assertThat(new GitVcsRepository(referenceFor("v0.1.12")).resolveRemoteRef().getName(), equalTo("refs/tags/v0.1.12"));
        assertThat(new GitVcsRepository(referenceFor("refs/v0.1.12")).resolveRemoteRef(), nullValue());
        assertThat(new GitVcsRepository(referenceFor("refs/tags/v0.1.12")).resolveRemoteRef().getName(), equalTo("refs/tags/v0.1.12"));

    }

    @Nonnull
    protected VcsReference referenceFor(@Nullable String ref) throws VcsValidationException {
        return vcsReference(git, NAME, URI, ref, null);