From f5a364020e82cc09f3cda4ef95ed4fa831b4a951 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Wed, 8 Feb 2023 12:46:07 +0100 Subject: [PATCH] =?utf8?q?=E2=9C=85=20Add=20test=20for=20ClientGet=20comma?= =?utf8?q?nd?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../java/net/pterodactylus/fcp/ClientGetTest.java | 135 +++++++++++++++++++++ 1 file changed, 135 insertions(+) create mode 100644 src/test/java/net/pterodactylus/fcp/ClientGetTest.java diff --git a/src/test/java/net/pterodactylus/fcp/ClientGetTest.java b/src/test/java/net/pterodactylus/fcp/ClientGetTest.java new file mode 100644 index 0000000..5ebd4de --- /dev/null +++ b/src/test/java/net/pterodactylus/fcp/ClientGetTest.java @@ -0,0 +1,135 @@ +package net.pterodactylus.fcp; + +import java.util.function.Consumer; + +import org.hamcrest.Matcher; +import org.junit.Test; + +import static net.pterodactylus.fcp.Persistence.reboot; +import static net.pterodactylus.fcp.Priority.bulkSplitfile; +import static net.pterodactylus.fcp.Verbosity.COMPRESSION; +import static net.pterodactylus.fcp.Verbosity.PROGRESS; +import static net.pterodactylus.fcp.test.Matchers.isMessage; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.allOf; +import static org.hamcrest.Matchers.hasItem; + +/** + * Unit test for {@link ClientGet}. + */ +public class ClientGetTest { + + @Test + public void canCreateClientGet() { + ClientGet clientGet = new ClientGet("uri", "identifier"); + assertThat(clientGet, isMessage("ClientGet", + "URI=uri", + "Identifier=identifier", + "ReturnType=direct" + )); + } + + @Test + public void canCreateClientGetWithReturnType() { + ClientGet clientGet = new ClientGet("uri", "identifier", ReturnType.disk); + assertThat(clientGet, isMessage("ClientGet", + "URI=uri", + "Identifier=identifier", + "ReturnType=disk" + )); + } + + @Test + public void ignoreDataStoreFlagIsIncluded() { + testThatAFieldIsIncluded(cg -> cg.setIgnoreDataStore(true), "IgnoreDS=true"); + } + + @Test + public void setDataStoreOnlyFlagIsIncluded() { + testThatAFieldIsIncluded(cg -> cg.setDataStoreOnly(true), "DSonly=true"); + } + + @Test + public void verbosityIsIncluded() { + testThatAFieldIsIncluded(cg -> cg.setVerbosity(COMPRESSION.add(PROGRESS)), "Verbosity=513"); + } + + @Test + public void maxSizeIsIncluded() { + testThatAFieldIsIncluded(cg -> cg.setMaxSize(1234567), "MaxSize=1234567"); + } + + @Test + public void maxTempSizeIsIncluded() { + testThatAFieldIsIncluded(cg -> cg.setMaxTempSize(2345678), "MaxTempSize=2345678"); + } + + @Test + public void maxRetriesIsIncluded() { + testThatAFieldIsIncluded(cg -> cg.setMaxRetries(12), "MaxRetries=12"); + } + + @Test + public void priorityIsIncluded() { + testThatAFieldIsIncluded(cg -> cg.setPriority(bulkSplitfile), "PriorityClass=4"); + } + + @Test + public void realTimeFlagIsIncluded() { + testThatAFieldIsIncluded(cg -> cg.setRealTimeFlag(true), "RealTimeFlag=true"); + } + + @Test + public void persistenceIsIncluded() { + testThatAFieldIsIncluded(cg -> cg.setPersistence(reboot), "Persistence=reboot"); + } + + @Test + public void clientTokenIsIncluded() { + testThatAFieldIsIncluded(cg -> cg.setClientToken("clientToken"), "ClientToken=clientToken"); + } + + @Test + public void globalIsIncluded() { + testThatAFieldIsIncluded(cg -> cg.setGlobal(true), "Global=true"); + } + + @Test + public void binaryBlobIsIncluded() { + testThatAFieldIsIncluded(cg -> cg.setBinaryBlob(true), "BinaryBlob=true"); + } + + @Test + public void filterDataIsIncluded() { + testThatAFieldIsIncluded(cg -> cg.setFilterData(true), "FilterData=true"); + } + + @Test + public void allowedMimeTypesAreIncluded() { + testThatAFieldIsIncluded(cg -> cg.setAllowedMimeTypes("text/plain", "text/html"), "AllowedMIMETypes=text/plain;text/html"); + } + + @Test + public void filenameIsIncluded() { + testThatAFieldIsIncluded(cg -> cg.setFilename("file.dat"), "Filename=file.dat"); + } + + @Test + public void tempFilenameIsIncluded() { + testThatAFieldIsIncluded(cg -> cg.setTempFilename("temp.dat"), "TempFilename=temp.dat"); + } + + private void testThatAFieldIsIncluded(Consumer setter, String expectedResult) { + ClientGet clientGet = new ClientGet("uri", "identifier"); + setter.accept(clientGet); + assertThat(clientGet, isMessage("ClientGet", allOf( + containsBoilerPlate(), + hasItem(expectedResult) + ))); + } + + private static Matcher> containsBoilerPlate() { + return allOf(hasItem("URI=uri"), hasItem("Identifier=identifier"), hasItem("ReturnType=direct")); + } + +} -- 2.7.4