c3c8d98530a6902fb896bbb0a22e31739dfb8d39
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.remote.core.tests / src / org / eclipse / tracecompass / tmf / remote / core / tests / shell / CommandInputTest.java
1 /*******************************************************************************
2 * Copyright (c) 2015 Ericsson
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * Bernd Hufmann - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.tracecompass.tmf.remote.core.tests.shell;
14
15 import static org.junit.Assert.assertEquals;
16
17 import java.util.ArrayList;
18 import java.util.Arrays;
19 import java.util.List;
20
21 import org.eclipse.jdt.annotation.NonNull;
22 import org.eclipse.tracecompass.common.core.NonNullUtils;
23 import org.eclipse.tracecompass.internal.tmf.remote.core.shell.CommandInput;
24 import org.eclipse.tracecompass.tmf.remote.core.shell.ICommandInput;
25 import org.junit.Test;
26
27 /**
28 * Test suite for the {@link CommandInput} class
29 */
30 public class CommandInputTest {
31
32 private static final @NonNull String COMMAND = "my-command";
33 private static final String @NonNull [] CMD_INPUT = { "This", "are", "the", "params" };
34
35 /**
36 * Test suite for the {@link CommandInput#add(String)} and {@link CommandInput#addAll(List)}
37 */
38 @Test
39 public void testConstructorAndAdd() {
40 ICommandInput iunput = new CommandInput();
41 iunput.add(COMMAND);
42 List<String> params = Arrays.asList(CMD_INPUT);
43 iunput.addAll(NonNullUtils.checkNotNull(params));
44
45 List<String> expectedList = new ArrayList<>();
46 expectedList.add(COMMAND);
47 expectedList.addAll(params);
48 assertEquals(expectedList, iunput.getInput());
49 String expected = expectedInputString();
50 assertEquals(expected, iunput.toString());
51 }
52
53 /**
54 * Test suite to test null segment for {@link CommandInput#add(String)}
55 */
56 @Test
57 public void testNullSegment() {
58 ICommandInput input = new CommandInput();
59 input.add(null);
60 assertEquals(0, input.getInput().size());
61 }
62
63 private static String expectedInputString() {
64 StringBuilder builder = new StringBuilder();
65 builder.append(COMMAND).append((' '));
66 for (String segment : CMD_INPUT) {
67 builder.append(segment).append(' ');
68 }
69 return builder.toString().trim();
70 }
71
72 }
This page took 0.036078 seconds and 4 git commands to generate.