2 * Sone - GetSonesCommandTest.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.fcp;
20 import static java.util.Arrays.asList;
21 import static net.pterodactylus.sone.fcp.Verifiers.verifyAnswer;
22 import static net.pterodactylus.sone.fcp.Verifiers.verifySones;
23 import static net.pterodactylus.sone.freenet.fcp.Command.AccessType.DIRECT;
25 import java.util.Collections;
26 import java.util.List;
28 import net.pterodactylus.sone.data.Mocks;
29 import net.pterodactylus.sone.data.Sone;
30 import net.pterodactylus.sone.freenet.SimpleFieldSetBuilder;
31 import net.pterodactylus.sone.freenet.fcp.Command.Response;
33 import freenet.node.FSParseException;
34 import freenet.support.SimpleFieldSet;
36 import org.junit.Test;
39 * Unit test for {@link GetSonesCommand}.
41 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
43 public class GetSonesCommandTest {
45 private final Mocks mocks = new Mocks();
46 private final GetSonesCommand getSonesCommand = new GetSonesCommand(mocks.core);
47 private final List<Sone> mockedSones = prepareSones();
50 public void gettingAllSones() throws FSParseException {
51 SimpleFieldSet getSonesFieldSet = new SimpleFieldSetBuilder()
52 .put("Message", "GetSones")
54 Response response = getSonesCommand.execute(getSonesFieldSet, null, DIRECT);
55 verifyAnswer(response, "Sones");
56 verifySones(response.getReplyParameters(), "", mockedSones);
60 public void skipMoreSonesThanThereAre() throws FSParseException {
61 SimpleFieldSet getSonesFieldSet = new SimpleFieldSetBuilder()
62 .put("Message", "GetSones")
63 .put("StartSone", "5")
65 Response response = getSonesCommand.execute(getSonesFieldSet, null, DIRECT);
66 verifyAnswer(response, "Sones");
67 verifySones(response.getReplyParameters(), "", Collections.<Sone>emptyList());
71 public void gettingOnlyTwoSones() throws FSParseException {
72 SimpleFieldSet getSonesFieldSet = new SimpleFieldSetBuilder()
73 .put("Message", "GetSones")
76 Response response = getSonesCommand.execute(getSonesFieldSet, null, DIRECT);
77 verifyAnswer(response, "Sones");
78 verifySones(response.getReplyParameters(), "", mockedSones.subList(0, 2));
82 public void gettingAllSonesSkippingTheFirst() throws FSParseException {
83 SimpleFieldSet getSonesFieldSet = new SimpleFieldSetBuilder()
84 .put("Message", "GetSones")
85 .put("StartSone", "1")
87 Response response = getSonesCommand.execute(getSonesFieldSet, null, DIRECT);
88 verifyAnswer(response, "Sones");
89 verifySones(response.getReplyParameters(), "", mockedSones.subList(1, mockedSones.size()));
93 public void gettingOnlyOneSonesSkippingTheFirst() throws FSParseException {
94 SimpleFieldSet getSonesFieldSet = new SimpleFieldSetBuilder()
95 .put("Message", "GetSones")
97 .put("StartSone", "1")
99 Response response = getSonesCommand.execute(getSonesFieldSet, null, DIRECT);
100 verifyAnswer(response, "Sones");
101 verifySones(response.getReplyParameters(), "", mockedSones.subList(1, 2));
104 private List<Sone> prepareSones() {
105 Sone sone3 = mocks.mockSone("Sone3").withName("Sone3").withProfileName("S.", "O.", "Ne3").withTime(3000L).create();
106 Sone sone1 = mocks.mockSone("Sone1").withName("Sone1").withProfileName("S.", "O.", "Ne1").withTime(1000L).create();
107 Sone sone2 = mocks.mockSone("Sone2").withName("Sone2").withProfileName("S.", "O.", "Ne2").withTime(2000L).create();
108 return asList(sone1, sone2, sone3);