blob: 91ce5f5d2485988656f6e94d41ef5c28520983f1 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
/*******************************************************************************
* Copyright (c) 2011 SAP AG
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Lazar Kirchev, SAP AG - initial API and implementation
*******************************************************************************/
package org.eclipse.equinox.console.command.adapter;
import static org.junit.Assert.*;
import java.lang.reflect.Method;
import java.util.HashSet;
import java.util.Set;
import org.apache.felix.service.command.CommandSession;
import org.eclipse.osgi.framework.console.CommandInterpreter;
import org.eclipse.osgi.framework.console.CommandProvider;
import org.junit.Test;
import org.easymock.EasyMock;
public class CommandProviderAdapterTest {
@Test
public void testMain() throws Exception {
CommandProvider provider = new TestCommandProvider();
Method[] methods = TestCommandProvider.class.getMethods();
Set<Method> m = new HashSet<Method>();
for (Method method : methods) {
if (method.getName().startsWith("_")) {
m.add(method);
}
}
CommandProviderAdapter providerAdapter = new CommandProviderAdapter(provider, m.toArray(new Method[0]));
CommandSession session = EasyMock.createMock(CommandSession.class);
String result = (String) providerAdapter.main(session, new Object[] {"test"});
assertEquals("Result should be test", "test", result);
result = (String) providerAdapter.main(session, new Object[] {"echo", "hello"});
assertEquals("Result should be hello", "hello", result);
}
class TestCommandProvider implements CommandProvider {
public String _test(CommandInterpreter i) {
return "test";
}
public String _echo(CommandInterpreter i) {
return i.nextArgument();
}
public String getHelp() {
return "this is a test command provider";
}
}
}
|