Use a single constant for the string to be encoded.
[Sone.git] / src / test / java / net / pterodactylus / sone / freenet / StringBucketTest.java
1 /*
2  * Sone - StringBucketTest.java - Copyright © 2013 David Roden
3  *
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.
8  *
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.
13  *
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/>.
16  */
17
18 package net.pterodactylus.sone.freenet;
19
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;
25
26 import java.io.IOException;
27 import java.io.UnsupportedEncodingException;
28 import java.nio.charset.Charset;
29
30 import freenet.support.api.Bucket;
31
32 import org.junit.Test;
33
34 /**
35  * TODO
36  *
37  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
38  */
39 public class StringBucketTest {
40
41         private static final String TEST_STRING = "StringBücket Test";
42         private final StringBucket stringBucket = new StringBucket(TEST_STRING, Charset.forName("UTF-8"));
43
44         @Test
45         public void shadowYieldsTheSameContent() throws IOException {
46                 Bucket secondBucket = stringBucket.createShadow();
47                 assertThat(secondBucket.getInputStream(), delivers(TEST_STRING.getBytes("UTF-8")));
48         }
49
50         @Test
51         public void freeingTheBucketDoesNothingBad() {
52                 stringBucket.free();
53         }
54
55         @Test
56         public void stringBucketHasTheCorrectSize() throws UnsupportedEncodingException {
57                 assertThat(stringBucket.size(), is((long) TEST_STRING.getBytes("UTF-8").length));
58         }
59
60         @Test
61         public void inputStreamDeliversContent() throws UnsupportedEncodingException {
62                 assertThat(stringBucket.getInputStream(), delivers(TEST_STRING.getBytes("UTF-8")));
63         }
64
65         @Test
66         public void nameContainsReferenceToStringBucket() {
67                 assertThat(stringBucket.getName(), containsString(stringBucket.getClass().getSimpleName()));
68         }
69
70         @Test
71         public void noOutputStreamIsReturned() {
72                 assertThat(stringBucket.getOutputStream(), nullValue());
73         }
74
75         @Test
76         public void theBucketIsReadOnly() {
77                 assertThat(stringBucket.isReadOnly(), is(true));
78         }
79
80         @Test
81         public void setStringBucketReadOnly() {
82                 stringBucket.setReadOnly();
83                 assertThat(stringBucket.isReadOnly(), is(true));
84         }
85
86         @Test
87         public void storingToObjectContainerDoesNothing() {
88                 stringBucket.storeTo(null);
89         }
90
91         @Test
92         public void removalFromObjectContainerDoesNothing() {
93                 stringBucket.removeFrom(null);
94         }
95
96 }