// Path: src/main/java/com/tw/go/plugins/artifactory/task/config/ConfigElement.java
// public abstract class ConfigElement<T> {
//     public static ConfigElement<UriConfig> uriConfig = new UriConfigElement();
//     public static ConfigElement<String> path = new PathConfigElement();
//     public static ConfigElement<Map<String, String>> buildProperties = new BuildPropertiesConfigElement();
// 
//     public List<String> names;
// 
//     protected ConfigElement(String... name) {
//         this.names = asList(name);
//     }
// 
//     public void addTo(TaskConfig taskConfig) {
//         for (String name : names) {
//             taskConfig.addProperty(name);
//         }
//     }
// 
//     public abstract T from(TaskConfig taskConfig);
//     public abstract Optional<ValidationError> validate(TaskConfig taskConfig);
// }


import com.thoughtworks.go.plugin.api.response.validation.ValidationError;
import com.thoughtworks.go.plugin.api.response.validation.ValidationResult;
import com.thoughtworks.go.plugin.api.task.TaskConfig;
import com.thoughtworks.go.plugin.api.task.TaskExecutor;
import com.tw.go.plugins.artifactory.task.config.ConfigElement;
import org.junit.Test;
import java.util.List;
import static com.google.common.base.Optional.absent;
import static com.google.common.base.Optional.of;
import static java.util.Arrays.asList;
import static org.mockito.Mockito.*;
import static org.truth0.Truth.ASSERT;
package com.tw.go.plugins.artifactory.task;




public class GenericTaskTest {
    private ConfigElement configElement = mock(ConfigElement.class);
    private GenericTask task = new TestableGenericTask(asList(configElement));

    @Test
    public void shouldAddConfigElementToTaskConfig() {
        TaskConfig config = task.config();
        verify(configElement).addTo(config);
    }

    @Test
    public void shouldReturnErrorsIfValidationFails() {
        TaskConfig taskConfig = mock(TaskConfig.class);
        ValidationError error = new ValidationError("error message");

        when(configElement.validate(taskConfig)).thenReturn(of(error));

        ValidationResult result = task.validate(taskConfig);

        ASSERT.that(result.getErrors()).has().exactly(error);
    }

    @Test
    public void shouldNotReturnErrorsIfValidationPasses() {
        TaskConfig taskConfig = mock(TaskConfig.class);
        when(configElement.validate(taskConfig)).thenReturn(absent());

        ValidationResult result = task.validate(taskConfig);

        ASSERT.that(result.isSuccessful()).isTrue();
    }

    private static class TestableGenericTask extends GenericTask {
// Path: src/main/java/com/tw/go/plugins/artifactory/task/config/ConfigElement.java
// public abstract class ConfigElement<T> {
//     public static ConfigElement<UriConfig> uriConfig = new UriConfigElement();
//     public static ConfigElement<String> path = new PathConfigElement();
//     public static ConfigElement<Map<String, String>> buildProperties = new BuildPropertiesConfigElement();
// 
//     public List<String> names;
// 
//     protected ConfigElement(String... name) {
//         this.names = asList(name);
//     }
// 
//     public void addTo(TaskConfig taskConfig) {
//         for (String name : names) {
//             taskConfig.addProperty(name);
//         }
//     }
// 
//     public abstract T from(TaskConfig taskConfig);
//     public abstract Optional<ValidationError> validate(TaskConfig taskConfig);
// }


// Path: src/test/java/com/tw/go/plugins/artifactory/task/GenericTaskTest.java
import com.thoughtworks.go.plugin.api.response.validation.ValidationError;
import com.thoughtworks.go.plugin.api.response.validation.ValidationResult;
import com.thoughtworks.go.plugin.api.task.TaskConfig;
import com.thoughtworks.go.plugin.api.task.TaskExecutor;
import com.tw.go.plugins.artifactory.task.config.ConfigElement;
import org.junit.Test;
import java.util.List;
import static com.google.common.base.Optional.absent;
import static com.google.common.base.Optional.of;
import static java.util.Arrays.asList;
import static org.mockito.Mockito.*;
import static org.truth0.Truth.ASSERT;

package com.tw.go.plugins.artifactory.task;




public class GenericTaskTest {
    private ConfigElement configElement = mock(ConfigElement.class);
    private GenericTask task = new TestableGenericTask(asList(configElement));

    @Test
    public void shouldAddConfigElementToTaskConfig() {
        TaskConfig config = task.config();
        verify(configElement).addTo(config);
    }

    @Test
    public void shouldReturnErrorsIfValidationFails() {
        TaskConfig taskConfig = mock(TaskConfig.class);
        ValidationError error = new ValidationError("error message");

        when(configElement.validate(taskConfig)).thenReturn(of(error));

        ValidationResult result = task.validate(taskConfig);

        ASSERT.that(result.getErrors()).has().exactly(error);
    }

    @Test
    public void shouldNotReturnErrorsIfValidationPasses() {
        TaskConfig taskConfig = mock(TaskConfig.class);
        when(configElement.validate(taskConfig)).thenReturn(absent());

        ValidationResult result = task.validate(taskConfig);

        ASSERT.that(result.isSuccessful()).isTrue();
    }

    private static class TestableGenericTask extends GenericTask {
        public TestableGenericTask(List<? extends ConfigElement> configElements) {