-
Notifications
You must be signed in to change notification settings - Fork 256
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e54ce94
commit bc30328
Showing
5 changed files
with
281 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
...rc/test/java/org/togglz/junit/vary/TogglzRuleWithVariations_CalledMultipleTimes_Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package org.togglz.junit.vary; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.togglz.junit.TogglzRule; | ||
|
||
import static org.junit.Assert.assertTrue; | ||
import static org.junit.Assert.fail; | ||
|
||
public class TogglzRuleWithVariations_CalledMultipleTimes_Test { | ||
|
||
@Rule | ||
public TogglzRule togglzRule = TogglzRule.builder(MyFeatures.class) | ||
.vary(MyFeatures.F2) | ||
.vary(MyFeatures.F3) | ||
.build(); | ||
|
||
private List<Tuple> tuples = new ArrayList<Tuple>(); | ||
private int i; | ||
|
||
@Test | ||
public void test() { | ||
tuples.add(new Tuple(MyFeatures.F1.isActive(), MyFeatures.F2.isActive(), MyFeatures.F3.isActive())); | ||
|
||
i++; | ||
switch (i) { | ||
case 1: | ||
// can't assert here because the order seems to vary between "environment" (ie mvn vs IDE) | ||
break; | ||
case 2: | ||
// can't assert here because the order seems to vary between "environment" (ie mvn vs IDE) | ||
break; | ||
case 3: | ||
// can't assert here because the order seems to vary between "environment" (ie mvn vs IDE) | ||
break; | ||
case 4: | ||
assertTrue(tuples.contains(new Tuple(false,false,false))); | ||
assertTrue(tuples.contains(new Tuple(false,false,true))); | ||
assertTrue(tuples.contains(new Tuple(false,true,false))); | ||
assertTrue(tuples.contains(new Tuple(false, true, true))); | ||
break; | ||
default: | ||
fail(); | ||
} | ||
} | ||
|
||
|
||
static class Tuple { | ||
boolean f1; | ||
boolean f2; | ||
boolean f3; | ||
|
||
public Tuple(final boolean f1, final boolean f2, final boolean f3) { | ||
this.f1 = f1; | ||
this.f2 = f2; | ||
this.f3 = f3; | ||
} | ||
|
||
@Override | ||
public boolean equals(final Object o) { | ||
if (this == o) | ||
return true; | ||
if (o == null || getClass() != o.getClass()) | ||
return false; | ||
|
||
final Tuple tuple = (Tuple) o; | ||
|
||
if (f1 != tuple.f1) | ||
return false; | ||
if (f2 != tuple.f2) | ||
return false; | ||
return f3 == tuple.f3; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
int result = (f1 ? 1 : 0); | ||
result = 31 * result + (f2 ? 1 : 0); | ||
result = 31 * result + (f3 ? 1 : 0); | ||
return result; | ||
} | ||
|
||
@Override public String toString() { | ||
return "Tuple{" + | ||
"f1=" + f1 + | ||
", f2=" + f2 + | ||
", f3=" + f3 + | ||
'}'; | ||
} | ||
} | ||
|
||
|
||
|
||
} |
28 changes: 28 additions & 0 deletions
28
junit/src/test/java/org/togglz/junit/vary/TogglzRuleWithVariations_DisableSadCase_Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package org.togglz.junit.vary; | ||
|
||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.ExpectedException; | ||
import org.togglz.junit.TogglzRule; | ||
|
||
import static org.junit.Assert.assertTrue; | ||
|
||
public class TogglzRuleWithVariations_DisableSadCase_Test { | ||
|
||
@Rule | ||
public ExpectedException expectedException = ExpectedException.none(); | ||
|
||
@Rule | ||
public TogglzRule togglzRule = TogglzRule.builder(MyFeatures.class) | ||
.disable(MyFeatures.F1) | ||
.build(); | ||
|
||
@Test | ||
public void test() { | ||
expectedException.expect(AssertionError.class); | ||
|
||
assertTrue(MyFeatures.F1.isActive()); | ||
} | ||
|
||
|
||
} |
28 changes: 28 additions & 0 deletions
28
junit/src/test/java/org/togglz/junit/vary/TogglzRuleWithVariations_EnableSadCase_Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package org.togglz.junit.vary; | ||
|
||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.ExpectedException; | ||
import org.togglz.junit.TogglzRule; | ||
|
||
import static org.junit.Assert.assertFalse; | ||
|
||
public class TogglzRuleWithVariations_EnableSadCase_Test { | ||
|
||
@Rule | ||
public ExpectedException expectedException = ExpectedException.none(); | ||
|
||
@Rule | ||
public TogglzRule togglzRule = TogglzRule.builder(MyFeatures.class) | ||
.enable(MyFeatures.F1) | ||
.build(); | ||
|
||
@Test | ||
public void test() { | ||
expectedException.expect(AssertionError.class); | ||
|
||
assertFalse(MyFeatures.F1.isActive()); | ||
} | ||
|
||
|
||
} |
32 changes: 32 additions & 0 deletions
32
junit/src/test/java/org/togglz/junit/vary/TogglzRuleWithVariations_HappyCase_Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package org.togglz.junit.vary; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.ExpectedException; | ||
import org.togglz.junit.TogglzRule; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
import static org.junit.Assert.fail; | ||
|
||
public class TogglzRuleWithVariations_HappyCase_Test { | ||
|
||
@Rule | ||
public TogglzRule togglzRule = TogglzRule.builder(MyFeatures.class) | ||
.enable(MyFeatures.F1) | ||
.vary(MyFeatures.F2) | ||
.vary(MyFeatures.F3) | ||
.build(); | ||
|
||
@Test | ||
public void test() { | ||
assertTrue(MyFeatures.F1.isActive()); | ||
assertTrue(MyFeatures.F2.isActive() || !MyFeatures.F2.isActive()); | ||
assertTrue(MyFeatures.F3.isActive() || !MyFeatures.F3.isActive()); | ||
} | ||
|
||
} |