Commit | Line | Data |
---|---|---|
1d6a2139 BH |
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 | ||
aa353506 AM |
29 | private static final @NonNull String @NonNull [] CMD_OUTPUT = { "This", "is", "the", "output" }; |
30 | private static final @NonNull String @NonNull [] CMD_NO_ERROR_OUTPUT = {}; | |
31 | private static final @NonNull String @NonNull [] CMD_ERROR_OUTPUT = { "This", "is", "the", "error", "output" }; | |
1d6a2139 BH |
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 | } |