Skip to content

Commit

Permalink
Format java files in o.e.equinox.console.tests
Browse files Browse the repository at this point in the history
This was achieved by running:
eclipse -consolelog -nosplash -application org.eclipse.jdt.core.JavaCodeFormatter \
  -config .settings/org.eclipse.jdt.core.prefs . -data `mktemp -d`

Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@st.com>
  • Loading branch information
Torbjorn-Svensson authored and akurtakov committed Oct 12, 2023
1 parent 4ace30c commit fd08ba6
Show file tree
Hide file tree
Showing 18 changed files with 216 additions and 190 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import org.junit.Test;

public class ActivatorTests {

private static final String SCOPE_PROPERTY_NAME = "osgi.command.scope";
private static final String FUNCTION_PROPERTY_NAME = "osgi.command.function";
private static final String EQUINOX_SCOPE = "equinox";
Expand All @@ -37,45 +37,47 @@ public void testGetCommandMethods() {
commandNames.add("_testMethod1");
commandNames.add("_testMethod2");
commandNames.add("_testMethod3");

Activator activator = new Activator();
CommandProvider command = new TestCommandProvider();
Method[] methods = activator.getCommandMethods(command);

assertEquals("Command methods not as expected", 3, methods.length);
for (Method method : methods) {
assertTrue("Command methods should not include " + method.getName(), commandNames.contains(method.getName()));
assertTrue("Command methods should not include " + method.getName(),
commandNames.contains(method.getName()));
}

Dictionary<String, Object> props = activator.getAttributes(methods);
assertTrue("Attributes should contain property " + SCOPE_PROPERTY_NAME + " with value " + EQUINOX_SCOPE, EQUINOX_SCOPE.equals(props.get(SCOPE_PROPERTY_NAME)));
String[] methodNames = (String[])props.get(FUNCTION_PROPERTY_NAME);
assertTrue("Attributes should contain property " + SCOPE_PROPERTY_NAME + " with value " + EQUINOX_SCOPE,
EQUINOX_SCOPE.equals(props.get(SCOPE_PROPERTY_NAME)));
String[] methodNames = (String[]) props.get(FUNCTION_PROPERTY_NAME);
assertEquals("Methods number not as expected", methods.length, methodNames.length);
for(int i = 0; i < methods.length; i++) {

for (int i = 0; i < methods.length; i++) {
assertEquals("Wrong method name", methods[i].getName().substring(1), methodNames[i]);
}
}

class TestCommandProvider implements CommandProvider {
public void _testMethod1(CommandInterpreter i) {

}

public void _testMethod2(CommandInterpreter i) {

}

public void _testMethod3(CommandInterpreter i) {

}

@Override
public String getHelp() {
// TODO Auto-generated method stub
return null;
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,27 +40,27 @@ public void testMain() throws Exception {
}
CommandProviderAdapter providerAdapter = new CommandProviderAdapter(provider, m.toArray(new Method[0]));
CommandSession session = mock(CommandSession.class);
String result = (String) providerAdapter.main(session, new Object[] {"test"});

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"});

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();
}

@Override
public String getHelp() {
return "this is a test command provider";
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@ public void testWrite() throws Exception {
byte[] res = byteOut.toByteArray();

Assert.assertNotNull("Bytes not written; result null", res);
Assert.assertFalse("Bytes not written; result empty", res.length == 0);
Assert.assertFalse("Bytes not written; result empty", res.length == 0);

for (int i = 0; i < DATA_LENGTH; i++) {
Assert.assertEquals("Wrong char read. Position " + i + ", expected " + data[i] + ", read " + res[i], data[i], res[i]);
}
for (int i = 0; i < DATA_LENGTH; i++) {
Assert.assertEquals("Wrong char read. Position " + i + ", expected " + data[i] + ", read " + res[i],
data[i], res[i]);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import org.junit.Assert;
import org.junit.Test;


public class HistoryHolderTests {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ public void testBuffer() throws Exception {
byte[] expected = new byte[] { 'a', 'b', 'c', 'd' };

Assert.assertTrue("Data not as expected: expected length " + expected.length + ", actual length " + data.length,
data.length == expected.length);
data.length == expected.length);

for (int i = 0; i < data.length; i++) {
Assert.assertEquals("Incorrect data read. Position " + i + ", expected " + expected[i] + ", read " + data[i], expected[i], data[i]);
Assert.assertEquals(
"Incorrect data read. Position " + i + ", expected " + expected[i] + ", read " + data[i],
expected[i], data[i]);
}

buffer.insert('a');
Expand Down Expand Up @@ -89,10 +91,12 @@ private void check(SimpleByteBuffer buffer, byte[] expected) throws Exception {
byte[] data = buffer.copyCurrentData();

Assert.assertTrue("Data not as expected: expected length " + expected.length + ", actual length " + data.length,
data.length == expected.length);
data.length == expected.length);

for (int i = 0; i < data.length; i++) {
Assert.assertEquals("Incorrect data read. Position " + i + ", expected " + expected[i] + ", read " + data[i], expected[i], data[i]);
Assert.assertEquals(
"Incorrect data read. Position " + i + ", expected " + expected[i] + ", read " + data[i],
expected[i], data[i]);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import org.junit.Test;

public class CommandLineParserTests {

private static final String PIPE_TEST_INPUT = "command1|comm";
private static final String CONSECUTIVE_COMMANDS_TEST_INPUT = "command1;comm";
private static final String ASSIGNMENT_TEST_INPUT = "var=val";
Expand All @@ -34,54 +34,55 @@ public class CommandLineParserTests {
private static final String LIST_TEST_INPUT = "[elem1, elem2, elem3]other";
private static final String COMMAND_ARGUMENTS_TEST_INPUT = "command argument1 argum";
private static final String COMMAND_NAME_TEST_INPUT = "com";
private static final String COMMENT_TEST_INPUT="command#comment";
private static final String COMMENT_TEST_INPUT = "command#comment";

@Test
public void testGetCurrentToken() {
String token;

token = CommandLineParser.getCurrentToken(PIPE_TEST_INPUT, PIPE_TEST_INPUT.length());
assertEquals("Pipe not parsed correctly", "comm", token);

token = CommandLineParser.getCurrentToken(CONSECUTIVE_COMMANDS_TEST_INPUT, CONSECUTIVE_COMMANDS_TEST_INPUT.length());

token = CommandLineParser.getCurrentToken(CONSECUTIVE_COMMANDS_TEST_INPUT,
CONSECUTIVE_COMMANDS_TEST_INPUT.length());
assertEquals("Consequtive commands not parsed correctly", "comm", token);

token = CommandLineParser.getCurrentToken(ASSIGNMENT_TEST_INPUT, ASSIGNMENT_TEST_INPUT.length());
assertEquals("Assignment not parsed correctly", "val", token);

token = CommandLineParser.getCurrentToken(START_CLOSURE_TEST_INPUT, START_CLOSURE_TEST_INPUT.length());
assertEquals("Start closure not parsed correctly", "comm", token);

token = CommandLineParser.getCurrentToken(END_CLOSURE_TEST_INPUT, END_CLOSURE_TEST_INPUT.length());
assertEquals("End closure not parsed correctly", "arg1", token);

token = CommandLineParser.getCurrentToken(START_MACRO_TEST_INPUT, START_MACRO_TEST_INPUT.length());
assertEquals("Start macro not parsed correctly", "macr", token);

token = CommandLineParser.getCurrentToken(END_MACRO_TEST_INPUT, END_MACRO_TEST_INPUT.length());
assertEquals("End macro not parsed correctly", "val", token);

token = CommandLineParser.getCurrentToken(VARIABLE_TEST_INPUT, VARIABLE_TEST_INPUT.length());
assertEquals("Variable name not parsed correctly", "VAR", token);

token = CommandLineParser.getCurrentToken(START_MAP_TEST_INPUT, START_MAP_TEST_INPUT.length());
assertNull("Start map not parsed correctly", token);

token = CommandLineParser.getCurrentToken(END_MAP_TEST_INPUT, END_MAP_TEST_INPUT.length());
assertEquals("End map not parsed correctly", "other", token);

token = CommandLineParser.getCurrentToken(START_LIST_TEST_INPUT, START_LIST_TEST_INPUT.length());
assertNull("Start list not parsed correctly", token);

token = CommandLineParser.getCurrentToken(LIST_TEST_INPUT, LIST_TEST_INPUT.length());
assertEquals("List not parsed correctly", "other", token);

token = CommandLineParser.getCurrentToken(COMMAND_ARGUMENTS_TEST_INPUT, COMMAND_ARGUMENTS_TEST_INPUT.length());
assertEquals("Command with arguments not parsed correctly", "argum", token);

token = CommandLineParser.getCurrentToken(COMMAND_NAME_TEST_INPUT, COMMAND_NAME_TEST_INPUT.length());
assertEquals("Command name not parsed correctly", "com", token);

token = CommandLineParser.getCurrentToken(COMMENT_TEST_INPUT, COMMENT_TEST_INPUT.length());
assertNull("Comment not parsed correctly", token);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import org.osgi.framework.ServiceReference;

public class CommandNamesCompleterTests {

private static final String COMMANDS = ".commands";

@Test
Expand All @@ -41,36 +41,38 @@ public void testGetCandidates() throws Exception {
commands.add("gogo:lb");
commands.add("gogo:echo");
commands.add("gogo:set");

CommandSession session = mock(CommandSession.class);
when(session.get(COMMANDS)).thenReturn(commands);

Filter filter = mock(Filter.class);

BundleContext context = mock(BundleContext.class);
when(context.createFilter("(objectClass=org.eclipse.equinox.console.commands.CommandsTracker)")).thenReturn(filter);
when(context.createFilter("(objectClass=org.eclipse.equinox.console.commands.CommandsTracker)"))
.thenReturn(filter);
context.addServiceListener(isA(ServiceListener.class), isA(String.class));
when(context.getServiceReferences("org.eclipse.equinox.console.commands.CommandsTracker", null)).thenReturn(new ServiceReference[]{});

when(context.getServiceReferences("org.eclipse.equinox.console.commands.CommandsTracker", null))
.thenReturn(new ServiceReference[] {});

CommandNamesCompleter completer = new CommandNamesCompleter(context, session);
Map<String, Integer> candidates;

candidates = completer.getCandidates("se", 2);
assertNotNull("Candidates null", candidates);
assertEquals("Candidates not as expected", 2, candidates.size());
assertNotNull("set should be in the resultset, but it is not", candidates.get("set"));
assertNotNull("setprop should be in the resultset, but it is not", candidates.get("setprop"));

candidates = completer.getCandidates("equinox:bun", "equinox:bun".length());
assertNotNull("Candidates null", candidates);
assertEquals("Candidates not as expected", 1, candidates.size());
assertNotNull("equinox:bundles should be in the resultset, but it is not", candidates.get("equinox:bundles"));

candidates = completer.getCandidates("ec", 2);
assertNotNull("Candidates null", candidates);
assertEquals("Candidates not as expected", 1, candidates.size());
assertNotNull("echo should be in the resultset, but it is not", candidates.get("echo"));

candidates = completer.getCandidates("head", 4);
assertNotNull("Candidates null", candidates);
assertEquals("Candidates not as expected", 0, candidates.size());
Expand Down
Loading

0 comments on commit fd08ba6

Please sign in to comment.