// Path: src/main/java/org/grouchotools/jsrules/exception/InvalidParameterClassException.java
// public class InvalidParameterClassException extends InvalidParameterException {
//     public InvalidParameterClassException() {
//     }
// 
//     public InvalidParameterClassException(String message) {
//         super(message);
//     }
// 
//     public InvalidParameterClassException(String message, Throwable cause) {
//         super(message, cause);
//     }
// 
//     public InvalidParameterClassException(Throwable cause) {
//         super(cause);
//     }
// 
//     public InvalidParameterClassException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
//         super(message, cause, enableSuppression, writableStackTrace);
//     }
// }
// 
// Path: src/main/java/org/grouchotools/jsrules/exception/MissingParameterException.java
// public class MissingParameterException extends InvalidParameterException {
//     public MissingParameterException() {
//     }
// 
//     public MissingParameterException(String message) {
//         super(message);
//     }
// 
//     public MissingParameterException(String message, Throwable cause) {
//         super(message, cause);
//     }
// 
//     public MissingParameterException(Throwable cause) {
//         super(cause);
//     }
// 
//     public MissingParameterException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
//         super(message, cause, enableSuppression, writableStackTrace);
//     }
// }
// 
// Path: src/main/java/org/grouchotools/jsrules/impl/FirstTrueRulesetExecutorImpl.java
// public class FirstTrueRulesetExecutorImpl<T> extends RulesetExecutor<T> {
//     private final List<RuleExecutor<T>> ruleSet;
//     private String name;
// 
//     public FirstTrueRulesetExecutorImpl(String name, List<RuleExecutor<T>> ruleSet) {
//         this.name = name;
//         this.ruleSet = ruleSet;
//     }
// 
//     @Override
//     public T execute(Map<String, Object> parameters) throws InvalidParameterException {
//         T result = null;
//         for (RuleExecutor<T> rule : ruleSet) {
//             Parameter left = rule.getLeftParameter();
//             String leftName = left.getName();
//             Object leftParameter = parameters.get(leftName);
//             validateParameter(leftName, leftParameter, left.getKlasse());
// 
//             Parameter right = rule.getRightParameter();
// 
//             T ruleResponse;
// 
//             if (right.getStaticValue() == null) {
//                 //send both parameters
//                 String rightName = right.getName();
//                 Object rightParameter = parameters.get(rightName);
//                 validateParameter(rightName, rightParameter, right.getKlasse());
// 
//                 ruleResponse = rule.execute(leftParameter, rightParameter);
// 
//             } else {
//                 //send left parameter only
//                 ruleResponse = rule.execute(leftParameter);
//             }
// 
//             // if the rule is true, send its response and stop processing
//             if (null != ruleResponse) {
//                 result = ruleResponse;
//                 break;
//             }
//         }
//         return result;
//     }
// 
//     @Override
//     public String getName() {
//         return name;
//     }
// 
// 
// }


import org.mockito.runners.MockitoJUnitRunner;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.when;
import org.grouchotools.jsrules.exception.InvalidParameterClassException;
import org.grouchotools.jsrules.exception.MissingParameterException;
import org.grouchotools.jsrules.impl.FirstTrueRulesetExecutorImpl;
import org.junit.*;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Mock;
/*
 * The MIT License
 *
 * Copyright 2015 Paul.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
package org.grouchotools.jsrules;




/**
 * @author Paul
 */
@RunWith(MockitoJUnitRunner.class)
public class FirstTrueRulesetExecutorTest {
    private RulesetExecutor<String> executor;

    private final String leftName = "left";
    private final String rightName = "right";
    private final String nameName = "name";

    private final String rulesetName = "mockRuleset";

    @org.junit.Rule
    public ExpectedException exception = ExpectedException.none();

    @Mock
    RuleExecutor<String> ruleExecutorMock1;

    @Mock
    RuleExecutor<String> ruleExecutorMock2;

    private List<RuleExecutor<String>> ruleListMock;

    @BeforeClass
    public static void setUpClass() {
    }

    @AfterClass
    public static void tearDownClass() {
    }

    @Before
    public void setUp() {
        when(ruleExecutorMock1.getLeftParameter()).thenReturn(new Parameter<>(leftName, Long.class));
        when(ruleExecutorMock1.getRightParameter()).thenReturn(new Parameter<>(rightName, Long.class));

        when(ruleExecutorMock2.getLeftParameter()).thenReturn(new Parameter<>(leftName, Long.class));
        when(ruleExecutorMock2.getRightParameter()).thenReturn(new Parameter<>(rightName, Long.class));

        ruleListMock = new ArrayList<>();
        ruleListMock.add(ruleExecutorMock1);
        ruleListMock.add(ruleExecutorMock2);

// Path: src/main/java/org/grouchotools/jsrules/exception/InvalidParameterClassException.java
// public class InvalidParameterClassException extends InvalidParameterException {
//     public InvalidParameterClassException() {
//     }
// 
//     public InvalidParameterClassException(String message) {
//         super(message);
//     }
// 
//     public InvalidParameterClassException(String message, Throwable cause) {
//         super(message, cause);
//     }
// 
//     public InvalidParameterClassException(Throwable cause) {
//         super(cause);
//     }
// 
//     public InvalidParameterClassException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
//         super(message, cause, enableSuppression, writableStackTrace);
//     }
// }
// 
// Path: src/main/java/org/grouchotools/jsrules/exception/MissingParameterException.java
// public class MissingParameterException extends InvalidParameterException {
//     public MissingParameterException() {
//     }
// 
//     public MissingParameterException(String message) {
//         super(message);
//     }
// 
//     public MissingParameterException(String message, Throwable cause) {
//         super(message, cause);
//     }
// 
//     public MissingParameterException(Throwable cause) {
//         super(cause);
//     }
// 
//     public MissingParameterException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
//         super(message, cause, enableSuppression, writableStackTrace);
//     }
// }
// 
// Path: src/main/java/org/grouchotools/jsrules/impl/FirstTrueRulesetExecutorImpl.java
// public class FirstTrueRulesetExecutorImpl<T> extends RulesetExecutor<T> {
//     private final List<RuleExecutor<T>> ruleSet;
//     private String name;
// 
//     public FirstTrueRulesetExecutorImpl(String name, List<RuleExecutor<T>> ruleSet) {
//         this.name = name;
//         this.ruleSet = ruleSet;
//     }
// 
//     @Override
//     public T execute(Map<String, Object> parameters) throws InvalidParameterException {
//         T result = null;
//         for (RuleExecutor<T> rule : ruleSet) {
//             Parameter left = rule.getLeftParameter();
//             String leftName = left.getName();
//             Object leftParameter = parameters.get(leftName);
//             validateParameter(leftName, leftParameter, left.getKlasse());
// 
//             Parameter right = rule.getRightParameter();
// 
//             T ruleResponse;
// 
//             if (right.getStaticValue() == null) {
//                 //send both parameters
//                 String rightName = right.getName();
//                 Object rightParameter = parameters.get(rightName);
//                 validateParameter(rightName, rightParameter, right.getKlasse());
// 
//                 ruleResponse = rule.execute(leftParameter, rightParameter);
// 
//             } else {
//                 //send left parameter only
//                 ruleResponse = rule.execute(leftParameter);
//             }
// 
//             // if the rule is true, send its response and stop processing
//             if (null != ruleResponse) {
//                 result = ruleResponse;
//                 break;
//             }
//         }
//         return result;
//     }
// 
//     @Override
//     public String getName() {
//         return name;
//     }
// 
// 
// }


// Path: src/test/java/org/grouchotools/jsrules/FirstTrueRulesetExecutorTest.java
import org.mockito.runners.MockitoJUnitRunner;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.when;
import org.grouchotools.jsrules.exception.InvalidParameterClassException;
import org.grouchotools.jsrules.exception.MissingParameterException;
import org.grouchotools.jsrules.impl.FirstTrueRulesetExecutorImpl;
import org.junit.*;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Mock;

/*
 * The MIT License
 *
 * Copyright 2015 Paul.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
package org.grouchotools.jsrules;




/**
 * @author Paul
 */
@RunWith(MockitoJUnitRunner.class)
public class FirstTrueRulesetExecutorTest {
    private RulesetExecutor<String> executor;

    private final String leftName = "left";
    private final String rightName = "right";
    private final String nameName = "name";

    private final String rulesetName = "mockRuleset";

    @org.junit.Rule
    public ExpectedException exception = ExpectedException.none();

    @Mock
    RuleExecutor<String> ruleExecutorMock1;

    @Mock
    RuleExecutor<String> ruleExecutorMock2;

    private List<RuleExecutor<String>> ruleListMock;

    @BeforeClass
    public static void setUpClass() {
    }

    @AfterClass
    public static void tearDownClass() {
    }

    @Before
    public void setUp() {
        when(ruleExecutorMock1.getLeftParameter()).thenReturn(new Parameter<>(leftName, Long.class));
        when(ruleExecutorMock1.getRightParameter()).thenReturn(new Parameter<>(rightName, Long.class));

        when(ruleExecutorMock2.getLeftParameter()).thenReturn(new Parameter<>(leftName, Long.class));
        when(ruleExecutorMock2.getRightParameter()).thenReturn(new Parameter<>(rightName, Long.class));

        ruleListMock = new ArrayList<>();
        ruleListMock.add(ruleExecutorMock1);
        ruleListMock.add(ruleExecutorMock2);

        executor = new FirstTrueRulesetExecutorImpl<>(rulesetName, ruleListMock);