From 5312e83fe6ec3578b506b4c7e9df2312dc34ec13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Sun, 27 Sep 2020 23:18:46 +0200 Subject: [PATCH] :truck: Add missing test classes --- .../AnnotatedMethodServiceFactory.java | 2 +- .../services/mock/AnnotatedMethodTest.java | 37 ++++++++++ .../mock/CompletingPartialResultService.java | 48 +++++++++++++ .../mock/DefaultSideEffectService.java | 39 ++++++++++ .../services/mock/MockChunkedRequest.java | 67 +++++++++++++++++ .../services/mock/MockResultConsumer.java | 39 ++++++++++ .../services/mock/MockService.java | 71 +++++++++++++++++++ .../services/mock/MockSideEffectService.java | 48 +++++++++++++ .../services/mock/SecondaryMockService.java | 43 +++++++++++ 9 files changed, 393 insertions(+), 1 deletion(-) create mode 100644 cloud-services/src/test/java/cloud/commandframework/services/mock/AnnotatedMethodTest.java create mode 100644 cloud-services/src/test/java/cloud/commandframework/services/mock/CompletingPartialResultService.java create mode 100644 cloud-services/src/test/java/cloud/commandframework/services/mock/DefaultSideEffectService.java create mode 100644 cloud-services/src/test/java/cloud/commandframework/services/mock/MockChunkedRequest.java create mode 100644 cloud-services/src/test/java/cloud/commandframework/services/mock/MockResultConsumer.java create mode 100644 cloud-services/src/test/java/cloud/commandframework/services/mock/MockService.java create mode 100644 cloud-services/src/test/java/cloud/commandframework/services/mock/MockSideEffectService.java create mode 100644 cloud-services/src/test/java/cloud/commandframework/services/mock/SecondaryMockService.java diff --git a/cloud-services/src/main/java/cloud/commandframework/services/AnnotatedMethodServiceFactory.java b/cloud-services/src/main/java/cloud/commandframework/services/AnnotatedMethodServiceFactory.java index addf0ecb..72cef9fc 100644 --- a/cloud-services/src/main/java/cloud/commandframework/services/AnnotatedMethodServiceFactory.java +++ b/cloud-services/src/main/java/cloud/commandframework/services/AnnotatedMethodServiceFactory.java @@ -1,7 +1,7 @@ // // MIT License // -// Copyright (c) 2020 IntellectualSites +// Copyright (c) 2020 Alexander Söderberg // // 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/cloud-services/src/test/java/cloud/commandframework/services/mock/AnnotatedMethodTest.java b/cloud-services/src/test/java/cloud/commandframework/services/mock/AnnotatedMethodTest.java new file mode 100644 index 00000000..56637ef5 --- /dev/null +++ b/cloud-services/src/test/java/cloud/commandframework/services/mock/AnnotatedMethodTest.java @@ -0,0 +1,37 @@ +// +// MIT License +// +// Copyright (c) 2020 IntellectualSites +// +// 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 cloud.commandframework.services.mock; + +import cloud.commandframework.services.annotations.ServiceImplementation; + +import javax.annotation.Nonnull; + +public class AnnotatedMethodTest { + + @ServiceImplementation(MockService.class) + public MockService.MockResult handle(@Nonnull final MockService.MockContext context) { + return new MockService.MockResult(context.getString().length()); + } + +} diff --git a/cloud-services/src/test/java/cloud/commandframework/services/mock/CompletingPartialResultService.java b/cloud-services/src/test/java/cloud/commandframework/services/mock/CompletingPartialResultService.java new file mode 100644 index 00000000..3394142d --- /dev/null +++ b/cloud-services/src/test/java/cloud/commandframework/services/mock/CompletingPartialResultService.java @@ -0,0 +1,48 @@ +// +// MIT License +// +// Copyright (c) 2020 IntellectualSites +// +// 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 cloud.commandframework.services.mock; + +import javax.annotation.Nonnull; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class CompletingPartialResultService implements MockPartialResultService { + + @Nonnull + @Override + public Map handleRequests( + @Nonnull List requests) { + final Map map = new HashMap<>(); + for (final MockChunkedRequest.Animal animal : requests) { + if (animal.getName().equals("cow")) { + map.put(animal, new MockChunkedRequest.Sound("moo")); + } else if (animal.getName().equals("dog")) { + map.put(animal, new MockChunkedRequest.Sound("woof")); + } + } + return map; + } + +} diff --git a/cloud-services/src/test/java/cloud/commandframework/services/mock/DefaultSideEffectService.java b/cloud-services/src/test/java/cloud/commandframework/services/mock/DefaultSideEffectService.java new file mode 100644 index 00000000..9bf2116d --- /dev/null +++ b/cloud-services/src/test/java/cloud/commandframework/services/mock/DefaultSideEffectService.java @@ -0,0 +1,39 @@ +// +// MIT License +// +// Copyright (c) 2020 IntellectualSites +// +// 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 cloud.commandframework.services.mock; + +import cloud.commandframework.services.State; + +import javax.annotation.Nonnull; + +public class DefaultSideEffectService implements MockSideEffectService { + + @Nonnull + @Override + public State handle(@Nonnull final MockPlayer mockPlayer) { + mockPlayer.setHealth(0); + return State.ACCEPTED; + } + +} diff --git a/cloud-services/src/test/java/cloud/commandframework/services/mock/MockChunkedRequest.java b/cloud-services/src/test/java/cloud/commandframework/services/mock/MockChunkedRequest.java new file mode 100644 index 00000000..8395bca7 --- /dev/null +++ b/cloud-services/src/test/java/cloud/commandframework/services/mock/MockChunkedRequest.java @@ -0,0 +1,67 @@ +// +// MIT License +// +// Copyright (c) 2020 IntellectualSites +// +// 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 cloud.commandframework.services.mock; + +import cloud.commandframework.services.ChunkedRequestContext; + +import javax.annotation.Nonnull; +import java.util.Collection; + +public class MockChunkedRequest + extends ChunkedRequestContext { + + public MockChunkedRequest(@Nonnull final Collection requests) { + super(requests); + } + + public static class Animal { + + private final String name; + + public Animal(@Nonnull final String name) { + this.name = name; + } + + @Nonnull + public String getName() { + return this.name; + } + } + + + public static class Sound { + + private final String sound; + + public Sound(@Nonnull final String sound) { + this.sound = sound; + } + + @Nonnull + public String getSound() { + return this.sound; + } + } + +} diff --git a/cloud-services/src/test/java/cloud/commandframework/services/mock/MockResultConsumer.java b/cloud-services/src/test/java/cloud/commandframework/services/mock/MockResultConsumer.java new file mode 100644 index 00000000..4426e1a6 --- /dev/null +++ b/cloud-services/src/test/java/cloud/commandframework/services/mock/MockResultConsumer.java @@ -0,0 +1,39 @@ +// +// MIT License +// +// Copyright (c) 2020 IntellectualSites +// +// 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 cloud.commandframework.services.mock; + +import cloud.commandframework.services.State; +import cloud.commandframework.services.types.SideEffectService; + +import javax.annotation.Nonnull; + +public class MockResultConsumer implements SideEffectService { + + @Nonnull + @Override + public State handle(@Nonnull final MockService.MockResult mockResultConsumer) { + return State.ACCEPTED; + } + +} diff --git a/cloud-services/src/test/java/cloud/commandframework/services/mock/MockService.java b/cloud-services/src/test/java/cloud/commandframework/services/mock/MockService.java new file mode 100644 index 00000000..8c4508ca --- /dev/null +++ b/cloud-services/src/test/java/cloud/commandframework/services/mock/MockService.java @@ -0,0 +1,71 @@ +// +// MIT License +// +// Copyright (c) 2020 IntellectualSites +// +// 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 cloud.commandframework.services.mock; + +import cloud.commandframework.services.types.Service; + +import javax.annotation.Nonnull; + +public interface MockService extends Service { + + class MockContext { + + private final String string; + private String state = ""; + + public MockContext(@Nonnull final String string) { + this.string = string; + } + + @Nonnull + public String getString() { + return this.string; + } + + @Nonnull + public String getState() { + return this.state; + } + + public void setState(@Nonnull final String state) { + this.state = state; + } + + } + + class MockResult { + + private final int integer; + + public MockResult(final int integer) { + this.integer = integer; + } + + public int getInteger() { + return this.integer; + } + + } + +} diff --git a/cloud-services/src/test/java/cloud/commandframework/services/mock/MockSideEffectService.java b/cloud-services/src/test/java/cloud/commandframework/services/mock/MockSideEffectService.java new file mode 100644 index 00000000..fa5962de --- /dev/null +++ b/cloud-services/src/test/java/cloud/commandframework/services/mock/MockSideEffectService.java @@ -0,0 +1,48 @@ +// +// MIT License +// +// Copyright (c) 2020 IntellectualSites +// +// 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 cloud.commandframework.services.mock; + +import cloud.commandframework.services.types.SideEffectService; + +public interface MockSideEffectService extends SideEffectService { + + class MockPlayer { + + private int health; + + public MockPlayer(final int health) { + this.health = health; + } + + public int getHealth() { + return this.health; + } + + public void setHealth(final int health) { + this.health = health; + } + + } + +} diff --git a/cloud-services/src/test/java/cloud/commandframework/services/mock/SecondaryMockService.java b/cloud-services/src/test/java/cloud/commandframework/services/mock/SecondaryMockService.java new file mode 100644 index 00000000..7469c8a4 --- /dev/null +++ b/cloud-services/src/test/java/cloud/commandframework/services/mock/SecondaryMockService.java @@ -0,0 +1,43 @@ +// +// MIT License +// +// Copyright (c) 2020 IntellectualSites +// +// 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 cloud.commandframework.services.mock; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import java.util.function.Predicate; + +public class SecondaryMockService implements MockService, Predicate { + + @Nullable + @Override + public MockResult handle(@Nonnull final MockContext mockContext) { + return new MockResult(999); + } + + @Override + public boolean test(final MockContext mockContext) { + return mockContext.getString().equalsIgnoreCase("potato"); + } + +}