c854530ce07ccbc222995f2794861e03c99e541a
1 /*******************************************************************************
2 * Copyright (c) 2015 Ericsson
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
10 * Bernd Hufmann - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.tmf
.remote
.core
.tests
.shell
;
15 import static org
.junit
.Assert
.assertEquals
;
17 import java
.util
.Arrays
;
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
;
25 * Test suite for the {@link CommandResult} class
27 public class CommandResultTest
{
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" };
34 * Test suite for the {@link CommandResult} class
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());
47 * Test suite for the {@link CommandResult} method
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());
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");
65 expected
.append("Return Value: ").append(result
).append("\n");
66 for (String string
: output
) {
67 expected
.append(string
).append("\n");
69 return expected
.toString();
This page took 0.035583 seconds and 4 git commands to generate.