Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Kurtakov2021-12-01 12:44:06 +0000
committerAlexander Kurtakov2021-12-01 14:25:13 +0000
commitdd529e68cba91392c9ea6e54ef8c1c4926b00eb3 (patch)
treee9983fe4143c7eef154bc04f8c26aa08dcbe278a
parent457dd2f67cc42e0ff514dfa302ad77f8cd3e598b (diff)
downloadrt.equinox.bundles-dd529e68cba91392c9ea6e54ef8c1c4926b00eb3.tar.gz
rt.equinox.bundles-dd529e68cba91392c9ea6e54ef8c1c4926b00eb3.tar.xz
rt.equinox.bundles-dd529e68cba91392c9ea6e54ef8c1c4926b00eb3.zip
Enable save actions to automate a bit tedious tasks. Change-Id: Iac272434ed72a70b8b3a3b2de614ada88d7ee1c3 Signed-off-by: Alexander Kurtakov <akurtako@redhat.com> Reviewed-on: https://git.eclipse.org/r/c/equinox/rt.equinox.bundles/+/188407 Tested-by: Equinox Bot <equinox-bot@eclipse.org>
-rw-r--r--bundles/org.eclipse.equinox.console.tests/.settings/org.eclipse.jdt.ui.prefs140
-rwxr-xr-xbundles/org.eclipse.equinox.console.tests/META-INF/MANIFEST.MF8
-rw-r--r--bundles/org.eclipse.equinox.console.tests/pom.xml2
-rwxr-xr-xbundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/command/adapter/CommandProviderAdapterTest.java6
-rwxr-xr-xbundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/completion/CommandNamesCompleterTests.java22
-rwxr-xr-xbundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/completion/CompletionHandlerTests.java26
-rwxr-xr-xbundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/completion/VariableNamesCompleterTests.java12
-rwxr-xr-xbundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/supportability/ConsoleInputScannerTests.java24
-rwxr-xr-xbundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetCommandTests.java32
-rwxr-xr-xbundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetCommandWithConfigAdminTests.java102
-rwxr-xr-xbundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetConnectionTests.java44
-rwxr-xr-xbundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetDisconnectionTest.java34
-rwxr-xr-xbundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetInputHandlerTests.java10
-rwxr-xr-xbundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetInputScannerTests.java69
-rwxr-xr-xbundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetServerTests.java60
15 files changed, 327 insertions, 264 deletions
diff --git a/bundles/org.eclipse.equinox.console.tests/.settings/org.eclipse.jdt.ui.prefs b/bundles/org.eclipse.equinox.console.tests/.settings/org.eclipse.jdt.ui.prefs
index 9e213f625..52baf4381 100644
--- a/bundles/org.eclipse.equinox.console.tests/.settings/org.eclipse.jdt.ui.prefs
+++ b/bundles/org.eclipse.equinox.console.tests/.settings/org.eclipse.jdt.ui.prefs
@@ -1,3 +1,143 @@
+cleanup_settings_version=2
eclipse.preferences.version=1
+editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true
formatter_profile=org.eclipse.jdt.ui.default.eclipse_profile
formatter_settings_version=21
+sp_cleanup.add_all=false
+sp_cleanup.add_default_serial_version_id=true
+sp_cleanup.add_generated_serial_version_id=false
+sp_cleanup.add_missing_annotations=true
+sp_cleanup.add_missing_deprecated_annotations=true
+sp_cleanup.add_missing_methods=false
+sp_cleanup.add_missing_nls_tags=false
+sp_cleanup.add_missing_override_annotations=true
+sp_cleanup.add_missing_override_annotations_interface_methods=true
+sp_cleanup.add_serial_version_id=false
+sp_cleanup.always_use_blocks=true
+sp_cleanup.always_use_parentheses_in_expressions=false
+sp_cleanup.always_use_this_for_non_static_field_access=false
+sp_cleanup.always_use_this_for_non_static_method_access=false
+sp_cleanup.array_with_curly=false
+sp_cleanup.arrays_fill=false
+sp_cleanup.bitwise_conditional_expression=false
+sp_cleanup.boolean_literal=false
+sp_cleanup.boolean_value_rather_than_comparison=false
+sp_cleanup.break_loop=false
+sp_cleanup.collection_cloning=false
+sp_cleanup.comparing_on_criteria=false
+sp_cleanup.comparison_statement=false
+sp_cleanup.controlflow_merge=false
+sp_cleanup.convert_functional_interfaces=false
+sp_cleanup.convert_to_enhanced_for_loop=false
+sp_cleanup.convert_to_enhanced_for_loop_if_loop_var_used=false
+sp_cleanup.convert_to_switch_expressions=false
+sp_cleanup.correct_indentation=false
+sp_cleanup.do_while_rather_than_while=false
+sp_cleanup.double_negation=false
+sp_cleanup.else_if=false
+sp_cleanup.embedded_if=false
+sp_cleanup.evaluate_nullable=false
+sp_cleanup.extract_increment=false
+sp_cleanup.format_source_code=true
+sp_cleanup.format_source_code_changes_only=true
+sp_cleanup.hash=false
+sp_cleanup.if_condition=false
+sp_cleanup.insert_inferred_type_arguments=false
+sp_cleanup.instanceof=false
+sp_cleanup.instanceof_keyword=false
+sp_cleanup.invert_equals=false
+sp_cleanup.join=false
+sp_cleanup.lazy_logical_operator=false
+sp_cleanup.make_local_variable_final=true
+sp_cleanup.make_parameters_final=false
+sp_cleanup.make_private_fields_final=true
+sp_cleanup.make_type_abstract_if_missing_method=false
+sp_cleanup.make_variable_declarations_final=false
+sp_cleanup.map_cloning=false
+sp_cleanup.merge_conditional_blocks=false
+sp_cleanup.multi_catch=false
+sp_cleanup.never_use_blocks=false
+sp_cleanup.never_use_parentheses_in_expressions=true
+sp_cleanup.no_string_creation=false
+sp_cleanup.no_super=false
+sp_cleanup.number_suffix=false
+sp_cleanup.objects_equals=false
+sp_cleanup.on_save_use_additional_actions=true
+sp_cleanup.one_if_rather_than_duplicate_blocks_that_fall_through=false
+sp_cleanup.operand_factorization=false
+sp_cleanup.organize_imports=true
+sp_cleanup.overridden_assignment=false
+sp_cleanup.plain_replacement=false
+sp_cleanup.precompile_regex=false
+sp_cleanup.primitive_comparison=false
+sp_cleanup.primitive_parsing=false
+sp_cleanup.primitive_rather_than_wrapper=false
+sp_cleanup.primitive_serialization=false
+sp_cleanup.pull_out_if_from_if_else=false
+sp_cleanup.pull_up_assignment=false
+sp_cleanup.push_down_negation=false
+sp_cleanup.qualify_static_field_accesses_with_declaring_class=false
+sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true
+sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true
+sp_cleanup.qualify_static_member_accesses_with_declaring_class=false
+sp_cleanup.qualify_static_method_accesses_with_declaring_class=false
+sp_cleanup.reduce_indentation=false
+sp_cleanup.redundant_comparator=false
+sp_cleanup.redundant_falling_through_block_end=false
+sp_cleanup.remove_private_constructors=true
+sp_cleanup.remove_redundant_modifiers=false
+sp_cleanup.remove_redundant_semicolons=false
+sp_cleanup.remove_redundant_type_arguments=false
+sp_cleanup.remove_trailing_whitespaces=false
+sp_cleanup.remove_trailing_whitespaces_all=true
+sp_cleanup.remove_trailing_whitespaces_ignore_empty=false
+sp_cleanup.remove_unnecessary_array_creation=false
+sp_cleanup.remove_unnecessary_casts=true
+sp_cleanup.remove_unnecessary_nls_tags=false
+sp_cleanup.remove_unused_imports=false
+sp_cleanup.remove_unused_local_variables=false
+sp_cleanup.remove_unused_private_fields=true
+sp_cleanup.remove_unused_private_members=false
+sp_cleanup.remove_unused_private_methods=true
+sp_cleanup.remove_unused_private_types=true
+sp_cleanup.return_expression=false
+sp_cleanup.simplify_lambda_expression_and_method_ref=false
+sp_cleanup.single_used_field=false
+sp_cleanup.sort_members=false
+sp_cleanup.sort_members_all=false
+sp_cleanup.standard_comparison=false
+sp_cleanup.static_inner_class=false
+sp_cleanup.strictly_equal_or_different=false
+sp_cleanup.stringbuffer_to_stringbuilder=false
+sp_cleanup.stringbuilder=false
+sp_cleanup.stringbuilder_for_local_vars=true
+sp_cleanup.stringconcat_to_textblock=false
+sp_cleanup.substring=false
+sp_cleanup.switch=false
+sp_cleanup.system_property=false
+sp_cleanup.system_property_boolean=false
+sp_cleanup.system_property_file_encoding=false
+sp_cleanup.system_property_file_separator=false
+sp_cleanup.system_property_line_separator=false
+sp_cleanup.system_property_path_separator=false
+sp_cleanup.ternary_operator=false
+sp_cleanup.try_with_resource=false
+sp_cleanup.unlooped_while=false
+sp_cleanup.unreachable_block=false
+sp_cleanup.use_anonymous_class_creation=false
+sp_cleanup.use_autoboxing=false
+sp_cleanup.use_blocks=false
+sp_cleanup.use_blocks_only_for_return_and_throw=false
+sp_cleanup.use_directly_map_method=false
+sp_cleanup.use_lambda=true
+sp_cleanup.use_parentheses_in_expressions=false
+sp_cleanup.use_string_is_blank=false
+sp_cleanup.use_this_for_non_static_field_access=false
+sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true
+sp_cleanup.use_this_for_non_static_method_access=false
+sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true
+sp_cleanup.use_unboxing=false
+sp_cleanup.use_var=false
+sp_cleanup.useless_continue=false
+sp_cleanup.useless_return=false
+sp_cleanup.valueof_rather_than_instantiation=false
diff --git a/bundles/org.eclipse.equinox.console.tests/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.console.tests/META-INF/MANIFEST.MF
index 9c465f3cc..965fb32c0 100755
--- a/bundles/org.eclipse.equinox.console.tests/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.equinox.console.tests/META-INF/MANIFEST.MF
@@ -3,11 +3,13 @@ Bundle-ManifestVersion: 2
Bundle-Name: Console tests
Bundle-Vendor: Eclipse.org - Equinox
Bundle-SymbolicName: org.eclipse.equinox.console.tests
-Bundle-Version: 1.1.100.qualifier
+Bundle-Version: 1.2.0.qualifier
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Import-Package: org.apache.sshd.client.future,
- org.easymock;version="2.4.0",
- org.junit;version="4.8.1"
+ org.junit;version="4.8.1",
+ org.mockito,
+ org.mockito.stubbing,
+ org.mockito.invocation
Fragment-Host: org.eclipse.equinox.console
Automatic-Module-Name: org.eclipse.equinox.console.tests
diff --git a/bundles/org.eclipse.equinox.console.tests/pom.xml b/bundles/org.eclipse.equinox.console.tests/pom.xml
index 7b546d332..3d8a3d41c 100644
--- a/bundles/org.eclipse.equinox.console.tests/pom.xml
+++ b/bundles/org.eclipse.equinox.console.tests/pom.xml
@@ -19,7 +19,7 @@
</parent>
<groupId>org.eclipse.equinox</groupId>
<artifactId>org.eclipse.equinox.console.tests</artifactId>
- <version>1.1.100-SNAPSHOT</version>
+ <version>1.2.0-SNAPSHOT</version>
<packaging>eclipse-test-plugin</packaging>
<properties>
<skipTests>true</skipTests>
diff --git a/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/command/adapter/CommandProviderAdapterTest.java b/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/command/adapter/CommandProviderAdapterTest.java
index e0928c959..aae006de7 100755
--- a/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/command/adapter/CommandProviderAdapterTest.java
+++ b/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/command/adapter/CommandProviderAdapterTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011, 2017 SAP AG and others.
+ * Copyright (c) 2011, 2021 SAP AG and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -15,6 +15,7 @@
package org.eclipse.equinox.console.command.adapter;
import static org.junit.Assert.*;
+import static org.mockito.Mockito.mock;
import java.lang.reflect.Method;
import java.util.HashSet;
@@ -24,7 +25,6 @@ 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 {
@@ -39,7 +39,7 @@ public class CommandProviderAdapterTest {
}
}
CommandProviderAdapter providerAdapter = new CommandProviderAdapter(provider, m.toArray(new Method[0]));
- CommandSession session = EasyMock.createMock(CommandSession.class);
+ CommandSession session = mock(CommandSession.class);
String result = (String) providerAdapter.main(session, new Object[] {"test"});
assertEquals("Result should be test", "test", result);
diff --git a/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/completion/CommandNamesCompleterTests.java b/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/completion/CommandNamesCompleterTests.java
index 28b0cb0c0..e8041a4c3 100755
--- a/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/completion/CommandNamesCompleterTests.java
+++ b/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/completion/CommandNamesCompleterTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011, 2017 SAP AG and others.
+ * Copyright (c) 2011, 2021 SAP AG and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -15,7 +15,7 @@
package org.eclipse.equinox.console.completion;
import static org.junit.Assert.*;
-import static org.easymock.EasyMock.*;
+import static org.mockito.Mockito.*;
import java.util.HashSet;
import java.util.Map;
@@ -42,19 +42,15 @@ public class CommandNamesCompleterTests {
commands.add("gogo:echo");
commands.add("gogo:set");
- CommandSession session = createMock(CommandSession.class);
- expect(session.get(COMMANDS)).andReturn(commands).times(4);
- replay(session);
+ CommandSession session = mock(CommandSession.class);
+ when(session.get(COMMANDS)).thenReturn(commands);
- Filter filter = createMock(Filter.class);
- replay(filter);
+ Filter filter = mock(Filter.class);
- BundleContext context = createMock(BundleContext.class);
-// expect(context.createFilter(String.format("(&(%s=*)(%s=*))", CommandProcessor.COMMAND_SCOPE, CommandProcessor.COMMAND_FUNCTION))).andReturn(filter);
- expect(context.createFilter("(objectClass=org.eclipse.equinox.console.commands.CommandsTracker)")).andReturn(filter);
+ BundleContext context = mock(BundleContext.class);
+ when(context.createFilter("(objectClass=org.eclipse.equinox.console.commands.CommandsTracker)")).thenReturn(filter);
context.addServiceListener(isA(ServiceListener.class), isA(String.class));
- expect(context.getServiceReferences("org.eclipse.equinox.console.commands.CommandsTracker", null)).andReturn(new ServiceReference[]{});
- replay(context);
+ when(context.getServiceReferences("org.eclipse.equinox.console.commands.CommandsTracker", null)).thenReturn(new ServiceReference[]{});
CommandNamesCompleter completer = new CommandNamesCompleter(context, session);
Map<String, Integer> candidates;
@@ -78,8 +74,6 @@ public class CommandNamesCompleterTests {
candidates = completer.getCandidates("head", 4);
assertNotNull("Candidates null", candidates);
assertEquals("Candidates not as expected", 0, candidates.size());
-
- verify(session);
}
}
diff --git a/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/completion/CompletionHandlerTests.java b/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/completion/CompletionHandlerTests.java
index 9c610b5dc..9c6ef003c 100755
--- a/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/completion/CompletionHandlerTests.java
+++ b/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/completion/CompletionHandlerTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011, 2017 SAP AG and others.
+ * Copyright (c) 2011, 2021 SAP AG and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -15,7 +15,7 @@
package org.eclipse.equinox.console.completion;
import static org.junit.Assert.*;
-import static org.easymock.EasyMock.*;
+import static org.mockito.Mockito.*;
import java.io.File;
import java.io.FileOutputStream;
@@ -64,16 +64,13 @@ public class CompletionHandlerTests {
@Test
public void testGetCandidates() throws Exception {
- Filter filter = createMock(Filter.class);
- replay(filter);
-
- BundleContext context = createMock(BundleContext.class);
- expect(context.getServiceReferences(Completer.class.getName(), null)).andReturn(null).anyTimes();
- expect(context.createFilter("(objectClass=org.eclipse.equinox.console.commands.CommandsTracker)")).andReturn(filter).anyTimes();
+ Filter filter = mock(Filter.class);
+
+ BundleContext context = mock(BundleContext.class);
+ when(context.getServiceReferences(Completer.class.getName(), null)).thenReturn(null);
+ when(context.createFilter("(objectClass=org.eclipse.equinox.console.commands.CommandsTracker)")).thenReturn(filter);
context.addServiceListener(isA(ServiceListener.class), isA(String.class));
- expectLastCall().anyTimes();
- expect(context.getServiceReferences("org.eclipse.equinox.console.commands.CommandsTracker", null)).andReturn(new ServiceReference[]{}).anyTimes();
- replay(context);
+ when(context.getServiceReferences("org.eclipse.equinox.console.commands.CommandsTracker", null)).thenReturn(new ServiceReference[]{});
Set<String> variables = new HashSet<>();
variables.add("SCOPE");
@@ -89,10 +86,9 @@ public class CompletionHandlerTests {
commands.add("gogo:echo");
commands.add("gogo:set");
- CommandSession session = createMock(CommandSession.class);
- expect(session.get(null)).andReturn(variables).anyTimes();
- expect(session.get(COMMANDS)).andReturn(commands).anyTimes();
- replay(session);
+ CommandSession session = mock(CommandSession.class);
+ when(session.get(null)).thenReturn(variables);
+ when(session.get(COMMANDS)).thenReturn(commands);
CompletionHandler completer = new CompletionHandler(context, session);
Map<String, Integer> candidates;
diff --git a/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/completion/VariableNamesCompleterTests.java b/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/completion/VariableNamesCompleterTests.java
index 4875877bc..93ee49fe1 100755
--- a/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/completion/VariableNamesCompleterTests.java
+++ b/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/completion/VariableNamesCompleterTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011, 2017 SAP AG and others.
+ * Copyright (c) 2011, 2021 SAP AG and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -14,7 +14,7 @@
package org.eclipse.equinox.console.completion;
-import static org.easymock.EasyMock.*;
+import static org.mockito.Mockito.*;
import static org.junit.Assert.*;
import java.util.HashSet;
@@ -34,9 +34,8 @@ public class VariableNamesCompleterTests {
variables.add("ECHO_ON");
variables.add("ECHO");
- CommandSession session = createMock(CommandSession.class);
- expect(session.get(null)).andReturn(variables).times(3);
- replay(session);
+ CommandSession session = mock(CommandSession.class);
+ when(session.get(null)).thenReturn(variables);
VariableNamesCompleter completer = new VariableNamesCompleter(session);
Map<String, Integer> candidates;
@@ -55,8 +54,5 @@ public class VariableNamesCompleterTests {
candidates = completer.getCandidates("AB", 2);
assertNotNull("Candidates null", candidates);
assertEquals("Candidates not as expected", 0, candidates.size());
-
- verify(session);
}
-
}
diff --git a/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/supportability/ConsoleInputScannerTests.java b/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/supportability/ConsoleInputScannerTests.java
index 30203582c..e87b92e09 100755
--- a/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/supportability/ConsoleInputScannerTests.java
+++ b/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/supportability/ConsoleInputScannerTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011, 2017 SAP AG and others.
+ * Copyright (c) 2011, 2021 SAP AG and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -14,10 +14,7 @@
package org.eclipse.equinox.console.supportability;
-import static org.easymock.EasyMock.isA;
-import static org.easymock.EasyMock.createMock;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.replay;
+import static org.mockito.Mockito.*;
import org.apache.felix.service.command.CommandSession;
import org.eclipse.equinox.console.common.ConsoleInputScanner;
@@ -187,15 +184,13 @@ public class ConsoleInputScannerTests {
res = byteOut.toString();
Assert.assertTrue("Error processing Ins; expected las, actual " + res.substring(res.length() - 4), res.endsWith("lasa"));
- Filter filter = createMock(Filter.class);
- replay(filter);
+ Filter filter = mock(Filter.class);
- BundleContext context = createMock(BundleContext.class);
- expect(context.getServiceReferences(Completer.class.getName(), null)).andReturn(null).anyTimes();
- expect(context.createFilter("(objectClass=org.eclipse.equinox.console.commands.CommandsTracker)")).andReturn(filter);
+ BundleContext context = mock(BundleContext.class);
+ when(context.getServiceReferences(Completer.class.getName(), null)).thenReturn(null);
+ when(context.createFilter("(objectClass=org.eclipse.equinox.console.commands.CommandsTracker)")).thenReturn(filter);
context.addServiceListener(isA(ServiceListener.class), isA(String.class));
- expect(context.getServiceReferences("org.eclipse.equinox.console.commands.CommandsTracker", null)).andReturn(new ServiceReference[]{});
- replay(context);
+ when(context.getServiceReferences("org.eclipse.equinox.console.commands.CommandsTracker", null)).thenReturn(new ServiceReference[]{});
Set<String> commands = new HashSet<>();
commands.add("equinox:bundles");
@@ -204,9 +199,8 @@ public class ConsoleInputScannerTests {
commands.add("gogo:bundlelevel");
commands.add("equinox:headers");
- CommandSession session = createMock(CommandSession.class);
- expect(session.get(COMMANDS)).andReturn(commands).anyTimes();
- replay(session);
+ CommandSession session = mock(CommandSession.class);
+ when(session.get(COMMANDS)).thenReturn(commands);
scanner.setContext(context);
scanner.setSession(session);
diff --git a/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetCommandTests.java b/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetCommandTests.java
index 21fc84ade..d02ec2a1c 100755
--- a/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetCommandTests.java
+++ b/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetCommandTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011, 2012 SAP AG
+ * Copyright (c) 2011, 2021 SAP AG and others
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -14,6 +14,10 @@
package org.eclipse.equinox.console.telnet;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
import java.io.OutputStream;
import java.io.PrintStream;
import java.net.Socket;
@@ -21,12 +25,10 @@ import java.util.Dictionary;
import org.apache.felix.service.command.CommandProcessor;
import org.apache.felix.service.command.CommandSession;
-import org.easymock.EasyMock;
import org.eclipse.equinox.console.common.ConsoleInputStream;
import org.junit.Test;
import org.osgi.framework.BundleContext;
-
public class TelnetCommandTests {
private static final int TEST_CONTENT = 100;
@@ -40,23 +42,16 @@ public class TelnetCommandTests {
@Test
public void testTelnetCommand() throws Exception {
- try (CommandSession session = EasyMock.createMock(CommandSession.class)) {
- session.put((String)EasyMock.anyObject(), EasyMock.anyObject());
- EasyMock.expectLastCall().times(3);
- EasyMock.expect(session.execute((String)EasyMock.anyObject())).andReturn(new Object());
- session.close();
- EasyMock.expectLastCall();
- EasyMock.replay(session);
+ try (CommandSession session = mock(CommandSession.class)) {
+ when(session.execute(any(String.class))).thenReturn(new Object());
- CommandProcessor processor = EasyMock.createMock(CommandProcessor.class);
- EasyMock.expect(processor.createSession((ConsoleInputStream)EasyMock.anyObject(), (PrintStream)EasyMock.anyObject(), (PrintStream)EasyMock.anyObject())).andReturn(session);
- EasyMock.replay(processor);
+ CommandProcessor processor = mock(CommandProcessor.class);
+ when(processor.createSession(any(ConsoleInputStream.class), any(PrintStream.class), any(PrintStream.class))).thenReturn(session);
- BundleContext context = EasyMock.createMock(BundleContext.class);
- EasyMock.expect(context.getProperty(USE_CONFIG_ADMIN_PROP)).andReturn(FALSE);
- EasyMock.expect(context.getProperty(TELNET_PORT_PROP_NAME)).andReturn(Integer.toString(TELNET_PORT));
- EasyMock.expect(context.registerService((String)EasyMock.anyObject(), EasyMock.anyObject(), (Dictionary<String, ?>)EasyMock.anyObject())).andReturn(null);
- EasyMock.replay(context);
+ BundleContext context = mock(BundleContext.class);
+ when(context.getProperty(USE_CONFIG_ADMIN_PROP)).thenReturn(FALSE);
+ when(context.getProperty(TELNET_PORT_PROP_NAME)).thenReturn(Integer.toString(TELNET_PORT));
+ when(context.registerService(any(String.class), any(), any(Dictionary.class))).thenReturn(null);
TelnetCommand command = new TelnetCommand(processor, context);
command.startService();
@@ -76,7 +71,6 @@ public class TelnetCommandTests {
} finally {
command.telnet(new String[] {STOP_COMMAND});
}
- EasyMock.verify(context);
}
}
}
diff --git a/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetCommandWithConfigAdminTests.java b/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetCommandWithConfigAdminTests.java
index 1d71aea88..c8443f880 100755
--- a/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetCommandWithConfigAdminTests.java
+++ b/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetCommandWithConfigAdminTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011, 2017 SAP AG and others.
+ * Copyright (c) 2011, 2021 SAP AG and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -14,6 +14,9 @@
package org.eclipse.equinox.console.telnet;
import static org.junit.Assert.fail;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
import java.io.IOException;
import java.io.OutputStream;
@@ -24,7 +27,6 @@ import java.util.Hashtable;
import org.apache.felix.service.command.CommandProcessor;
import org.apache.felix.service.command.CommandSession;
-import org.easymock.EasyMock;
import org.eclipse.equinox.console.common.ConsoleInputStream;
import org.junit.Test;
import org.osgi.framework.BundleContext;
@@ -45,42 +47,25 @@ public class TelnetCommandWithConfigAdminTests {
@Test
public void testTelnetCommandWithConfigAdminEnabledTelnet() throws Exception {
- CommandSession session = EasyMock.createMock(CommandSession.class);
- session.put((String)EasyMock.anyObject(), EasyMock.anyObject());
- EasyMock.expectLastCall().times(3);
- EasyMock.expect(session.execute((String)EasyMock.anyObject())).andReturn(new Object());
- session.close();
- EasyMock.expectLastCall();
- EasyMock.replay(session);
+ CommandSession session = mock(CommandSession.class);
+ when(session.execute(any(String.class))).thenReturn(new Object());
- CommandProcessor processor = EasyMock.createMock(CommandProcessor.class);
- EasyMock.expect(processor.createSession((ConsoleInputStream)EasyMock.anyObject(), (PrintStream)EasyMock.anyObject(), (PrintStream)EasyMock.anyObject())).andReturn(session);
- EasyMock.replay(processor);
+ CommandProcessor processor = mock(CommandProcessor.class);
+ when(processor.createSession(any(ConsoleInputStream.class), any(PrintStream.class), any(PrintStream.class))).thenReturn(session);
- final ServiceRegistration<?> registration = EasyMock.createMock(ServiceRegistration.class);
- registration.setProperties((Dictionary<String, ?>)EasyMock.anyObject());
+ final ServiceRegistration<?> registration = mock(ServiceRegistration.class);
- EasyMock.expectLastCall();
- EasyMock.replay(registration);
- BundleContext context = EasyMock.createMock(BundleContext.class);
- EasyMock.expect(context.getProperty(USE_CONFIG_ADMIN_PROP)).andReturn(TRUE);
- EasyMock.expect(
- (ServiceRegistration) context.registerService(
- (String)EasyMock.anyObject(),
- (ManagedService)EasyMock.anyObject(),
- (Dictionary<String, ?>)EasyMock.anyObject())
- ).andAnswer(() -> {
- configurator = (ManagedService) EasyMock.getCurrentArguments()[1];
- return registration;
- });
- EasyMock.expect(
- context.registerService(
- (String)EasyMock.anyObject(),
- (TelnetCommand)EasyMock.anyObject(),
- (Dictionary<String, ?>)EasyMock.anyObject())).andReturn(null);
- EasyMock.replay(context);
-
+ BundleContext context =mock(BundleContext.class);
+ when(context.getProperty(USE_CONFIG_ADMIN_PROP)).thenReturn(TRUE);
+ when(context.registerService(any(String.class), any(ManagedService.class), any(Dictionary.class)))
+ .thenAnswer(invocation -> {
+ configurator = (ManagedService) invocation.getArguments()[1];
+ return registration;
+ });
+ when(context.registerService(any(String.class), any(TelnetCommand.class), any(Dictionary.class)))
+ .thenReturn(null);
+
TelnetCommand command = new TelnetCommand(processor, context);
command.startService();
Dictionary<String, String> props = new Hashtable<>();
@@ -104,7 +89,6 @@ public class TelnetCommandWithConfigAdminTests {
} finally {
command.telnet(new String[] {STOP_COMMAND});
}
- EasyMock.verify(context);
}
@Test
@@ -118,42 +102,25 @@ public class TelnetCommandWithConfigAdminTests {
}
private void disabledTelnet(boolean isDefault) throws Exception {
- CommandSession session = EasyMock.createMock(CommandSession.class);
- session.put((String)EasyMock.anyObject(), EasyMock.anyObject());
- EasyMock.expectLastCall().times(4);
- EasyMock.expect(session.execute((String)EasyMock.anyObject())).andReturn(new Object());
- session.close();
- EasyMock.expectLastCall();
- EasyMock.replay(session);
+ CommandSession session = mock(CommandSession.class);
+ when(session.execute(any(String.class))).thenReturn(new Object());
- CommandProcessor processor = EasyMock.createMock(CommandProcessor.class);
- EasyMock.expect(processor.createSession((ConsoleInputStream)EasyMock.anyObject(), (PrintStream)EasyMock.anyObject(), (PrintStream)EasyMock.anyObject())).andReturn(session);
- EasyMock.replay(processor);
+ CommandProcessor processor = mock(CommandProcessor.class);
+ when(processor.createSession(any(ConsoleInputStream.class), any(PrintStream.class),
+ any(PrintStream.class))).thenReturn(session);
- final ServiceRegistration<?> registration = EasyMock.createMock(ServiceRegistration.class);
- registration.setProperties((Dictionary<String, ?>)EasyMock.anyObject());
+ final ServiceRegistration<?> registration = mock(ServiceRegistration.class);
- EasyMock.expectLastCall();
- EasyMock.replay(registration);
+ BundleContext context = mock(BundleContext.class);
+ when(context.getProperty(USE_CONFIG_ADMIN_PROP)).thenReturn(TRUE);
+ when(context.registerService(any(String.class), any(ManagedService.class), any(Dictionary.class)))
+ .thenAnswer(invocation -> {
+ configurator = (ManagedService) invocation.getArguments()[1];
+ return registration;
+ });
+ when(context.registerService(any(String.class), any(TelnetCommand.class), any(Dictionary.class)))
+ .thenReturn(null);
- BundleContext context = EasyMock.createMock(BundleContext.class);
- EasyMock.expect(context.getProperty(USE_CONFIG_ADMIN_PROP)).andReturn(TRUE);
- EasyMock.expect(
- (ServiceRegistration) context.registerService(
- (String)EasyMock.anyObject(),
- (ManagedService)EasyMock.anyObject(),
- (Dictionary<String, ?>)EasyMock.anyObject())
- ).andAnswer(() -> {
- configurator = (ManagedService) EasyMock.getCurrentArguments()[1];
- return registration;
- });
- EasyMock.expect(
- context.registerService(
- (String)EasyMock.anyObject(),
- (TelnetCommand)EasyMock.anyObject(),
- (Dictionary<String, ?>)EasyMock.anyObject())).andReturn(null);
- EasyMock.replay(context);
-
TelnetCommand command = new TelnetCommand(processor, context);
command.startService();
Dictionary<String, String> props = new Hashtable<>();
@@ -176,7 +143,6 @@ public class TelnetCommandWithConfigAdminTests {
//this is expected
}
}
- EasyMock.verify(context);
}
}
diff --git a/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetConnectionTests.java b/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetConnectionTests.java
index acbf5bbe4..2ea267eaa 100755
--- a/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetConnectionTests.java
+++ b/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetConnectionTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011, 2017 SAP AG and others.
+ * Copyright (c) 2011, 2021 SAP AG and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -14,12 +14,10 @@
package org.eclipse.equinox.console.telnet;
-import org.apache.felix.service.command.CommandProcessor;
-import org.apache.felix.service.command.CommandSession;
-import org.junit.Assert;
-import org.junit.Test;
-import org.easymock.EasyMock;
-import org.eclipse.equinox.console.common.ConsoleInputStream;
+import static org.junit.Assert.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
import java.io.InputStream;
import java.io.OutputStream;
@@ -27,6 +25,11 @@ import java.io.PrintStream;
import java.net.ServerSocket;
import java.net.Socket;
+import org.apache.felix.service.command.CommandProcessor;
+import org.apache.felix.service.command.CommandSession;
+import org.eclipse.equinox.console.common.ConsoleInputStream;
+import org.junit.Test;
+
public class TelnetConnectionTests {
private static final String HOST = "localhost";
@@ -39,19 +42,14 @@ public class TelnetConnectionTests {
try (ServerSocket servSocket = new ServerSocket(0);
Socket socketClient = new Socket(HOST, servSocket.getLocalPort());
Socket socketServer = servSocket.accept();
- CommandSession session = EasyMock.createMock(CommandSession.class)) {
+ CommandSession session = mock(CommandSession.class)) {
- session.put((String) EasyMock.anyObject(), EasyMock.anyObject());
- EasyMock.expectLastCall().times(3);
- EasyMock.expect(session.execute((String) EasyMock.anyObject())).andReturn(null);
- session.close();
- EasyMock.expectLastCall();
- EasyMock.replay(session);
+ when(session.execute(any(String.class))).thenReturn(null);
- CommandProcessor processor = EasyMock.createMock(CommandProcessor.class);
- EasyMock.expect(processor.createSession((ConsoleInputStream) EasyMock.anyObject(),
- (PrintStream) EasyMock.anyObject(), (PrintStream) EasyMock.anyObject())).andReturn(session);
- EasyMock.replay(processor);
+ CommandProcessor processor = mock(CommandProcessor.class);
+ when(processor.createSession(any(ConsoleInputStream.class), any(PrintStream.class),
+ any(PrintStream.class)))
+ .thenReturn(session);
try (TelnetConnection connection = new TelnetConnection(socketServer, processor, null)) {
connection.start();
@@ -63,20 +61,18 @@ public class TelnetConnectionTests {
InputStream input = socketServer.getInputStream();
int in = input.read();
- Assert.assertTrue(
- "Server received [" + in + "] instead of " + TEST_CONTENT + " from the telnet client.",
- in == TEST_CONTENT);
+ assertEquals("Server received [" + in + "] instead of " + TEST_CONTENT + " from the telnet client.",
+ TEST_CONTENT, in);
input = socketClient.getInputStream();
in = input.read();
// here IAC is expected, since when the output stream in TelnetConsoleSession is
// created, several telnet
// commands are written to it, each of them starting with IAC
- Assert.assertTrue("Client receive telnet responses from the server unexpected value [" + in
- + "] instead of " + IAC + ".", in == IAC);
+ assertEquals("Client receive telnet responses from the server unexpected value [" + in
+ + "] instead of " + IAC + ".", IAC, in);
connection.telnetNegotiationFinished();
Thread.sleep(5000);
- EasyMock.verify(session, processor);
}
}
}
diff --git a/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetDisconnectionTest.java b/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetDisconnectionTest.java
index 84f25cbb5..7ee0fc161 100755
--- a/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetDisconnectionTest.java
+++ b/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetDisconnectionTest.java
@@ -1,5 +1,10 @@
package org.eclipse.equinox.console.telnet;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
import java.io.InputStream;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
@@ -9,10 +14,8 @@ import java.net.Socket;
import org.apache.felix.service.command.CommandProcessor;
import org.apache.felix.service.command.CommandSession;
-import org.easymock.EasyMock;
import org.eclipse.equinox.console.commands.DisconnectCommand;
import org.eclipse.equinox.console.common.ConsoleInputStream;
-import org.junit.Assert;
import org.junit.Test;
import org.osgi.framework.BundleContext;
@@ -21,34 +24,27 @@ public class TelnetDisconnectionTest {
private InputStream in;
@Test
- public void testTelneConnection() throws Exception {
+ public void testTelnetConnection() throws Exception {
TelnetConnection connection = null;
try (ServerSocket servSocket = new ServerSocket(0);
Socket socketClient = new Socket(HOST, servSocket.getLocalPort());
Socket socketServer = servSocket.accept();
- CommandSession session = EasyMock.createMock(CommandSession.class)) {
+ CommandSession session = mock(CommandSession.class)) {
- CommandProcessor processor = EasyMock.createMock(CommandProcessor.class);
+ CommandProcessor processor = mock(CommandProcessor.class);
connection = new TelnetConnection(socketServer, processor, null);
- EasyMock.makeThreadSafe(session, true);
- session.put((String) EasyMock.anyObject(), EasyMock.anyObject());
- EasyMock.expectLastCall().times(3);
- EasyMock.expect(session.get("CLOSEABLE")).andReturn(connection);
- EasyMock.expect(session.execute((String) EasyMock.anyObject())).andReturn(null);
- session.close();
- EasyMock.expectLastCall();
- EasyMock.replay(session);
+ when(session.get("CLOSEABLE")).thenReturn(connection);
+ when(session.execute(any(String.class))).thenReturn(null);
- EasyMock.expect(processor.createSession((ConsoleInputStream) EasyMock.anyObject(),
- (PrintStream) EasyMock.anyObject(), (PrintStream) EasyMock.anyObject())).andReturn(session);
- EasyMock.replay(processor);
+ when(processor.createSession(any(ConsoleInputStream.class), any(PrintStream.class), any(PrintStream.class)))
+ .thenReturn(session);
connection.start();
Thread.sleep(60000);
- BundleContext context = EasyMock.createMock(BundleContext.class);
+ BundleContext context = mock(BundleContext.class);
final DisconnectCommand command = new DisconnectCommand(context);
PipedOutputStream outputStream = new PipedOutputStream();
@@ -69,13 +65,11 @@ public class TelnetDisconnectionTest {
outputStream.flush();
Thread.sleep(3000);
- Assert.assertTrue("Socket is not closed!", socketServer.isClosed());
+ assertTrue("Socket is not closed!", socketServer.isClosed());
connection.telnetNegotiationFinished();
Thread.sleep(5000);
- EasyMock.verify(session, processor);
} finally {
-
System.setIn(in);
}
}
diff --git a/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetInputHandlerTests.java b/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetInputHandlerTests.java
index a4708eeb9..9308073bb 100755
--- a/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetInputHandlerTests.java
+++ b/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetInputHandlerTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011, 2017 SAP AG and others.
+ * Copyright (c) 2011, 2021 SAP AG and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -14,14 +14,14 @@
package org.eclipse.equinox.console.telnet;
-import static org.easymock.EasyMock.createMock;
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.mock;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import org.eclipse.equinox.console.common.ConsoleInputStream;
import org.eclipse.equinox.console.common.ConsoleOutputStream;
-import org.junit.Assert;
import org.junit.Test;
public class TelnetInputHandlerTests {
@@ -34,7 +34,7 @@ public class TelnetInputHandlerTests {
ConsoleInputStream in = new ConsoleInputStream();
ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
ConsoleOutputStream out = new ConsoleOutputStream(byteOut);
- Callback callback = createMock(Callback.class);
+ Callback callback = mock(Callback.class);
TelnetInputHandler handler = new TelnetInputHandler(input, in, out, callback);
handler.start();
@@ -46,7 +46,7 @@ public class TelnetInputHandlerTests {
}
String res = byteOut.toString();
- Assert.assertTrue("Wrong input. Expected abcde, read " + res, res.equals("abcde"));
+ assertEquals("Wrong input. Expected abcde, read " + res, "abcde", res);
}
}
diff --git a/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetInputScannerTests.java b/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetInputScannerTests.java
index 5a5251de3..bc630df11 100755
--- a/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetInputScannerTests.java
+++ b/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetInputScannerTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011, 2017 SAP AG and others.
+ * Copyright (c) 2011, 2021 SAP AG and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -14,6 +14,17 @@
package org.eclipse.equinox.console.telnet;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.PipedInputStream;
+import java.io.PipedOutputStream;
+import java.util.HashMap;
+import java.util.Map;
+
import org.eclipse.equinox.console.common.ConsoleInputStream;
import org.eclipse.equinox.console.common.ConsoleOutputStream;
import org.eclipse.equinox.console.common.KEYS;
@@ -23,18 +34,8 @@ import org.eclipse.equinox.console.common.terminal.TerminalTypeMappings;
import org.eclipse.equinox.console.common.terminal.VT100TerminalTypeMappings;
import org.eclipse.equinox.console.common.terminal.VT220TerminalTypeMappings;
import org.eclipse.equinox.console.common.terminal.VT320TerminalTypeMappings;
-import org.junit.Assert;
import org.junit.Test;
-import static org.easymock.EasyMock.*;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.PipedInputStream;
-import java.io.PipedOutputStream;
-import java.util.HashMap;
-import java.util.Map;
-
public class TelnetInputScannerTests {
private static final int IAC = 255;
@@ -66,7 +67,7 @@ public class TelnetInputScannerTests {
ConsoleInputStream in = new ConsoleInputStream();
ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
ConsoleOutputStream out = new ConsoleOutputStream(byteOut);
- Callback callback = createMock(Callback.class);
+ Callback callback = mock(Callback.class);
TelnetInputScanner scanner = new TelnetInputScanner(in, out, callback);
try {
scanner.scan((byte) SE);
@@ -86,7 +87,7 @@ public class TelnetInputScannerTests {
}
String output = byteOut.toString();
- Assert.assertTrue("Output incorrect. Expected abc, but read " + output, output.equals("abc"));
+ assertEquals("Output incorrect. Expected abc, but read " + output, "abc", output);
}
@Test
@@ -94,7 +95,7 @@ public class TelnetInputScannerTests {
ConsoleInputStream in = new ConsoleInputStream();
ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
ConsoleOutputStream out = new ConsoleOutputStream(byteOut);
- Callback callback = createMock(Callback.class);
+ Callback callback = mock(Callback.class);
TelnetInputScanner scanner = new TelnetInputScanner(in, out, callback);
try {
@@ -108,7 +109,7 @@ public class TelnetInputScannerTests {
}
String output = byteOut.toString();
- Assert.assertTrue("Output incorrect. Expected ab, but read " + output, output.equals("ab"));
+ assertTrue("Output incorrect. Expected ab, but read " + output, output.equals("ab"));
}
@Test
@@ -139,28 +140,28 @@ public class TelnetInputScannerTests {
out.flush();
int read = clientIn.read();
- Assert.assertEquals("Unexpected input ", IAC, read);
+ assertEquals("Unexpected input ", IAC, read);
read = clientIn.read();
- Assert.assertEquals("Unexpected input ", DO, read);
+ assertEquals("Unexpected input ", DO, read);
read = clientIn.read();
- Assert.assertEquals("Unexpected input ", TTYPE, read);
+ assertEquals("Unexpected input ", TTYPE, read);
scanner.scan(IAC);
scanner.scan(WILL);
scanner.scan(TTYPE);
read = clientIn.read();
- Assert.assertEquals("Unexpected input ", IAC, read);
+ assertEquals("Unexpected input ", IAC, read);
read = clientIn.read();
- Assert.assertEquals("Unexpected input ", SB, read);
+ assertEquals("Unexpected input ", SB, read);
read = clientIn.read();
- Assert.assertEquals("Unexpected input ", TTYPE, read);
+ assertEquals("Unexpected input ", TTYPE, read);
read = clientIn.read();
- Assert.assertEquals("Unexpected input ", SEND, read);
+ assertEquals("Unexpected input ", SEND, read);
read = clientIn.read();
- Assert.assertEquals("Unexpected input ", IAC, read);
+ assertEquals("Unexpected input ", IAC, read);
read = clientIn.read();
- Assert.assertEquals("Unexpected input ", SE, read);
+ assertEquals("Unexpected input ", SE, read);
scanner.scan(IAC);
scanner.scan(SB);
@@ -175,17 +176,17 @@ public class TelnetInputScannerTests {
scanner.scan(SE);
read = clientIn.read();
- Assert.assertEquals("Unexpected input ", IAC, read);
+ assertEquals("Unexpected input ", IAC, read);
read = clientIn.read();
- Assert.assertEquals("Unexpected input ", SB, read);
+ assertEquals("Unexpected input ", SB, read);
read = clientIn.read();
- Assert.assertEquals("Unexpected input ", TTYPE, read);
+ assertEquals("Unexpected input ", TTYPE, read);
read = clientIn.read();
- Assert.assertEquals("Unexpected input ", SEND, read);
+ assertEquals("Unexpected input ", SEND, read);
read = clientIn.read();
- Assert.assertEquals("Unexpected input ", IAC, read);
+ assertEquals("Unexpected input ", IAC, read);
read = clientIn.read();
- Assert.assertEquals("Unexpected input ", SE, read);
+ assertEquals("Unexpected input ", SE, read);
scanner.scan(IAC);
scanner.scan(SB);
@@ -197,17 +198,17 @@ public class TelnetInputScannerTests {
scanner.scan(IAC);
scanner.scan(SE);
- Assert.assertEquals("Incorrect BACKSPACE: ", mappings.getBackspace(), scanner.getBackspace());
- Assert.assertEquals("Incorrect DELL: ", mappings.getDel(), scanner.getDel());
+ assertEquals("Incorrect BACKSPACE: ", mappings.getBackspace(), scanner.getBackspace());
+ assertEquals("Incorrect DELL: ", mappings.getDel(), scanner.getDel());
Map<String, KEYS> currentEscapesToKey = scanner.getCurrentEscapesToKey();
Map<String, KEYS> expectedEscapesToKey = mappings.getEscapesToKey();
for (String escape : expectedEscapesToKey.keySet()) {
KEYS key = expectedEscapesToKey.get(escape);
- Assert.assertEquals("Incorrect " + key.name(), key, currentEscapesToKey.get(escape));
+ assertEquals("Incorrect " + key.name(), key, currentEscapesToKey.get(escape));
}
- Assert.assertTrue("Callback not called ", testCallback.getState());
+ assertTrue("Callback not called ", testCallback.getState());
}
class TestCallback implements Callback {
diff --git a/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetServerTests.java b/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetServerTests.java
index ce471cd73..9f965d7dc 100755
--- a/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetServerTests.java
+++ b/bundles/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetServerTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011, 2017 SAP AG and others.
+ * Copyright (c) 2011, 2021 SAP AG and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -14,12 +14,11 @@
package org.eclipse.equinox.console.telnet;
-import org.apache.felix.service.command.CommandProcessor;
-import org.apache.felix.service.command.CommandSession;
-import org.easymock.EasyMock;
-import org.eclipse.equinox.console.common.ConsoleInputStream;
-import org.junit.Assert;
-import org.junit.Test;
+import static org.junit.Assert.fail;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
import java.io.OutputStream;
import java.io.PrintStream;
@@ -28,7 +27,11 @@ import java.net.Socket;
import java.util.ArrayList;
import java.util.List;
-import static org.easymock.EasyMock.*;
+import org.apache.felix.service.command.CommandProcessor;
+import org.apache.felix.service.command.CommandSession;
+import org.eclipse.equinox.console.common.ConsoleInputStream;
+import org.junit.Test;
+
public class TelnetServerTests {
@@ -39,18 +42,12 @@ public class TelnetServerTests {
@Test
public void testTelnetServer() throws Exception {
- try (CommandSession session = EasyMock.createMock(CommandSession.class)) {
- session.put((String) EasyMock.anyObject(), EasyMock.anyObject());
- EasyMock.expectLastCall().times(3);
- EasyMock.expect(session.execute((String) EasyMock.anyObject())).andReturn(new Object());
- session.close();
- EasyMock.expectLastCall();
- EasyMock.replay(session);
-
- CommandProcessor processor = EasyMock.createMock(CommandProcessor.class);
- EasyMock.expect(processor.createSession((ConsoleInputStream) EasyMock.anyObject(),
- (PrintStream) EasyMock.anyObject(), (PrintStream) EasyMock.anyObject())).andReturn(session);
- EasyMock.replay(processor);
+ try (CommandSession session = mock(CommandSession.class)) {
+ when(session.execute(anyString())).thenReturn(new Object());
+
+ CommandProcessor processor = mock(CommandProcessor.class);
+ when(processor.createSession(any(ConsoleInputStream.class), any(PrintStream.class), any(PrintStream.class)))
+ .thenReturn(session);
List<CommandProcessor> processors = new ArrayList<>();
processors.add(processor);
@@ -69,9 +66,8 @@ public class TelnetServerTests {
} catch (InterruptedException ie) {
// do nothing
}
- verify();
} catch (ConnectException e) {
- Assert.fail("Telnet port not open");
+ fail("Telnet port not open");
} finally {
telnetServer.stopTelnetServer();
}
@@ -80,18 +76,12 @@ public class TelnetServerTests {
@Test
public void testTelnetServerWithoutHost() throws Exception {
- try (CommandSession session = EasyMock.createMock(CommandSession.class)) {
- session.put((String) EasyMock.anyObject(), EasyMock.anyObject());
- EasyMock.expectLastCall().times(4);
- EasyMock.expect(session.execute((String) EasyMock.anyObject())).andReturn(new Object());
- session.close();
- EasyMock.expectLastCall();
- EasyMock.replay(session);
-
- CommandProcessor processor = EasyMock.createMock(CommandProcessor.class);
- EasyMock.expect(processor.createSession((ConsoleInputStream) EasyMock.anyObject(),
- (PrintStream) EasyMock.anyObject(), (PrintStream) EasyMock.anyObject())).andReturn(session);
- EasyMock.replay(processor);
+ try (CommandSession session = mock(CommandSession.class)) {
+ when(session.execute(anyString())).thenReturn(new Object());
+
+ CommandProcessor processor = mock(CommandProcessor.class);
+ when(processor.createSession(any(ConsoleInputStream.class),
+ any(PrintStream.class), any(PrintStream.class))).thenReturn(session);
List<CommandProcessor> processors = new ArrayList<>();
processors.add(processor);
@@ -111,7 +101,7 @@ public class TelnetServerTests {
// do nothing
}
} catch (ConnectException e) {
- Assert.fail("Telnet port not open");
+ fail("Telnet port not open");
} finally {
telnetServer.stopTelnetServer();
}

Back to the top