Add unit test for StringBucket.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 14 Nov 2013 21:41:49 +0000 (22:41 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 28 Feb 2014 21:26:07 +0000 (22:26 +0100)
src/test/java/net/pterodactylus/sone/freenet/StringBucketTest.java [new file with mode: 0644]

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 (file)
index 0000000..3109a6f
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.
+ */
+
+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 <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+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);
+       }
+
+}