2 * Sone - SimpleFieldSetBuilderTest.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.contains;
21 import static net.pterodactylus.sone.Matchers.containsInAnyOrder;
22 import static org.hamcrest.MatcherAssert.assertThat;
23 import static org.hamcrest.Matchers.is;
25 import freenet.node.FSParseException;
26 import freenet.support.SimpleFieldSet;
28 import org.junit.Test;
31 * Unit test for {@link SimpleFieldSetBuilder}.
33 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
35 public class SimpleFieldSetBuilderTest {
37 private final SimpleFieldSetBuilder simpleFieldSetBuilder = new SimpleFieldSetBuilder();
40 public void creatingASimpleFieldSetWithAStringValue() {
41 SimpleFieldSet fieldSet = simpleFieldSetBuilder.put("Key", "Value").get();
42 assertThat(fieldSet.keyIterator(), contains("Key"));
43 assertThat(fieldSet.get("Key"), is("Value"));
47 public void creatingASimpleFieldSetWithAnIntValue() throws FSParseException {
48 SimpleFieldSet fieldSet = simpleFieldSetBuilder.put("Key", 17).get();
49 assertThat(fieldSet.keyIterator(), contains("Key"));
50 assertThat(fieldSet.getInt("Key"), is(17));
54 public void creatingASimpleFieldSetWithALongValue() throws FSParseException {
55 SimpleFieldSet fieldSet = simpleFieldSetBuilder.put("Key", 17L).get();
56 assertThat(fieldSet.keyIterator(), contains("Key"));
57 assertThat(fieldSet.getLong("Key"), is(17L));
61 public void creatingASimpleFieldSetWithAnotherFieldSet() throws FSParseException {
62 SimpleFieldSet originalFieldSet = new SimpleFieldSet(true);
63 originalFieldSet.putSingle("StringKey", "Value");
64 originalFieldSet.put("IntKey", 17);
65 originalFieldSet.put("LongKey", 17L);
66 SimpleFieldSet fieldSet = simpleFieldSetBuilder.put(originalFieldSet).get();
67 assertThat(fieldSet.keyIterator(), containsInAnyOrder("IntKey", "StringKey", "LongKey"));
68 assertThat(fieldSet.get("StringKey"), is("Value"));
69 assertThat(fieldSet.getInt("IntKey"), is(17));
70 assertThat(fieldSet.getLong("LongKey"), is(17L));