/*
 * @author Ranides Atterwim <ranides@gmail.com>
 * @copyright Ranides Atterwim
 * @license WTFPL
 * @url http://ranides.net/projects/assira.junit
 */
package net.ranides.assira.junit.mockup;

import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.function.Supplier;
import javax.annotation.Resource;
import net.ranides.assira.junit.TestContract;
import net.ranides.assira.junit.TestContractRunner;
import net.ranides.assira.junit.mockup.TesterObjects.*;
import net.ranides.assira.junit.mockup.TesterInterfaces.*;
import org.junit.Ignore;

/**
 *
 * @author Ranides Atterwim <ranides@gmail.com>
 */
@SuppressWarnings("PMD")
public class Testers {
    
    public static class ForA1 {

        @TestContract
        public void run(IntA object) {
            object.findFirst();
            object.findAll();
        }

    }
        
    public static class ForA2 {

        @TestContract
        public void exec(IntA object) {
            TesterObjects.OUT.add("ForA2.exec");
        }

    }
    
    public static class ForFunction {

        @TestContract
        public void supplier(Supplier<List<String>> s) {
            s.get();
            TesterObjects.OUT.add("ForFunction.supplier");
        }
        
        @TestContract
        public void function(Function<int[], List<String>> f) {
            TesterObjects.OUT.add("ForFunction.function");
        }
        
        @TestContract
        public void list(List<String> list) {
            TesterObjects.OUT.add("ForFunction.list");
        }

    }
    
    public static class ForSupport {

        @TestContract
        public void run(IntA object) {
            object.findFirst();
            object.findAll();
        }
        
        @TestContract
        public void ignored(IntA object) {
            throw new NumberFormatException();
        }
		
		@TestContract
        public void otherMethod4Pattern(IntA object) {
            throw new NumberFormatException();
        }

    }
    
    public static class Invalid {

        @TestContract
        public void run(IntA object) {
            object.findFirst();
            object.findAll();
        }
        
        @TestContract
        public void other(IntA object, int params) {
            object.findFirst();
            object.findAll();
        }

    }
    
    public static class Correct {

        @TestContract
        public void run(IntA object) {
            object.findFirst();
            object.findAll();
        }
        
        @Ignore
        @TestContract
        public void other(IntA object, int params) {
            object.findFirst();
            object.findAll();
        }

    }

    public static class ForB {

        @TestContract
        public void runO(IntB object) {
            object.open();
        }

        @TestContract
        public void runC(IntB object) {
            object.close();
        }

    }

    public static class ForC {

        @TestContract
        public void runR(IntC object) {
            object.read();
        }

        @TestContract
        public void runW(IntC object) {
            object.write();
        }
        
        @TestContract
        public void runZ(Supplier<IntC> function) {
            function.get().next();
        }

    }
    
    public static class ForAbstractAB {
        
        @TestContract
        public void exec(AbstractAB that) {
            TesterObjects.OUT.add("ForAbstractAB.exec");
        }
                
    }
    
    public static class ForMap {
        
        @TestContract
        public void exec(Supplier<Map<Integer, String>> supplier) {
            TesterObjects.OUT.add("map");
        }
 
    }
    
    public static class ForWildcard {
        
        @TestContract
        public void wildcard(Supplier<? extends Map<Integer, String>> supplier) {
            TesterObjects.OUT.add("map");
        }
        
    }
    
    public static class ForResource1 {
        
        @Resource
        private TestContractRunner runner;
        
        @Resource
        private String name;
        
        @Resource(name="count!")
        private int count;
        
        @TestContract
        public void run(Object input) {
            TesterObjects.OUT.add("n=" +name + " c="+count);
            runner.param("out", "text:" + count);
        }
        
    }
    
    public static class ForResource2 {
        
        @Resource
        private String out;
        
        @TestContract
        public void run(Object input) {
            TesterObjects.OUT.add("v=" + out);
        }

    }
    
}
