c854530ce07ccbc222995f2794861e03c99e541a
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.remote.core.tests / src / org / eclipse / tracecompass / tmf / remote / core / tests / shell / CommandResultTest.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.Arrays;
18
19 import org.eclipse.jdt.annotation.NonNull;
20 import org.eclipse.tracecompass.internal.tmf.remote.core.shell.CommandResult;
21 import org.eclipse.tracecompass.tmf.remote.core.shell.ICommandResult;
22 import org.junit.Test;
23
24 /**
25 * Test suite for the {@link CommandResult} class
26 */
27 public class CommandResultTest {
28
29 private static final @NonNull String[] CMD_OUTPUT = { "This", "is", "the", "output" };
30 private static final @NonNull String[] CMD_NO_ERROR_OUTPUT = {};
31 private static final @NonNull String[] CMD_ERROR_OUTPUT = { "This", "is", "the", "error", "output" };
32
33 /**
34 * Test suite for the {@link CommandResult} class
35 */
36 @Test
37 public void testConstructorNoError() {
38 ICommandResult result = new CommandResult(0, CMD_OUTPUT, CMD_NO_ERROR_OUTPUT);
39 assertEquals(0, result.getResult());
40 assertEquals(Arrays.asList(CMD_OUTPUT), result.getOutput());
41 assertEquals(Arrays.asList(CMD_NO_ERROR_OUTPUT), result.getErrorOutput());
42 String expected = expectedResultString(0, CMD_OUTPUT, CMD_NO_ERROR_OUTPUT);
43 assertEquals(expected, result.toString());
44 }
45
46 /**
47 * Test suite for the {@link CommandResult} method
48 */
49 @Test
50 public void testConstructorError() {
51 ICommandResult result = new CommandResult(1, CMD_OUTPUT, CMD_ERROR_OUTPUT);
52 assertEquals(1, result.getResult());
53 assertEquals(Arrays.asList(CMD_OUTPUT), result.getOutput());
54 assertEquals(Arrays.asList(CMD_ERROR_OUTPUT), result.getErrorOutput());
55 String expected = expectedResultString(1, CMD_OUTPUT, CMD_ERROR_OUTPUT);
56 assertEquals(expected, result.toString());
57 }
58
59 private static String expectedResultString(int result, String output[], String[] errorOutput) {
60 StringBuffer expected = new StringBuffer();
61 expected.append("Error Output:\n");
62 for (String string : errorOutput) {
63 expected.append(string).append("\n");
64 }
65 expected.append("Return Value: ").append(result).append("\n");
66 for (String string : output) {
67 expected.append(string).append("\n");
68 }
69 return expected.toString();
70 }
71
72 }
This page took 0.049701 seconds and 4 git commands to generate.