1 | // Copyright 2012 Georg-August-Universität Göttingen, Germany |
---|
2 | // |
---|
3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
---|
4 | // you may not use this file except in compliance with the License. |
---|
5 | // You may obtain a copy of the License at |
---|
6 | // |
---|
7 | // http://www.apache.org/licenses/LICENSE-2.0 |
---|
8 | // |
---|
9 | // Unless required by applicable law or agreed to in writing, software |
---|
10 | // distributed under the License is distributed on an "AS IS" BASIS, |
---|
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
12 | // See the License for the specific language governing permissions and |
---|
13 | // limitations under the License. |
---|
14 | |
---|
15 | package de.ugoe.cs.autoquest.test; |
---|
16 | |
---|
17 | import static org.junit.Assert.fail; |
---|
18 | |
---|
19 | import java.util.ArrayList; |
---|
20 | import java.util.List; |
---|
21 | |
---|
22 | import de.ugoe.cs.util.console.Command; |
---|
23 | |
---|
24 | /** |
---|
25 | * <p> |
---|
26 | * TODO comment |
---|
27 | * </p> |
---|
28 | * |
---|
29 | * @version $Revision: $ $Date: 29.08.2012$ |
---|
30 | * @author 2012, last modified by $Author: pharms$ |
---|
31 | */ |
---|
32 | public class CommandRunner { |
---|
33 | |
---|
34 | /** |
---|
35 | * <p> |
---|
36 | * prevent instantiation |
---|
37 | * </p> |
---|
38 | */ |
---|
39 | private CommandRunner() { |
---|
40 | // just to prevent instantiation |
---|
41 | } |
---|
42 | |
---|
43 | public static void runCommand(Class<? extends Command> commandType, Object... parameters) { |
---|
44 | Command command; |
---|
45 | try { |
---|
46 | command = commandType.newInstance(); |
---|
47 | } |
---|
48 | catch (Exception e) { |
---|
49 | fail("could not instantiate command"); |
---|
50 | return; // just added to prevent compiler warning. But the fail will already throw an |
---|
51 | // exception |
---|
52 | } |
---|
53 | |
---|
54 | List<Object> params = new ArrayList<Object>(); |
---|
55 | |
---|
56 | for (Object parameter : parameters) { |
---|
57 | params.add(parameter); |
---|
58 | } |
---|
59 | |
---|
60 | command.run(params); |
---|
61 | } |
---|
62 | } |
---|