From 53343734b80197c3b63b9b4304f679096d451273 Mon Sep 17 00:00:00 2001 From: kashike Date: Mon, 27 Jan 2020 00:19:52 -0800 Subject: [PATCH] various changes over the past few months --- build.gradle | 5 +- header.txt | 2 +- license.txt | 2 +- src/main/java/net/kyori/filter/AllFilter.java | 5 +- src/main/java/net/kyori/filter/AnyFilter.java | 5 +- src/main/java/net/kyori/filter/Filter.java | 6 +- .../java/net/kyori/filter/FilterQuery.java | 2 +- .../java/net/kyori/filter/FilterResponse.java | 2 +- src/main/java/net/kyori/filter/Filters.java | 2 +- .../java/net/kyori/filter/MultiFilter.java | 6 +- src/main/java/net/kyori/filter/NotFilter.java | 2 +- .../java/net/kyori/filter/SingleFilter.java | 6 +- .../java/net/kyori/filter/StaticFilter.java | 4 +- .../java/net/kyori/filter/TypedFilter.java | 2 +- .../java/net/kyori/filter/AllFilterTest.java | 8 +-- .../java/net/kyori/filter/AnyFilterTest.java | 10 ++- .../net/kyori/filter/FilterResponseTest.java | 2 +- .../java/net/kyori/filter/FilterTest.java | 58 ----------------- .../java/net/kyori/filter/NotFilterTest.java | 10 ++- .../net/kyori/filter/StaticFilterTest.java | 9 ++- .../kyori/filter/{data => }/TestFilter.java | 20 ++++-- .../net/kyori/filter/TypedFilterTest.java | 64 +++++++++++++++++-- .../net/kyori/filter/data/TestQuery1.java | 34 ---------- .../net/kyori/filter/data/TestQuery2.java | 33 ---------- 24 files changed, 113 insertions(+), 186 deletions(-) delete mode 100644 src/test/java/net/kyori/filter/FilterTest.java rename src/test/java/net/kyori/filter/{data => }/TestFilter.java (84%) delete mode 100644 src/test/java/net/kyori/filter/data/TestQuery1.java delete mode 100644 src/test/java/net/kyori/filter/data/TestQuery2.java diff --git a/build.gradle b/build.gradle index 130dc37..79d97d1 100644 --- a/build.gradle +++ b/build.gradle @@ -32,7 +32,7 @@ repositories { } dependencies { - api 'net.kyori:component:1.0.0-SNAPSHOT' + api 'net.kyori:feature:1.0.0-SNAPSHOT' api 'net.kyori:examination-api:1.0.0-SNAPSHOT' api 'org.checkerframework:checker-qual:2.8.2' testImplementation 'com.google.guava:guava-testlib:28.0-jre' @@ -60,6 +60,7 @@ publishing { pom { name = project.name + url = 'https://github.com/KyoriPowered/filter' description = project.description developers { @@ -91,6 +92,6 @@ publishing { } signing { - required { project.hasProperty('signing.keyId') && gradle.taskGraph.hasTask(':publish') && project.version.endsWith('-SNAPSHOT') } + required { project.hasProperty('signing.keyId') && gradle.taskGraph.hasTask(':publish') && !project.version.endsWith('-SNAPSHOT') } sign publishing.publications.maven } diff --git a/header.txt b/header.txt index 4a99991..ba23d10 100644 --- a/header.txt +++ b/header.txt @@ -1,6 +1,6 @@ This file is part of filter, licensed under the MIT License. -Copyright (c) 2018-2019 KyoriPowered +Copyright (c) 2018-2020 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 diff --git a/license.txt b/license.txt index 32d32c5..277ced4 100644 --- a/license.txt +++ b/license.txt @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2018-2019 KyoriPowered +Copyright (c) 2018-2020 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 diff --git a/src/main/java/net/kyori/filter/AllFilter.java b/src/main/java/net/kyori/filter/AllFilter.java index 02bf124..86f8248 100644 --- a/src/main/java/net/kyori/filter/AllFilter.java +++ b/src/main/java/net/kyori/filter/AllFilter.java @@ -1,7 +1,7 @@ /* * This file is part of filter, licensed under the MIT License. * - * Copyright (c) 2018-2019 KyoriPowered + * Copyright (c) 2018-2020 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 @@ -30,11 +30,12 @@ * A filter that responds with {@link FilterResponse#ALLOW} if all of its children also respond with {@link FilterResponse#ALLOW}. */ public final class AllFilter extends MultiFilter { - protected AllFilter(final @NonNull Iterable filters) { + AllFilter(final @NonNull Iterable filters) { super(filters); } @Override + @SuppressWarnings("ForLoopReplaceableByForEach") public @NonNull FilterResponse query(final @NonNull FilterQuery query) { FilterResponse response = FilterResponse.ABSTAIN; final List filters = this.filters; diff --git a/src/main/java/net/kyori/filter/AnyFilter.java b/src/main/java/net/kyori/filter/AnyFilter.java index b639f38..e8b6474 100644 --- a/src/main/java/net/kyori/filter/AnyFilter.java +++ b/src/main/java/net/kyori/filter/AnyFilter.java @@ -1,7 +1,7 @@ /* * This file is part of filter, licensed under the MIT License. * - * Copyright (c) 2018-2019 KyoriPowered + * Copyright (c) 2018-2020 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 @@ -30,11 +30,12 @@ * A filter that responds with {@link FilterResponse#ALLOW} if any of its children respond with {@link FilterResponse#ALLOW}. */ public final class AnyFilter extends MultiFilter { - protected AnyFilter(final @NonNull Iterable filters) { + AnyFilter(final @NonNull Iterable filters) { super(filters); } @Override + @SuppressWarnings("ForLoopReplaceableByForEach") public @NonNull FilterResponse query(final @NonNull FilterQuery query) { FilterResponse response = FilterResponse.ABSTAIN; final List filters = this.filters; diff --git a/src/main/java/net/kyori/filter/Filter.java b/src/main/java/net/kyori/filter/Filter.java index 2f34a1e..6c7b255 100644 --- a/src/main/java/net/kyori/filter/Filter.java +++ b/src/main/java/net/kyori/filter/Filter.java @@ -1,7 +1,7 @@ /* * This file is part of filter, licensed under the MIT License. * - * Copyright (c) 2018-2019 KyoriPowered + * Copyright (c) 2018-2020 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 @@ -23,13 +23,13 @@ */ package net.kyori.filter; -import net.kyori.component.Component; +import net.kyori.feature.Feature; import org.checkerframework.checker.nullness.qual.NonNull; /** * A filter. */ -public interface Filter extends Component { +public interface Filter extends Feature { /** * Query this filter for a response. * diff --git a/src/main/java/net/kyori/filter/FilterQuery.java b/src/main/java/net/kyori/filter/FilterQuery.java index 5ef7943..a94423c 100644 --- a/src/main/java/net/kyori/filter/FilterQuery.java +++ b/src/main/java/net/kyori/filter/FilterQuery.java @@ -1,7 +1,7 @@ /* * This file is part of filter, licensed under the MIT License. * - * Copyright (c) 2018-2019 KyoriPowered + * Copyright (c) 2018-2020 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 diff --git a/src/main/java/net/kyori/filter/FilterResponse.java b/src/main/java/net/kyori/filter/FilterResponse.java index 29ea4c0..91a35fc 100644 --- a/src/main/java/net/kyori/filter/FilterResponse.java +++ b/src/main/java/net/kyori/filter/FilterResponse.java @@ -1,7 +1,7 @@ /* * This file is part of filter, licensed under the MIT License. * - * Copyright (c) 2018-2019 KyoriPowered + * Copyright (c) 2018-2020 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 diff --git a/src/main/java/net/kyori/filter/Filters.java b/src/main/java/net/kyori/filter/Filters.java index c9c8617..32d1243 100644 --- a/src/main/java/net/kyori/filter/Filters.java +++ b/src/main/java/net/kyori/filter/Filters.java @@ -1,7 +1,7 @@ /* * This file is part of filter, licensed under the MIT License. * - * Copyright (c) 2018-2019 KyoriPowered + * Copyright (c) 2018-2020 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 diff --git a/src/main/java/net/kyori/filter/MultiFilter.java b/src/main/java/net/kyori/filter/MultiFilter.java index f089518..a2d7c7f 100644 --- a/src/main/java/net/kyori/filter/MultiFilter.java +++ b/src/main/java/net/kyori/filter/MultiFilter.java @@ -1,7 +1,7 @@ /* * This file is part of filter, licensed under the MIT License. * - * Copyright (c) 2018-2019 KyoriPowered + * Copyright (c) 2018-2020 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 @@ -27,9 +27,9 @@ import java.util.List; import java.util.Objects; import java.util.stream.Stream; -import net.kyori.component.Component; import net.kyori.examination.Examinable; import net.kyori.examination.ExaminableProperty; +import net.kyori.feature.Feature; import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; @@ -51,7 +51,7 @@ protected MultiFilter(final @NonNull Iterable filters) { } @Override - public @NonNull Stream dependencies() { + public @NonNull Stream dependencies() { return this.filters.stream(); } diff --git a/src/main/java/net/kyori/filter/NotFilter.java b/src/main/java/net/kyori/filter/NotFilter.java index c673d93..a894f2c 100644 --- a/src/main/java/net/kyori/filter/NotFilter.java +++ b/src/main/java/net/kyori/filter/NotFilter.java @@ -1,7 +1,7 @@ /* * This file is part of filter, licensed under the MIT License. * - * Copyright (c) 2018-2019 KyoriPowered + * Copyright (c) 2018-2020 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 diff --git a/src/main/java/net/kyori/filter/SingleFilter.java b/src/main/java/net/kyori/filter/SingleFilter.java index 7b7df2d..6171e9e 100644 --- a/src/main/java/net/kyori/filter/SingleFilter.java +++ b/src/main/java/net/kyori/filter/SingleFilter.java @@ -1,7 +1,7 @@ /* * This file is part of filter, licensed under the MIT License. * - * Copyright (c) 2018-2019 KyoriPowered + * Copyright (c) 2018-2020 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 @@ -25,9 +25,9 @@ import java.util.Objects; import java.util.stream.Stream; -import net.kyori.component.Component; import net.kyori.examination.Examinable; import net.kyori.examination.ExaminableProperty; +import net.kyori.feature.Feature; import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; @@ -42,7 +42,7 @@ protected SingleFilter(final @NonNull Filter filter) { } @Override - public @NonNull Stream dependencies() { + public @NonNull Stream dependencies() { return Stream.of(this.filter); } diff --git a/src/main/java/net/kyori/filter/StaticFilter.java b/src/main/java/net/kyori/filter/StaticFilter.java index 9423e84..9b80af7 100644 --- a/src/main/java/net/kyori/filter/StaticFilter.java +++ b/src/main/java/net/kyori/filter/StaticFilter.java @@ -1,7 +1,7 @@ /* * This file is part of filter, licensed under the MIT License. * - * Copyright (c) 2018-2019 KyoriPowered + * Copyright (c) 2018-2020 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 @@ -47,7 +47,7 @@ public final class StaticFilter implements Examinable, Filter { static final StaticFilter DENY = new StaticFilter(FilterResponse.DENY); private final FilterResponse response; - protected StaticFilter(final @NonNull FilterResponse response) { + private StaticFilter(final @NonNull FilterResponse response) { this.response = response; } diff --git a/src/main/java/net/kyori/filter/TypedFilter.java b/src/main/java/net/kyori/filter/TypedFilter.java index fa9d658..a9a4e63 100644 --- a/src/main/java/net/kyori/filter/TypedFilter.java +++ b/src/main/java/net/kyori/filter/TypedFilter.java @@ -1,7 +1,7 @@ /* * This file is part of filter, licensed under the MIT License. * - * Copyright (c) 2018-2019 KyoriPowered + * Copyright (c) 2018-2020 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 diff --git a/src/test/java/net/kyori/filter/AllFilterTest.java b/src/test/java/net/kyori/filter/AllFilterTest.java index 3e5b1e2..c3070db 100644 --- a/src/test/java/net/kyori/filter/AllFilterTest.java +++ b/src/test/java/net/kyori/filter/AllFilterTest.java @@ -1,7 +1,7 @@ /* * This file is part of filter, licensed under the MIT License. * - * Copyright (c) 2018-2019 KyoriPowered + * Copyright (c) 2018-2020 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 @@ -24,8 +24,6 @@ package net.kyori.filter; import com.google.common.testing.EqualsTester; -import net.kyori.filter.data.TestFilter; -import net.kyori.filter.data.TestQuery1; import org.junit.jupiter.api.Test; import static com.google.common.truth.Truth8.assertThat; @@ -34,8 +32,8 @@ class AllFilterTest { @Test void testQuery() { - assertTrue(Filters.all(new TestFilter(10), new TestFilter(10)).allows(TestQuery1.of(10))); - assertTrue(Filters.all(new TestFilter(10), new TestFilter(20)).denies(TestQuery1.of(10))); + assertTrue(Filters.all(new TestFilter(10), new TestFilter(10)).allows(TestFilter.Query.of(10))); + assertTrue(Filters.all(new TestFilter(10), new TestFilter(20)).denies(TestFilter.Query.of(10))); } @Test diff --git a/src/test/java/net/kyori/filter/AnyFilterTest.java b/src/test/java/net/kyori/filter/AnyFilterTest.java index 6ed5ba0..0631f7d 100644 --- a/src/test/java/net/kyori/filter/AnyFilterTest.java +++ b/src/test/java/net/kyori/filter/AnyFilterTest.java @@ -1,7 +1,7 @@ /* * This file is part of filter, licensed under the MIT License. * - * Copyright (c) 2018-2019 KyoriPowered + * Copyright (c) 2018-2020 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 @@ -24,8 +24,6 @@ package net.kyori.filter; import com.google.common.testing.EqualsTester; -import net.kyori.filter.data.TestFilter; -import net.kyori.filter.data.TestQuery1; import org.junit.jupiter.api.Test; import static com.google.common.truth.Truth8.assertThat; @@ -35,9 +33,9 @@ class AnyFilterTest { @Test void testQuery() { final AnyFilter filter = Filters.any(new TestFilter(10), new TestFilter(20)); - assertTrue(filter.allows(TestQuery1.of(10))); - assertTrue(filter.denies(TestQuery1.of(15))); - assertTrue(filter.allows(TestQuery1.of(20))); + assertTrue(filter.allows(TestFilter.Query.of(10))); + assertTrue(filter.denies(TestFilter.Query.of(15))); + assertTrue(filter.allows(TestFilter.Query.of(20))); } @Test diff --git a/src/test/java/net/kyori/filter/FilterResponseTest.java b/src/test/java/net/kyori/filter/FilterResponseTest.java index 0354d8f..7a03a15 100644 --- a/src/test/java/net/kyori/filter/FilterResponseTest.java +++ b/src/test/java/net/kyori/filter/FilterResponseTest.java @@ -1,7 +1,7 @@ /* * This file is part of filter, licensed under the MIT License. * - * Copyright (c) 2018-2019 KyoriPowered + * Copyright (c) 2018-2020 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 diff --git a/src/test/java/net/kyori/filter/FilterTest.java b/src/test/java/net/kyori/filter/FilterTest.java deleted file mode 100644 index 6e08c12..0000000 --- a/src/test/java/net/kyori/filter/FilterTest.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; - -class FilterTest { - @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 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_deny() { - final TestFilter f0 = new TestFilter(0); - final FilterQuery q0 = TestQuery1.of(1); - assertEquals(FilterResponse.DENY, f0.query(q0)); - assertTrue(f0.denies(q0)); - } -} diff --git a/src/test/java/net/kyori/filter/NotFilterTest.java b/src/test/java/net/kyori/filter/NotFilterTest.java index 81c1989..aaaa111 100644 --- a/src/test/java/net/kyori/filter/NotFilterTest.java +++ b/src/test/java/net/kyori/filter/NotFilterTest.java @@ -1,7 +1,7 @@ /* * This file is part of filter, licensed under the MIT License. * - * Copyright (c) 2018-2019 KyoriPowered + * Copyright (c) 2018-2020 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 @@ -24,8 +24,6 @@ package net.kyori.filter; import com.google.common.testing.EqualsTester; -import net.kyori.filter.data.TestFilter; -import net.kyori.filter.data.TestQuery1; import org.junit.jupiter.api.Test; import static com.google.common.truth.Truth8.assertThat; @@ -35,9 +33,9 @@ class NotFilterTest { @Test void testQuery() { final Filter filter = Filters.not(new TestFilter(20)); - assertTrue(filter.allows(TestQuery1.of(10))); - assertTrue(filter.allows(TestQuery1.of(15))); - assertTrue(filter.denies(TestQuery1.of(20))); + assertTrue(filter.allows(TestFilter.Query.of(10))); + assertTrue(filter.allows(TestFilter.Query.of(15))); + assertTrue(filter.denies(TestFilter.Query.of(20))); } @Test diff --git a/src/test/java/net/kyori/filter/StaticFilterTest.java b/src/test/java/net/kyori/filter/StaticFilterTest.java index f41385c..1b92732 100644 --- a/src/test/java/net/kyori/filter/StaticFilterTest.java +++ b/src/test/java/net/kyori/filter/StaticFilterTest.java @@ -1,7 +1,7 @@ /* * This file is part of filter, licensed under the MIT License. * - * Copyright (c) 2018-2019 KyoriPowered + * Copyright (c) 2018-2020 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 @@ -24,7 +24,6 @@ package net.kyori.filter; import com.google.common.testing.EqualsTester; -import net.kyori.filter.data.TestQuery1; import org.junit.jupiter.api.Test; import static com.google.common.truth.Truth8.assertThat; @@ -34,21 +33,21 @@ class StaticFilterTest { @Test void testQuery_allow() { for(int i = 0; i < 10; i++) { - assertEquals(FilterResponse.ALLOW, Filters.allow().query(TestQuery1.of(i))); + assertEquals(FilterResponse.ALLOW, Filters.allow().query(TestFilter.Query.of(i))); } } @Test void testQuery_abstain() { for(int i = 0; i < 10; i++) { - assertEquals(FilterResponse.ABSTAIN, Filters.abstain().query(TestQuery1.of(i))); + assertEquals(FilterResponse.ABSTAIN, Filters.abstain().query(TestFilter.Query.of(i))); } } @Test void testQuery_deny() { for(int i = 0; i < 10; i++) { - assertEquals(FilterResponse.DENY, Filters.deny().query(TestQuery1.of(i))); + assertEquals(FilterResponse.DENY, Filters.deny().query(TestFilter.Query.of(i))); } } diff --git a/src/test/java/net/kyori/filter/data/TestFilter.java b/src/test/java/net/kyori/filter/TestFilter.java similarity index 84% rename from src/test/java/net/kyori/filter/data/TestFilter.java rename to src/test/java/net/kyori/filter/TestFilter.java index d2e9873..fada972 100644 --- a/src/test/java/net/kyori/filter/data/TestFilter.java +++ b/src/test/java/net/kyori/filter/TestFilter.java @@ -1,7 +1,7 @@ /* * This file is part of filter, licensed under the MIT License. * - * Copyright (c) 2018-2019 KyoriPowered + * Copyright (c) 2018-2020 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 @@ -21,16 +21,14 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package net.kyori.filter.data; +package net.kyori.filter; import java.util.stream.Stream; import net.kyori.examination.Examinable; import net.kyori.examination.ExaminableProperty; -import net.kyori.filter.FilterQuery; -import net.kyori.filter.TypedFilter; import org.checkerframework.checker.nullness.qual.NonNull; -public class TestFilter implements Examinable, TypedFilter.Strong { +public class TestFilter implements Examinable, TypedFilter.Strong { private final int number; public TestFilter(final int number) { @@ -39,11 +37,11 @@ public TestFilter(final int number) { @Override public boolean queryable(final @NonNull FilterQuery query) { - return query instanceof TestQuery1; + return query instanceof Query; } @Override - public boolean queryResponse(final @NonNull TestQuery1 query) { + public boolean queryResponse(final @NonNull Query query) { return this.number == query.number(); } @@ -51,4 +49,12 @@ public boolean queryResponse(final @NonNull TestQuery1 query) { public @NonNull Stream examinableProperties() { return Stream.of(ExaminableProperty.of("number", this.number)); } + + public interface Query extends FilterQuery { + static Query of(final int number) { + return () -> number; + } + + int number(); + } } diff --git a/src/test/java/net/kyori/filter/TypedFilterTest.java b/src/test/java/net/kyori/filter/TypedFilterTest.java index b4baef9..6ec4295 100644 --- a/src/test/java/net/kyori/filter/TypedFilterTest.java +++ b/src/test/java/net/kyori/filter/TypedFilterTest.java @@ -1,7 +1,7 @@ /* * This file is part of filter, licensed under the MIT License. * - * Copyright (c) 2018-2019 KyoriPowered + * Copyright (c) 2018-2020 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 @@ -23,9 +23,7 @@ */ package net.kyori.filter; -import net.kyori.filter.data.TestFilter; -import net.kyori.filter.data.TestQuery1; -import net.kyori.filter.data.TestQuery2; +import org.checkerframework.checker.nullness.qual.NonNull; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertFalse; @@ -34,8 +32,60 @@ class TypedFilterTest { @Test void testQueryable() { - final TestFilter filter = new TestFilter(0); - assertTrue(filter.queryable(TestQuery1.of(0))); - assertFalse(filter.queryable(TestQuery2.of())); + final TestFilterA f0 = new TestFilterA(); + assertTrue(f0.queryable(TestQueryA.create())); + assertFalse(f0.queryable(TestQueryB.create())); + final TestFilterB f1 = new TestFilterB(); + assertFalse(f1.queryable(TestQueryA.create())); + assertTrue(f1.queryable(TestQueryB.create())); + } + + @Test + void testQuery() { + final TestFilterA f0 = new TestFilterA(); + assertTrue(f0.abstains(TestQueryB.create())); + final TestFilterB f1 = new TestFilterB(); + assertTrue(f1.abstains(TestQueryA.create())); + } + + private static class TestFilterA implements TypedFilter.Strong { + @Override + public boolean queryable(final @NonNull FilterQuery query) { + return query instanceof TestQueryA; + } + + @Override + public boolean queryResponse(final @NonNull TestQueryA query) { + throw new UnsupportedOperationException(); + } + } + + private static class TestFilterB implements TypedFilter.Strong { + @Override + public boolean queryable(final @NonNull FilterQuery query) { + return query instanceof TestQueryB; + } + + @Override + public boolean queryResponse(final @NonNull TestQueryB query) { + throw new UnsupportedOperationException(); + } + } + + private interface TestQuery extends FilterQuery { + } + + private interface TestQueryA extends TestQuery { + static TestQueryA create() { + return new TestQueryA() { + }; + } + } + + private interface TestQueryB extends TestQuery { + static TestQueryB create() { + return new TestQueryB() { + }; + } } } diff --git a/src/test/java/net/kyori/filter/data/TestQuery1.java b/src/test/java/net/kyori/filter/data/TestQuery1.java deleted file mode 100644 index 0e7ae15..0000000 --- a/src/test/java/net/kyori/filter/data/TestQuery1.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * 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.data; - -import net.kyori.filter.FilterQuery; - -public interface TestQuery1 extends FilterQuery { - static TestQuery1 of(final int number) { - return () -> number; - } - - int number(); -} diff --git a/src/test/java/net/kyori/filter/data/TestQuery2.java b/src/test/java/net/kyori/filter/data/TestQuery2.java deleted file mode 100644 index 1846cc6..0000000 --- a/src/test/java/net/kyori/filter/data/TestQuery2.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * 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.data; - -import net.kyori.filter.FilterQuery; - -public interface TestQuery2 extends FilterQuery { - static TestQuery2 of() { - return new TestQuery2() { - }; - } -}