From: David ‘Bombe’ Roden Date: Thu, 14 Nov 2013 21:41:49 +0000 (+0100) Subject: Add unit test for StringBucket. X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=8af5f3270c8e2bd308fa5127729b5e0330611d19;p=Sone.git Add unit test for StringBucket. --- diff --git a/src/test/java/net/pterodactylus/sone/freenet/StringBucketTest.java b/src/test/java/net/pterodactylus/sone/freenet/StringBucketTest.java new file mode 100644 index 0000000..3109a6f --- /dev/null +++ b/src/test/java/net/pterodactylus/sone/freenet/StringBucketTest.java @@ -0,0 +1,95 @@ +/* + * Sone - StringBucketTest.java - Copyright © 2013 David Roden + * + * This program 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. + * + * This program 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 this program. If not, see . + */ + +package net.pterodactylus.sone.freenet; + +import static net.pterodactylus.sone.Matchers.delivers; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.nullValue; + +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.nio.charset.Charset; + +import freenet.support.api.Bucket; + +import org.junit.Test; + +/** + * TODO + * + * @author David ‘Bombe’ Roden + */ +public class StringBucketTest { + + private final StringBucket stringBucket = new StringBucket("StringBücket Test", Charset.forName("UTF-8")); + + @Test + public void shadowYieldsTheSameContent() throws IOException { + Bucket secondBucket = stringBucket.createShadow(); + assertThat(secondBucket.getInputStream(), delivers("StringBücket Test".getBytes("UTF-8"))); + } + + @Test + public void freeingTheBucketDoesNothingBad() { + stringBucket.free(); + } + + @Test + public void stringBucketHasTheCorrectSize() throws UnsupportedEncodingException { + assertThat(stringBucket.size(), is((long) "StringBücket Test".getBytes("UTF-8").length)); + } + + @Test + public void inputStreamDeliversContent() throws UnsupportedEncodingException { + assertThat(stringBucket.getInputStream(), delivers("StringBücket Test".getBytes("UTF-8"))); + } + + @Test + public void nameContainsReferenceToStringBucket() { + assertThat(stringBucket.getName(), containsString(stringBucket.getClass().getSimpleName())); + } + + @Test + public void noOutputStreamIsReturned() { + assertThat(stringBucket.getOutputStream(), nullValue()); + } + + @Test + public void theBucketIsReadOnly() { + assertThat(stringBucket.isReadOnly(), is(true)); + } + + @Test + public void setStringBucketReadOnly() { + stringBucket.setReadOnly(); + assertThat(stringBucket.isReadOnly(), is(true)); + } + + @Test + public void storingToObjectContainerDoesNothing() { + stringBucket.storeTo(null); + } + + @Test + public void removalFromObjectContainerDoesNothing() { + stringBucket.removeFrom(null); + } + +}