-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
* fixes bug in order of child conditions * add JUnit tests
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* This file is part of *** M y C o R e *** | ||
* See http://www.mycore.de/ for details. | ||
* | ||
* MyCoRe is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* MyCoRe is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with MyCoRe. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package org.mycore.access.facts.condition.combined; | ||
|
||
import org.mycore.access.facts.MCRFactsHolder; | ||
|
||
public final class MCRXorCondition extends MCRAbstractCombinedCondition { | ||
@Override | ||
public boolean matches(MCRFactsHolder facts) { | ||
return conditions.stream() | ||
.filter(c -> addDebugInfoIfRequested(c, facts)) | ||
.limit(2) | ||
.count() == 1; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* This file is part of *** M y C o R e *** | ||
* See http://www.mycore.de/ for details. | ||
* | ||
* MyCoRe is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* MyCoRe is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with MyCoRe. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package org.mycore.access.facts.condition.combined; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
class MCRAndConditionTest { | ||
|
||
@Test | ||
void matches() { | ||
MCRAndCondition xor=new MCRAndCondition(); | ||
xor.add(new MCRTestCondition(()->false)); | ||
assertFalse(xor.matches(null)); | ||
xor.add(new MCRTestCondition(()->false)); | ||
assertFalse(xor.matches(null)); | ||
xor.getChildConditions().clear(); | ||
xor.add(new MCRTestCondition(()->true)); | ||
assertTrue(xor.matches(null)); | ||
xor.add(new MCRTestCondition(()->true)); | ||
assertTrue(xor.matches(null)); | ||
xor.add(new MCRTestCondition(()->false)); | ||
assertFalse(xor.matches(null)); | ||
xor.add(new MCRTestCondition(() -> { | ||
throw new RuntimeException("Should not be checked"); | ||
Check warning on line 43 in mycore-base/src/test/java/org/mycore/access/facts/condition/combined/MCRAndConditionTest.java Codacy Production / Codacy Static Code Analysismycore-base/src/test/java/org/mycore/access/facts/condition/combined/MCRAndConditionTest.java#L43
|
||
})); | ||
assertFalse(xor.matches(null)); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* This file is part of *** M y C o R e *** | ||
* See http://www.mycore.de/ for details. | ||
* | ||
* MyCoRe is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* MyCoRe is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with MyCoRe. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package org.mycore.access.facts.condition.combined; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
Check notice on line 21 in mycore-base/src/test/java/org/mycore/access/facts/condition/combined/MCRNotConditionTest.java Codacy Production / Codacy Static Code Analysismycore-base/src/test/java/org/mycore/access/facts/condition/combined/MCRNotConditionTest.java#L21
Check notice on line 21 in mycore-base/src/test/java/org/mycore/access/facts/condition/combined/MCRNotConditionTest.java Codacy Production / Codacy Static Code Analysismycore-base/src/test/java/org/mycore/access/facts/condition/combined/MCRNotConditionTest.java#L21
|
||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
class MCRNotConditionTest { | ||
|
||
@Test | ||
void matches() { | ||
MCRNotCondition xor = new MCRNotCondition(); | ||
xor.add(new MCRTestCondition(() -> false)); | ||
xor.add(new MCRTestCondition(() -> { | ||
throw new RuntimeException("Should not be checked"); | ||
Check warning on line 33 in mycore-base/src/test/java/org/mycore/access/facts/condition/combined/MCRNotConditionTest.java Codacy Production / Codacy Static Code Analysismycore-base/src/test/java/org/mycore/access/facts/condition/combined/MCRNotConditionTest.java#L33
|
||
})); | ||
assertTrue(xor.matches(null)); | ||
xor.getChildConditions().clear(); | ||
xor.add(new MCRTestCondition(() -> false)); | ||
xor.add(new MCRTestCondition(() -> { | ||
throw new RuntimeException("Should not be checked"); | ||
})); | ||
assertTrue(xor.matches(null)); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* This file is part of *** M y C o R e *** | ||
* See http://www.mycore.de/ for details. | ||
* | ||
* MyCoRe is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* MyCoRe is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with MyCoRe. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package org.mycore.access.facts.condition.combined; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
class MCROrConditionTest { | ||
|
||
@Test | ||
void matches() { | ||
MCROrCondition xor = new MCROrCondition(); | ||
xor.add(new MCRTestCondition(() -> false)); | ||
assertFalse(xor.matches(null)); | ||
xor.add(new MCRTestCondition(() -> false)); | ||
assertFalse(xor.matches(null)); | ||
xor.add(new MCRTestCondition(() -> false)); | ||
assertFalse(xor.matches(null)); | ||
xor.add(new MCRTestCondition(() -> true)); | ||
assertTrue(xor.matches(null)); | ||
xor.add(new MCRTestCondition(() -> false)); | ||
assertTrue(xor.matches(null)); | ||
xor.add(new MCRTestCondition(() -> true)); | ||
assertTrue(xor.matches(null)); | ||
xor.add(new MCRTestCondition(() -> { | ||
throw new RuntimeException("Should not be checked"); | ||
Check warning on line 44 in mycore-base/src/test/java/org/mycore/access/facts/condition/combined/MCROrConditionTest.java Codacy Production / Codacy Static Code Analysismycore-base/src/test/java/org/mycore/access/facts/condition/combined/MCROrConditionTest.java#L44
|
||
})); | ||
assertTrue(xor.matches(null)); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* This file is part of *** M y C o R e *** | ||
* See http://www.mycore.de/ for details. | ||
* | ||
* MyCoRe is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* MyCoRe is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with MyCoRe. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package org.mycore.access.facts.condition.combined; | ||
|
||
import org.mycore.access.facts.MCRFactsHolder; | ||
import org.mycore.access.facts.condition.MCRAbstractCondition; | ||
|
||
import java.util.function.Supplier; | ||
|
||
class MCRTestCondition extends MCRAbstractCondition { | ||
Supplier<Boolean> match; | ||
|
||
public MCRTestCondition(Supplier<Boolean> match) { | ||
Check notice on line 29 in mycore-base/src/test/java/org/mycore/access/facts/condition/combined/MCRTestCondition.java Codacy Production / Codacy Static Code Analysismycore-base/src/test/java/org/mycore/access/facts/condition/combined/MCRTestCondition.java#L29
|
||
this.match = match; | ||
} | ||
|
||
@Override | ||
public boolean matches(MCRFactsHolder facts) { | ||
return match.get(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* This file is part of *** M y C o R e *** | ||
* See http://www.mycore.de/ for details. | ||
* | ||
* MyCoRe is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* MyCoRe is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with MyCoRe. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package org.mycore.access.facts.condition.combined; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
class MCRXorConditionTest { | ||
|
||
@Test | ||
void matches() { | ||
MCRXorCondition xor = new MCRXorCondition(); | ||
xor.add(new MCRTestCondition(() -> false)); | ||
assertFalse(xor.matches(null)); | ||
xor.add(new MCRTestCondition(() -> false)); | ||
assertFalse(xor.matches(null)); | ||
xor.add(new MCRTestCondition(() -> false)); | ||
assertFalse(xor.matches(null)); | ||
xor.add(new MCRTestCondition(() -> true)); | ||
assertTrue(xor.matches(null)); | ||
xor.add(new MCRTestCondition(() -> false)); | ||
assertTrue(xor.matches(null)); | ||
xor.add(new MCRTestCondition(() -> true)); | ||
assertFalse(xor.matches(null)); | ||
xor.add(new MCRTestCondition(() -> { | ||
throw new RuntimeException("Should not be checked"); | ||
Check warning on line 44 in mycore-base/src/test/java/org/mycore/access/facts/condition/combined/MCRXorConditionTest.java Codacy Production / Codacy Static Code Analysismycore-base/src/test/java/org/mycore/access/facts/condition/combined/MCRXorConditionTest.java#L44
|
||
})); | ||
assertFalse(xor.matches(null)); | ||
} | ||
} |