Skip to content
This repository has been archived by the owner on Jun 10, 2021. It is now read-only.

Commit

Permalink
test changes
Browse files Browse the repository at this point in the history
  • Loading branch information
kashike committed Mar 11, 2019
1 parent e54bf77 commit 6afee43
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 11 deletions.
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}

test {
useJUnitPlatform()
}

license {
header project.file('header.txt')
include '**/*.java'
Expand Down
14 changes: 12 additions & 2 deletions src/main/java/net/kyori/filter/Filter.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public interface Filter extends Component {
@NonNull FilterResponse query(final @NonNull FilterQuery query);

/**
* Query this filter and return {@code true} if {@link FilterResponse#ALLOW allowed} and {@code false} otherwise.
* Query this filter and return {@code true} if the response is {@link FilterResponse#ALLOW}, and {@code false} otherwise.
*
* @param query the query
* @return {@code true} if allowed, {@code false} otherwise
Expand All @@ -49,7 +49,17 @@ default boolean allows(final @NonNull FilterQuery query) {
}

/**
* Query this filter and return {@code true} if {@link FilterResponse#DENY denied} and {@code false} otherwise.
* Query this filter and return {@code true} if the response is {@link FilterResponse#ABSTAIN}, and {@code false} otherwise.
*
* @param query the query
* @return {@code true} if abstained, {@code false} otherwise
*/
default boolean abstains(final @NonNull FilterQuery query) {
return this.query(query) == FilterResponse.ABSTAIN;
}

/**
* Query this filter and return {@code true} if the response is {@link FilterResponse#DENY}, and {@code false} otherwise.
*
* @param query the query
* @return {@code true} if denied, {@code false} otherwise
Expand Down
26 changes: 17 additions & 9 deletions src/test/java/net/kyori/filter/FilterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,30 @@
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

class FilterTest {
private static final TestFilter FILTER = new TestFilter(0);
@Test
void testQuery_allow() {
final TestFilter f0 = new TestFilter(0);
final FilterQuery q0 = TestQuery1.of(0);
assertEquals(FilterResponse.ALLOW, f0.query(q0));
assertTrue(f0.allows(q0));
}

@Test
void testQueryable() {
assertTrue(FILTER.queryable(TestQuery1.of(0)));
assertFalse(FILTER.queryable(TestQuery2.of()));
void testQuery_abstain() {
final TestFilter f0 = new TestFilter(0);
final FilterQuery q0 = TestQuery2.of();
assertEquals(FilterResponse.ABSTAIN, f0.query(q0));
assertTrue(f0.abstains(q0));
}

@Test
void testQuery() {
assertEquals(FilterResponse.ALLOW, FILTER.query(TestQuery1.of(0)));
assertEquals(FilterResponse.ABSTAIN, FILTER.query(TestQuery2.of()));
assertEquals(FilterResponse.DENY, FILTER.query(TestQuery1.of(1)));
void testQuery_deny() {
final TestFilter f0 = new TestFilter(0);
final FilterQuery q0 = TestQuery1.of(1);
assertEquals(FilterResponse.DENY, f0.query(q0));
assertTrue(f0.denies(q0));
}
}
41 changes: 41 additions & 0 deletions src/test/java/net/kyori/filter/TypedFilterTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* This file is part of filter, licensed under the MIT License.
*
* Copyright (c) 2018-2019 KyoriPowered
*
* 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 net.kyori.filter;

import net.kyori.filter.data.TestFilter;
import net.kyori.filter.data.TestQuery1;
import net.kyori.filter.data.TestQuery2;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

class TypedFilterTest {
@Test
void testQueryable() {
final TestFilter filter = new TestFilter(0);
assertTrue(filter.queryable(TestQuery1.of(0)));
assertFalse(filter.queryable(TestQuery2.of()));
}
}

0 comments on commit 6afee43

Please sign in to comment.