package com.github.ahitrin.jqexample;

import com.pholser.junit.quickcheck.From;
import com.pholser.junit.quickcheck.Property;
import com.pholser.junit.quickcheck.runner.JUnitQuickcheck;
import java.util.List;
import org.junit.Ignore;
import org.junit.runner.RunWith;

import static org.junit.Assert.assertEquals;
import static org.junit.Assume.assumeTrue;

/**
 * @author Andrey Hitrin
 * @since 07.06.16
 */
@RunWith(JUnitQuickcheck.class)
public class LightSwitchTest {
    @Property public void singleSwitchWorksFine(boolean state) {
        LightSwitch aSwitch = new LightSwitch();
        aSwitch.switchLight(state);
        assertEquals(state, aSwitch.hasLight());
    }

    @Ignore("broken for now")
    @Property public void onlyTheLastSwitchHasEffect(List<Boolean> sequence) {
        assumeTrue(sequence.size() > 0);
        final LightSwitch lightSwitch = new LightSwitch();
        for (boolean state: sequence) {
            lightSwitch.switchLight(state);
        }
        assertEquals(sequence.get(sequence.size() - 1), lightSwitch.hasLight());
    }

    @Property public void singleSwitchWithGeneratorsWorksFine(@From(SwitchActionGenerator.class) SwitchAction action) {
        LightSwitch lightSwitch = new LightSwitch();
        LightSwitchModel model = new LightSwitchModel();
        action.apply(lightSwitch, model);
        assertEquals(lightSwitch.hasLight(), model.hasLight);
    }
}

@@ -207,33 +207,8 @@
 st;%0A
-import org.junit.Ignore;%0A
 impo
@@ -236,16 +236,16 @@
 unWith;%0A
+
 %0Aimport 
@@ -651,38 +651,8 @@
  %7D%0A%0A
-    @Ignore(%22broken for now%22)%0A
     
@@ -838,51 +838,33 @@
     
-for (boolean state: sequence) %7B%0A           
+sequence.forEach(state -%3E
  lig
@@ -894,20 +894,11 @@
 ate)
+)
 ;%0A
-        %7D%0A
     
@@ -1253,16 +1253,16 @@
 model);%0A
-
         
@@ -1320,11 +1320,445 @@
 );%0A    %7D
+%0A%0A    @Property public void onlyTheLastActionHasEffectWithGenerator(List%3C@From(SwitchActionGenerator.class) SwitchAction%3E sequence) %7B%0A        assumeTrue(sequence.size() %3E 0);%0A        final LightSwitch lightSwitch = new LightSwitch();%0A        final LightSwitchModel model = new LightSwitchModel();%0A        sequence.forEach(action -%3E action.apply(lightSwitch, model));%0A        assertEquals(model.hasLight, lightSwitch.hasLight());%0A    %7D
 %0A%7D%0A

Implement the same failing test using MBT