5
5
import java .util .HashMap ;
6
6
import java .util .Map ;
7
7
8
+ import com .devonfw .tools .ide .commandlet .Commandlet ;
9
+ import com .devonfw .tools .ide .commandlet .CommandletManager ;
10
+ import com .devonfw .tools .ide .commandlet .TestCommandletManager ;
8
11
import com .devonfw .tools .ide .common .SystemPath ;
9
12
import com .devonfw .tools .ide .environment .AbstractEnvironmentVariables ;
10
13
import com .devonfw .tools .ide .environment .EnvironmentVariables ;
@@ -37,14 +40,15 @@ public class AbstractIdeTestContext extends AbstractIdeContext {
37
40
38
41
private ProcessContext mockContext ;
39
42
43
+ private TestCommandletManager testCommandletManager ;
44
+
40
45
/**
41
46
* The constructor.
42
47
*
43
48
* @param logger the {@link IdeLogger}.
44
49
* @param workingDirectory the optional {@link Path} to current working directory.
45
- * @param answers the automatic answers simulating a user in test.
46
50
*/
47
- public AbstractIdeTestContext (IdeStartContextImpl logger , Path workingDirectory , String ... answers ) {
51
+ public AbstractIdeTestContext (IdeStartContextImpl logger , Path workingDirectory ) {
48
52
49
53
super (logger , workingDirectory );
50
54
this .answers = new String [0 ];
@@ -83,6 +87,10 @@ protected String readLine() {
83
87
return this .answers [this .answerIndex ++];
84
88
}
85
89
90
+ /**
91
+ * @param answers the answers for interactive questions in order (e.g. if "yes" is given as first answer, this will be used to answer the first
92
+ * question).
93
+ */
86
94
public void setAnswers (String ... answers ) {
87
95
requireMutable ();
88
96
this .answers = answers ;
@@ -103,9 +111,7 @@ public IdeProgressBar prepareProgressBar(String taskName, long size) {
103
111
IdeProgressBarTestImpl progressBar = new IdeProgressBarTestImpl (taskName , size );
104
112
IdeProgressBarTestImpl duplicate = this .progressBarMap .put (taskName , progressBar );
105
113
// If we have multiple downloads or unpacking, we may have an existing "Downloading" or "Unpacking" key
106
- if ((!taskName .equals ("Downloading" )) && (!taskName .equals ("Unpacking" ))) {
107
- assert duplicate == null ;
108
- }
114
+ assert (taskName .equals ("Downloading" )) || (taskName .equals ("Unpacking" )) || duplicate == null ;
109
115
return progressBar ;
110
116
}
111
117
@@ -199,4 +205,44 @@ public void setDefaultToolRepository(ToolRepository defaultToolRepository) {
199
205
200
206
this .defaultToolRepository = defaultToolRepository ;
201
207
}
208
+
209
+ /**
210
+ * @param settingsPath the new value of {@link #getSettingsPath()}.
211
+ */
212
+ public void setSettingsPath (Path settingsPath ) {
213
+
214
+ this .settingsPath = settingsPath ;
215
+ }
216
+
217
+ /**
218
+ * @param pluginsPath the new value of {@link #getPluginsPath()}.
219
+ */
220
+ public void setPluginsPath (Path pluginsPath ) {
221
+
222
+ this .pluginsPath = pluginsPath ;
223
+ }
224
+
225
+ /**
226
+ * @param commandletManager the new value of {@link #getCommandletManager()}.
227
+ */
228
+ public void setCommandletManager (CommandletManager commandletManager ) {
229
+ if (commandletManager instanceof TestCommandletManager tcm ) {
230
+ this .testCommandletManager = tcm ;
231
+ } else {
232
+ this .testCommandletManager = null ;
233
+ }
234
+ this .commandletManager = commandletManager ;
235
+ }
236
+
237
+ /**
238
+ * @param commandlet the {@link Commandlet} to add to {@link #getCommandletManager()} for testing.
239
+ */
240
+ public void addCommandlet (Commandlet commandlet ) {
241
+
242
+ if (this .testCommandletManager == null ) {
243
+ setCommandletManager (new TestCommandletManager (this ));
244
+ }
245
+ this .testCommandletManager .add (commandlet );
246
+ }
247
+
202
248
}
0 commit comments