package io.github.tatools.sunshine.testng;

import io.github.tatools.sunshine.core.*;
import org.testng.xml.XmlSuite;
import org.testng.xml.XmlTest;

import java.io.IOException;

/**
 * @author Dmytro Serdiuk (dmytro.serdiuk@gmail.com)
 * @version $Id$
 * @since 0.1
 */
@SuppressWarnings("WeakerAccess")
public final class LoadableTestNGSuite implements TestNGSuite {

    private final SunshineSuite artifacts;
    private final Directory suitePath;

    /**
     * Construct new instance with the specified file system, suite's directory and tests filter.
     * If suite's directory ({@code xmlSuiteDirectory}) doesn't exist, it will be created automatically.
     *
     * @param fileSystem        the place with the tests
     * @param xmlSuiteDirectory the place to store suite file
     * @param filter            the filter to be used to select desired tests
     * @see #LoadableTestNGSuite(FileSystem, Directory, Condition)
     * @since 0.2
     */
    public LoadableTestNGSuite(FileSystem fileSystem, String xmlSuiteDirectory, Condition filter) {
        this(
                fileSystem,
                new DirectoryWithAutomaticCreation(new DirectorySafe(new DirectoryBase(xmlSuiteDirectory))),
                filter
        );
    }

    public LoadableTestNGSuite(FileSystem fileSystem, Directory suitePath, Condition filter) {
        this(
                new SunshineSuitePrintable(new SunshineSuiteFilterable(new SunshineSuiteBase(fileSystem), filter)),
                suitePath
        );
    }

    public LoadableTestNGSuite(SunshineSuite artifacts, Directory suitePath) {
        this.artifacts = artifacts;
        this.suitePath = suitePath;
    }

    @Override
    public File tests() throws SuiteException {
        XmlSuite xmlSuite = new XmlSuite();
        xmlSuite.setName("Sunshine suite");
        try {
            for (SunshineTest sunshineTest : this.artifacts.tests()) {
                XmlTest test = new TestNGTest(sunshineTest).object();
                test.setSuite(xmlSuite);
                xmlSuite.addTest(test);
            }
            FileBase fileBase = new FileBase(this.suitePath, "sunshine-suite.xml");
            fileBase.write(xmlSuite.toXml());
            return fileBase;
        } catch (TestException | IOException e) {
            throw new SuiteException(e);
        }
    }
}

@@ -1238,32 +1238,434 @@
       );%0A    %7D%0A%0A
+    /**%0A     * Constructs new instance with the specified file system, suite's directory and tests filter. All filtered tests%0A     * will be printed to %7B@link System#out%7D.%0A     *%0A     * @param fileSystem        the place with the tests%0A     * @param xmlSuiteDirectory the place to store suite file%0A     * @param filter            the filter to be used to select desired tests%0A     * @since 0.1%0A     */%0A
     public Loada
@@ -1712,25 +1712,33 @@
 rectory 
-suitePath
+xmlSuiteDirectory
 , Condit
@@ -1901,35 +1901,282 @@
     
-suitePath%0A        );%0A    %7D%0A
+xmlSuiteDirectory%0A        );%0A    %7D%0A%0A    /**%0A     * Constructs new instance with the specified suite and suite's directory.%0A     *%0A     * @param suite             the tests to be used%0A     * @param xmlSuiteDirectory the directory to store suite file%0A     * @since 0.1%0A     */
 %0A   
@@ -2217,25 +2217,21 @@
 neSuite 
-artifacts
+suite
 , Direct
@@ -2234,25 +2234,33 @@
 rectory 
-suitePath
+xmlSuiteDirectory
 ) %7B%0A    
@@ -2263,21 +2263,16 @@
         
-this.
 artifact
@@ -2275,25 +2275,21 @@
 facts = 
-artifacts
+suite
 ;%0A      
@@ -2290,21 +2290,16 @@
         
-this.
 suitePat
@@ -2302,25 +2302,33 @@
 ePath = 
-suitePath
+xmlSuiteDirectory
 ;%0A    %7D%0A
@@ -2537,21 +2537,16 @@
 eTest : 
-this.
 artifact
@@ -2772,13 +2772,8 @@
 ase(
-this.
 suit

Add javadoc to constructors in LoadableTestNGSuite