3109a6f285797b349b6504726bbbad2ee2546a84
[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 final StringBucket stringBucket = new StringBucket("StringBücket Test", Charset.forName("UTF-8"));
42
43         @Test
44         public void shadowYieldsTheSameContent() throws IOException {
45                 Bucket secondBucket = stringBucket.createShadow();
46                 assertThat(secondBucket.getInputStream(), delivers("StringBücket Test".getBytes("UTF-8")));
47         }
48
49         @Test
50         public void freeingTheBucketDoesNothingBad() {
51                 stringBucket.free();
52         }
53
54         @Test
55         public void stringBucketHasTheCorrectSize() throws UnsupportedEncodingException {
56                 assertThat(stringBucket.size(), is((long) "StringBücket Test".getBytes("UTF-8").length));
57         }
58
59         @Test
60         public void inputStreamDeliversContent() throws UnsupportedEncodingException {
61                 assertThat(stringBucket.getInputStream(), delivers("StringBücket Test".getBytes("UTF-8")));
62         }
63
64         @Test
65         public void nameContainsReferenceToStringBucket() {
66                 assertThat(stringBucket.getName(), containsString(stringBucket.getClass().getSimpleName()));
67         }
68
69         @Test
70         public void noOutputStreamIsReturned() {
71                 assertThat(stringBucket.getOutputStream(), nullValue());
72         }
73
74         @Test
75         public void theBucketIsReadOnly() {
76                 assertThat(stringBucket.isReadOnly(), is(true));
77         }
78
79         @Test
80         public void setStringBucketReadOnly() {
81                 stringBucket.setReadOnly();
82                 assertThat(stringBucket.isReadOnly(), is(true));
83         }
84
85         @Test
86         public void storingToObjectContainerDoesNothing() {
87                 stringBucket.storeTo(null);
88         }
89
90         @Test
91         public void removalFromObjectContainerDoesNothing() {
92                 stringBucket.removeFrom(null);
93         }
94
95 }