2 * Sone - StringBucketTest.java - Copyright © 2013 David Roden
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 package net.pterodactylus.sone.freenet;
20 import static net.pterodactylus.sone.Matchers.delivers;
21 import static org.hamcrest.MatcherAssert.assertThat;
22 import static org.hamcrest.Matchers.containsString;
23 import static org.hamcrest.Matchers.is;
24 import static org.hamcrest.Matchers.nullValue;
26 import java.io.IOException;
27 import java.io.UnsupportedEncodingException;
28 import java.nio.charset.Charset;
30 import freenet.support.api.Bucket;
32 import org.junit.Test;
35 * Unit test for {@link StringBucket}.
37 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
39 public class StringBucketTest {
41 private static final String TEST_STRING = "StringBücket Test";
42 private final StringBucket stringBucket = new StringBucket(TEST_STRING, Charset.forName("UTF-8"));
45 public void shadowYieldsTheSameContent() throws IOException {
46 Bucket secondBucket = stringBucket.createShadow();
47 assertThat(secondBucket.getInputStream(), delivers(TEST_STRING.getBytes("UTF-8")));
51 public void freeingTheBucketDoesNothingBad() {
56 public void stringBucketHasTheCorrectSize() throws UnsupportedEncodingException {
57 assertThat(stringBucket.size(), is((long) TEST_STRING.getBytes("UTF-8").length));
61 public void inputStreamDeliversContent() throws UnsupportedEncodingException {
62 assertThat(stringBucket.getInputStream(), delivers(TEST_STRING.getBytes("UTF-8")));
66 public void nameContainsReferenceToStringBucket() {
67 assertThat(stringBucket.getName(), containsString(stringBucket.getClass().getSimpleName()));
71 public void noOutputStreamIsReturned() {
72 assertThat(stringBucket.getOutputStream(), nullValue());
76 public void theBucketIsReadOnly() {
77 assertThat(stringBucket.isReadOnly(), is(true));
81 public void setStringBucketReadOnly() {
82 stringBucket.setReadOnly();
83 assertThat(stringBucket.isReadOnly(), is(true));
87 public void storingToObjectContainerDoesNothing() {
88 stringBucket.storeTo(null);
92 public void removalFromObjectContainerDoesNothing() {
93 stringBucket.removeFrom(null);