-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fixes bug in order of child conditions * add JUnit tests
- Loading branch information
Showing
12 changed files
with
294 additions
and
40 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
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
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
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
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
31 changes: 31 additions & 0 deletions
31
mycore-base/src/main/java/org/mycore/access/facts/condition/combined/MCRXorCondition.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,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; | ||
} | ||
} |
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
48 changes: 48 additions & 0 deletions
48
...re-base/src/test/java/org/mycore/access/facts/condition/combined/MCRAndConditionTest.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,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 UnsupportedOperationException("Should not be checked"); | ||
})); | ||
assertFalse(xor.matches(null)); | ||
} | ||
|
||
} |
44 changes: 44 additions & 0 deletions
44
...re-base/src/test/java/org/mycore/access/facts/condition/combined/MCRNotConditionTest.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,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; | ||
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 UnsupportedOperationException("Should not be checked"); | ||
})); | ||
assertTrue(xor.matches(null)); | ||
xor.getChildConditions().clear(); | ||
xor.add(new MCRTestCondition(() -> true)); | ||
xor.add(new MCRTestCondition(() -> { | ||
throw new UnsupportedOperationException("Should not be checked"); | ||
})); | ||
assertFalse(xor.matches(null)); | ||
} | ||
|
||
} |
49 changes: 49 additions & 0 deletions
49
mycore-base/src/test/java/org/mycore/access/facts/condition/combined/MCROrConditionTest.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,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 UnsupportedOperationException("Should not be checked"); | ||
})); | ||
assertTrue(xor.matches(null)); | ||
} | ||
|
||
} |
37 changes: 37 additions & 0 deletions
37
mycore-base/src/test/java/org/mycore/access/facts/condition/combined/MCRTestCondition.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,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; | ||
|
||
MCRTestCondition(Supplier<Boolean> match) { | ||
this.match = match; | ||
} | ||
|
||
@Override | ||
public boolean matches(MCRFactsHolder facts) { | ||
return match.get(); | ||
} | ||
} |
Oops, something went wrong.