swtbot: move column in trace editor test
[deliverable/tracecompass.git] / org.eclipse.tracecompass.lttng2.control.ui.tests / stubs / org / eclipse / tracecompass / internal / lttng2 / control / stubs / shells / TestCommandShell.java
1 /**********************************************************************
2 * Copyright (c) 2012, 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 * Markus Schorn - Bug 448058: Use org.eclipse.remote in favor of RSE
12 **********************************************************************/
13 package org.eclipse.tracecompass.internal.lttng2.control.stubs.shells;
14
15 import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
16 import static org.eclipse.tracecompass.common.core.NonNullUtils.nullToEmptyString;
17
18 import java.util.ArrayList;
19 import java.util.Arrays;
20 import java.util.List;
21
22 import org.eclipse.core.commands.ExecutionException;
23 import org.eclipse.core.runtime.IProgressMonitor;
24 import org.eclipse.jdt.annotation.NonNull;
25 import org.eclipse.jdt.annotation.NonNullByDefault;
26 import org.eclipse.jdt.annotation.Nullable;
27 import org.eclipse.tracecompass.tmf.remote.core.shell.ICommandInput;
28 import org.eclipse.tracecompass.tmf.remote.core.shell.ICommandResult;
29 import org.eclipse.tracecompass.tmf.remote.core.shell.ICommandShell;
30
31 /**
32 * Command shell stub
33 */
34 public class TestCommandShell implements ICommandShell {
35
36 /** If the shell is connected */
37 protected boolean fIsConnected = false;
38
39 @Override
40 public void dispose() {
41 fIsConnected = false;
42 }
43
44 @Override
45 public ICommandResult executeCommand(ICommandInput command, IProgressMonitor monitor) throws ExecutionException {
46 if (fIsConnected) {
47 return new CommandResultStub(0, new String[0], new String[0]);
48 }
49 return new CommandResultStub(1, new String[0], new String[0]);
50 }
51
52 @Override
53 public ICommandInput createCommand() {
54 return new CommandInputStub();
55 }
56
57 /**
58 * Command Result Stub
59 */
60 @NonNullByDefault
61 protected class CommandResultStub implements ICommandResult {
62
63 private final int fResult;
64 private final List<String> fOutput;
65 private final List<String> fErrorOutput;
66 /**
67 * Constructor
68 *
69 * @param result
70 * The result of the command
71 * @param output
72 * The output, as an array of strings
73 * @param errorOutput
74 * THe error output as an array of strings
75 */
76 public CommandResultStub(int result, String[] output, String[] errorOutput) {
77 fResult = result;
78 fOutput = checkNotNull(Arrays.asList(output));
79 fErrorOutput = checkNotNull(Arrays.asList(errorOutput));
80 }
81
82 @Override
83 public int getResult() {
84 return fResult;
85 }
86
87 @Override
88 public List<String> getOutput() {
89 return fOutput;
90 }
91
92 @Override
93 public List<String> getErrorOutput() {
94 return fErrorOutput;
95 }
96
97 @Override
98 public String toString() {
99 StringBuffer ret = new StringBuffer();
100 ret.append("Error Output:\n"); //$NON-NLS-1$
101 for (String string : fErrorOutput) {
102 ret.append(string).append("\n"); //$NON-NLS-1$
103 }
104 ret.append("Return Value: "); //$NON-NLS-1$
105 ret.append(fResult);
106 ret.append("\n"); //$NON-NLS-1$
107 for (String string : fOutput) {
108 ret.append(string).append("\n"); //$NON-NLS-1$
109 }
110 return nullToEmptyString(ret.toString());
111 }
112 }
113
114 /**
115 * Command Input Stub
116 */
117 public class CommandInputStub implements ICommandInput {
118 private final List<String> fInput = new ArrayList<>();
119
120 @Override
121 @NonNull public List<String> getInput() {
122 return checkNotNull(fInput);
123 }
124
125 @Override
126 public void add(@Nullable String segment) {
127 if (segment != null) {
128 fInput.add(segment);
129 }
130 }
131
132 @Override
133 public void addAll(@Nullable List<String> segments) {
134 if (segments != null) {
135 fInput.addAll(segments);
136 }
137 }
138
139 @Override
140 public String toString() {
141 StringBuilder builder = new StringBuilder();
142 for (String segment : fInput) {
143 builder.append(segment).append(' ');
144 }
145 return nullToEmptyString(builder.toString().trim());
146 }
147 }
148 }
This page took 0.038408 seconds and 5 git commands to generate.