Skip to content

Commit c2c182e

Browse files
committed
Cleanup docker tests code
Simplify and remove unused code
1 parent 29152d3 commit c2c182e

15 files changed

+62
-195
lines changed

containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/docker/core/DockerConnectionManagerTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@
3333
import org.eclipse.linuxtools.internal.docker.ui.testutils.MockDockerConnectionFactory;
3434
import org.eclipse.linuxtools.internal.docker.ui.testutils.MockDockerConnectionStorageManagerFactory;
3535
import org.eclipse.linuxtools.internal.docker.ui.testutils.swt.SWTUtils;
36+
import org.eclipse.swt.widgets.Display;
3637
import org.junit.After;
3738
import org.junit.AfterClass;
3839
import org.junit.Before;
3940
import org.junit.Test;
40-
4141
import org.mandas.docker.client.DockerClient;
4242

4343
public class DockerConnectionManagerTest {
@@ -65,7 +65,7 @@ public void shouldRegisterConnectionOnRefreshContainersManager() {
6565
.withDefaultTCPConnectionSettings();
6666
dockerConnectionManager
6767
.setConnectionStorageManager(MockDockerConnectionStorageManagerFactory.providing(dockerConnection));
68-
SWTUtils.syncExec(() -> dockerConnectionManager.reloadConnections());
68+
Display.getDefault().syncExec(() -> dockerConnectionManager.reloadConnections());
6969
// when
7070
dockerConnection.getContainers();
7171
// then
@@ -80,11 +80,11 @@ public void shouldUnregisterConnectionOnRefreshContainersManager() {
8080
.withDefaultTCPConnectionSettings();
8181
dockerConnectionManager
8282
.setConnectionStorageManager(MockDockerConnectionStorageManagerFactory.providing(dockerConnection));
83-
SWTUtils.syncExec(() -> dockerConnectionManager.reloadConnections());
83+
Display.getDefault().syncExec(() -> dockerConnectionManager.reloadConnections());
8484
dockerConnection.getContainers();
8585
Assertions.assertThat(dockerContainersRefreshManager.getConnections()).contains(dockerConnection);
8686
// when
87-
SWTUtils.syncExec(() -> dockerConnectionManager.removeConnection(dockerConnection));
87+
Display.getDefault().syncExec(() -> dockerConnectionManager.removeConnection(dockerConnection));
8888
SWTUtils.wait(1, TimeUnit.SECONDS);
8989
// then
9090
Assertions.assertThat(!dockerContainersRefreshManager.getConnections().contains(dockerConnection));

containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/BaseSWTBotTest.java

Lines changed: 0 additions & 51 deletions
This file was deleted.

containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/commands/CommandUtilsSWTBotTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import org.junit.ClassRule;
3535
import org.junit.Rule;
3636
import org.junit.Test;
37-
3837
import org.mandas.docker.client.DockerClient;
3938

4039
/**
@@ -55,7 +54,7 @@ public class CommandUtilsSWTBotTest {
5554

5655
@Before
5756
public void lookupDockerExplorerView() {
58-
SWTUtils.asyncExec(() -> {
57+
bot.getDisplay().asyncExec(() -> {
5958
try {
6059
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
6160
.showView("org.eclipse.linuxtools.docker.ui.dockerExplorerView");
@@ -69,7 +68,7 @@ public void lookupDockerExplorerView() {
6968
bot.views().stream()
7069
.filter(v -> v.getReference().getId().equals("org.eclipse.linuxtools.docker.ui.dockerContainersView")
7170
|| v.getReference().getId().equals("org.eclipse.linuxtools.docker.ui.dockerImagesView"))
72-
.forEach(v -> v.close());
71+
.forEach(SWTBotView::close);
7372
}
7473

7574
@Test

containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/launch/BuildDockerImageShortcutSWTBotTest.java

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,10 @@
4343
import org.junit.ClassRule;
4444
import org.junit.Rule;
4545
import org.junit.Test;
46-
import org.mockito.ArgumentMatchers;
47-
import org.mockito.Mockito;
48-
4946
import org.mandas.docker.client.DockerClient;
5047
import org.mandas.docker.client.ProgressHandler;
48+
import org.mockito.ArgumentMatchers;
49+
import org.mockito.Mockito;
5150

5251
/**
5352
* Testing the {@link BuildDockerImageShortcut}
@@ -97,12 +96,12 @@ public void shouldDisableCommandOnFirstCallWhenMissingConnection() {
9796
// given no connection
9897
ClearConnectionManagerRule.removeAllConnections(DockerConnectionManager.getInstance());
9998
// when
100-
SWTUtils.asyncExec(() -> getRunAsdockerImageBuildContextMenu("foo", "Dockerfile").click());
99+
bot.getDisplay().asyncExec(() -> getRunAsdockerImageBuildContextMenu("foo", "Dockerfile").click());
101100
// then expect an error dialog because no Docker connection exists
102101
assertThat(bot.shell(LaunchMessages.getString("BuildDockerImageShortcut.no.connections.msg")))
103102
.isNotNull();
104103
// closing the wizard
105-
SWTUtils.syncExec(() -> {
104+
bot.getDisplay().syncExec(() -> {
106105
bot.button("No").click();
107106
});
108107
}
@@ -116,12 +115,12 @@ public void shouldPromptDialogThenBuildDockerImageOnFirstCall()
116115
final DockerConnection dockerConnection = MockDockerConnectionFactory.from("Test", client).withDefaultTCPConnectionSettings();
117116
DockerConnectionManagerUtils.configureConnectionManager(dockerConnection);
118117
// when
119-
SWTUtils.asyncExec(() -> getRunAsdockerImageBuildContextMenu("foo", "Dockerfile").click());
118+
bot.getDisplay().asyncExec(() -> getRunAsdockerImageBuildContextMenu("foo", "Dockerfile").click());
120119
// then expect a dialog, fill the "repository" text field and click "Ok"
121120
assertThat(bot.shell(WizardMessages.getString("ImageBuildDialog.title"))).isNotNull();
122121
bot.textWithLabel(WizardMessages.getString("ImageBuildDialog.repoNameLabel")).setText("foo/bar:latest");
123122
// when launching the build
124-
SWTUtils.syncExec(() -> {
123+
bot.getDisplay().syncExec(() -> {
125124
bot.button("OK").click();
126125
});
127126
// then the 'DockerConnection#buildImage(...) method should have been
@@ -140,12 +139,12 @@ public void shouldBuildDockerImageImmediatelyOnSecondCall()
140139
final DockerConnection dockerConnection = MockDockerConnectionFactory.from("Test", client).withDefaultTCPConnectionSettings();
141140
DockerConnectionManagerUtils.configureConnectionManager(dockerConnection);
142141
// when
143-
SWTUtils.asyncExec(() -> getRunAsdockerImageBuildContextMenu("foo", "Dockerfile").click());
142+
bot.getDisplay().asyncExec(() -> getRunAsdockerImageBuildContextMenu("foo", "Dockerfile").click());
144143
// then expect a dialog, fill the "repository" text field and click "Ok"
145144
assertThat(bot.shell(WizardMessages.getString("ImageBuildDialog.title"))).isNotNull();
146145
bot.textWithLabel(WizardMessages.getString("ImageBuildDialog.repoNameLabel")).setText("foo/bar:latest");
147146
// when launching the build
148-
SWTUtils.syncExec(() -> {
147+
bot.getDisplay().syncExec(() -> {
149148
bot.button("OK").click();
150149
});
151150
// then the 'DockerConnection#buildImage(...) method should have been
@@ -154,7 +153,7 @@ public void shouldBuildDockerImageImmediatelyOnSecondCall()
154153
ArgumentMatchers.any(Path.class), ArgumentMatchers.any(String.class),
155154
ArgumentMatchers.any(ProgressHandler.class), ArgumentMatchers.any());
156155
// when trying to call again, there should be no dialog
157-
SWTUtils.asyncExec(() -> getRunAsdockerImageBuildContextMenu("foo", "Dockerfile").click());
156+
bot.getDisplay().asyncExec(() -> getRunAsdockerImageBuildContextMenu("foo", "Dockerfile").click());
158157
// then a second call should have been done
159158
Mockito.verify(client, Mockito.timeout((int) TimeUnit.SECONDS.toMillis(3)).times(2)).build(
160159
ArgumentMatchers.any(Path.class), ArgumentMatchers.any(String.class),
@@ -170,12 +169,12 @@ public void shouldNotBuildDockerImageOnSecondCallWhenAllConnectionWereRemoved()
170169
final DockerConnection dockerConnection = MockDockerConnectionFactory.from("Test", client).withDefaultTCPConnectionSettings();
171170
DockerConnectionManagerUtils.configureConnectionManager(dockerConnection);
172171
// when
173-
SWTUtils.asyncExec(() -> getRunAsdockerImageBuildContextMenu("foo", "Dockerfile").click());
172+
bot.getDisplay().asyncExec(() -> getRunAsdockerImageBuildContextMenu("foo", "Dockerfile").click());
174173
// then expect a dialog, fill the "repository" text field and click "Ok"
175174
assertThat(bot.shell(WizardMessages.getString("ImageBuildDialog.title"))).isNotNull();
176175
bot.textWithLabel(WizardMessages.getString("ImageBuildDialog.repoNameLabel")).setText("foo/bar:latest");
177176
// when launching the build
178-
SWTUtils.syncExec(() -> {
177+
bot.getDisplay().syncExec(() -> {
179178
bot.button("OK").click();
180179
});
181180
// then the 'DockerConnection#buildImage(...) method should have been
@@ -195,7 +194,7 @@ public void shouldNotBuildDockerImageOnSecondCallWhenAllConnectionWereRemoved()
195194
shell.bot().button(IDialogConstants.CLOSE_LABEL).click();
196195
}, false);
197196
// do not save the config while closing
198-
SWTUtils.syncExec(() -> {
197+
bot.getDisplay().syncExec(() -> {
199198
bot.button(IDialogConstants.NO_LABEL).click();
200199
});
201200
}
@@ -208,12 +207,12 @@ public void shouldPromptForAnotherConnectionWhenBuildingDockerImageOnSecondCallA
208207
final DockerConnection dockerConnection = MockDockerConnectionFactory.from("Test", client).withDefaultTCPConnectionSettings();
209208
DockerConnectionManagerUtils.configureConnectionManager(dockerConnection);
210209
// when
211-
SWTUtils.asyncExec(() -> getRunAsdockerImageBuildContextMenu("foo", "Dockerfile").click());
210+
bot.getDisplay().asyncExec(() -> getRunAsdockerImageBuildContextMenu("foo", "Dockerfile").click());
212211
// then expect a dialog, fill the "repository" text field and click "Ok"
213212
assertThat(bot.shell(WizardMessages.getString("ImageBuildDialog.title"))).isNotNull();
214213
bot.textWithLabel(WizardMessages.getString("ImageBuildDialog.repoNameLabel")).setText("foo/bar:latest");
215214
// when launching the build
216-
SWTUtils.syncExec(() -> {
215+
bot.getDisplay().syncExec(() -> {
217216
bot.button("OK").click();
218217
});
219218
// then the 'DockerConnection#buildImage(...) method should have been
@@ -225,12 +224,12 @@ public void shouldPromptForAnotherConnectionWhenBuildingDockerImageOnSecondCallA
225224
// be an error dialog
226225
final DockerConnection dockerConnection2 = MockDockerConnectionFactory.from("Test 2", client).withDefaultTCPConnectionSettings();
227226
DockerConnectionManagerUtils.configureConnectionManager(dockerConnection2);
228-
SWTUtils.asyncExec(() -> getRunAsdockerImageBuildContextMenu("foo", "Dockerfile").click());
227+
bot.getDisplay().asyncExec(() -> getRunAsdockerImageBuildContextMenu("foo", "Dockerfile").click());
229228
// then expect a dialog, fill the "repository" text field and click "Ok"
230229
assertThat(bot.shell(WizardMessages.getString("ImageBuildDialog.title"))).isNotNull();
231230
bot.textWithLabel(WizardMessages.getString("ImageBuildDialog.repoNameLabel")).setText("foo/bar:latest");
232231
// when launching the build
233-
SWTUtils.syncExec(() -> {
232+
bot.getDisplay().syncExec(() -> {
234233
bot.button("OK").click();
235234
});
236235
// then the 'DockerConnection#buildImage(...) method should have been
@@ -250,12 +249,12 @@ public void shouldNotBuildDockerImageOnSecondCallWhenDockerfileWasRemoved()
250249
.withDefaultTCPConnectionSettings();
251250
DockerConnectionManagerUtils.configureConnectionManager(dockerConnection);
252251
// when
253-
SWTUtils.asyncExec(() -> getRunAsdockerImageBuildContextMenu("foo", "Dockerfile").click());
252+
bot.getDisplay().asyncExec(() -> getRunAsdockerImageBuildContextMenu("foo", "Dockerfile").click());
254253
// then expect a dialog, fill the "repository" text field and click "Ok"
255254
assertThat(bot.shell(WizardMessages.getString("ImageBuildDialog.title"))).isNotNull();
256255
bot.textWithLabel(WizardMessages.getString("ImageBuildDialog.repoNameLabel")).setText("foo/bar:latest");
257256
// when launching the build
258-
SWTUtils.syncExec(() -> {
257+
bot.getDisplay().syncExec(() -> {
259258
bot.button("OK").click();
260259
});
261260
// then the 'DockerConnection#buildImage(...) method should have been
@@ -270,7 +269,7 @@ public void shouldNotBuildDockerImageOnSecondCallWhenDockerfileWasRemoved()
270269
final SWTBotShell shell = bot.shell(JobMessages.getString("BuildImageJob.title")); //$NON-NLS-1$
271270
assertThat(shell).isNotNull();
272271
// closing the dialog
273-
SWTUtils.syncExec(() -> {
272+
bot.getDisplay().syncExec(() -> {
274273
shell.bot().button(IDialogConstants.OK_LABEL).click();
275274
});
276275
}

containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/launch/DockerComposeSWTBotTest.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
package org.eclipse.linuxtools.internal.docker.ui.launch;
1515

1616
import static org.assertj.core.api.Assertions.assertThat;
17+
import static org.junit.Assert.assertFalse;
1718
import static org.junit.Assert.assertTrue;
1819

1920
import java.io.ByteArrayInputStream;
@@ -46,7 +47,6 @@
4647
import org.eclipse.linuxtools.internal.docker.ui.testutils.swt.ProjectExplorerViewRule;
4748
import org.eclipse.linuxtools.internal.docker.ui.testutils.swt.SWTUtils;
4849
import org.eclipse.linuxtools.internal.docker.ui.testutils.swt.TextAssertions;
49-
import org.eclipse.linuxtools.internal.docker.ui.testutils.swt.ToolbarButtonAssertions;
5050
import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
5151
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
5252
import org.eclipse.swtbot.swt.finder.widgets.SWTBotMenu;
@@ -175,11 +175,11 @@ public void shouldDisableCommandOnFirstCallWhenMissingConnection() {
175175
// given no connection
176176
ClearConnectionManagerRule.removeAllConnections(DockerConnectionManager.getInstance());
177177
// when
178-
SWTUtils.asyncExec(() -> getRunAsDockerComposeContextMenu("foo", "docker-compose.yml").click());
178+
bot.getDisplay().asyncExec(() -> getRunAsDockerComposeContextMenu("foo", "docker-compose.yml").click());
179179
// then expect an error dialog because no Docker connection exists
180180
assertThat(bot.shell(LaunchMessages.getString("DockerComposeUpShortcut.no.connections.msg"))).isNotNull();
181181
// closing the wizard
182-
SWTUtils.syncExec(() -> {
182+
bot.getDisplay().syncExec(() -> {
183183
bot.button("No").click();
184184
});
185185
}
@@ -193,7 +193,7 @@ public void shouldStartDockerComposeFromScratch() throws CoreException {
193193
.withDefaultTCPConnectionSettings();
194194
DockerConnectionManagerUtils.configureConnectionManager(dockerConnection);
195195
// when
196-
SWTUtils.asyncExec(() -> getRunAsDockerComposeContextMenu("foo", "docker-compose.yml").click());
196+
bot.getDisplay().asyncExec(() -> getRunAsDockerComposeContextMenu("foo", "docker-compose.yml").click());
197197
// then confirm the connection
198198
bot.button("OK").click();
199199
// wait for the job to run
@@ -203,7 +203,7 @@ public void shouldStartDockerComposeFromScratch() throws CoreException {
203203
// expect the 'stop' button to be enabled
204204
final SWTBotToolbarButton consoleToolbarStopButton = SWTUtils.getConsoleToolbarButtonWithTooltipText(bot,
205205
ConsoleMessages.getString("DockerComposeStopAction.tooltip"));
206-
ToolbarButtonAssertions.assertThat(consoleToolbarStopButton).isEnabled();
206+
assertTrue(consoleToolbarStopButton.isEnabled());
207207
// verify that the launch configuration was saved
208208
final ILaunchConfiguration launchConfiguration = LaunchConfigurationUtils.getLaunchConfigurationByName(
209209
IDockerComposeLaunchConfigurationConstants.CONFIG_TYPE_ID, "Docker Compose [foo]");
@@ -223,11 +223,11 @@ public void shouldStartDockerComposeWithExistingLaunchConfiguration() throws Cor
223223
final IFile dockerComposeScript = projectInit.getProject().getFile("docker-compose.yml");
224224
LaunchConfigurationUtils.createDockerComposeUpLaunchConfiguration(dockerConnection, dockerComposeScript);
225225
// when
226-
SWTUtils.asyncExec(() -> getRunAsDockerComposeContextMenu("foo", "docker-compose.yml").click());
226+
bot.getDisplay().asyncExec(() -> getRunAsDockerComposeContextMenu("foo", "docker-compose.yml").click());
227227
// then confirm the connection
228228
final SWTBotToolbarButton consoleToolbarStopButton = SWTUtils.getConsoleToolbarButtonWithTooltipText(bot,
229229
ConsoleMessages.getString("DockerComposeStopAction.tooltip"));
230-
ToolbarButtonAssertions.assertThat(consoleToolbarStopButton).isEnabled();
230+
assertTrue(consoleToolbarStopButton.isEnabled());
231231
}
232232

233233
@Test
@@ -238,13 +238,13 @@ public void shouldStopDockerCompose() throws CoreException {
238238
// when
239239
final SWTBotToolbarButton consoleToolbarStopButton = SWTUtils.getConsoleToolbarButtonWithTooltipText(bot,
240240
ConsoleMessages.getString("DockerComposeStopAction.tooltip"));
241-
ToolbarButtonAssertions.assertThat(consoleToolbarStopButton).isEnabled();
241+
assertTrue(consoleToolbarStopButton.isEnabled());
242242
consoleToolbarStopButton.click();
243243
// then
244244
// verify the latch is down
245245
assertThat(latch.getCount()).isEqualTo(0);
246246
// verify the stop button is disabled
247-
ToolbarButtonAssertions.assertThat(consoleToolbarStopButton).isNotEnabled();
247+
assertFalse(consoleToolbarStopButton.isEnabled());
248248
}
249249

250250
@Test
@@ -256,23 +256,23 @@ public void shouldRestartDockerCompose() throws InterruptedException, DockerExce
256256
.withDefaultTCPConnectionSettings();
257257
DockerConnectionManagerUtils.configureConnectionManager(dockerConnection);
258258
// when starting without launch config
259-
SWTUtils.asyncExec(() -> getRunAsDockerComposeContextMenu("foo", "docker-compose.yml").click());
259+
bot.getDisplay().asyncExec(() -> getRunAsDockerComposeContextMenu("foo", "docker-compose.yml").click());
260260
bot.button("OK").click();
261261
// wait for the job to run
262262
SWTUtils.waitForJobsToComplete();
263263
// when stopping
264264
final SWTBotToolbarButton consoleToolbarStopButton = SWTUtils.getConsoleToolbarButtonWithTooltipText(bot,
265265
ConsoleMessages.getString("DockerComposeStopAction.tooltip"));
266-
ToolbarButtonAssertions.assertThat(consoleToolbarStopButton).isEnabled();
266+
assertTrue(consoleToolbarStopButton.isEnabled());
267267
consoleToolbarStopButton.click();
268268
// redo the setup to get a new mock process
269269
setupMockedProcessLauncher();
270270
// when restarting
271-
SWTUtils.asyncExec(() -> getRunAsDockerComposeContextMenu("foo", "docker-compose.yml").click());
271+
bot.getDisplay().asyncExec(() -> getRunAsDockerComposeContextMenu("foo", "docker-compose.yml").click());
272272
// wait for the job to run
273273
SWTUtils.waitForJobsToComplete();
274274
// then
275-
ToolbarButtonAssertions.assertThat(consoleToolbarStopButton).isEnabled();
275+
assertTrue(consoleToolbarStopButton.isEnabled());
276276
}
277277

278278
@Test

containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/swt/DockerConnectionManagerUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public static void configureConnectionManager(final IDockerConnectionStorageMana
5757
final SWTWorkbenchBot bot = new SWTWorkbenchBot();
5858
final SWTBotView dockerExplorerBotView = SWTUtils.getSWTBotView(bot, DockerExplorerView.VIEW_ID);
5959
final SWTBotView dockerContainersBotView = SWTUtils.getSWTBotView(bot, DockerContainersView.VIEW_ID);
60-
SWTUtils.syncExec(() -> {
60+
bot.getDisplay().syncExec(() -> {
6161
DockerConnectionManager.getInstance().reloadConnections();
6262
if (dockerExplorerBotView != null) {
6363
final DockerExplorerView dockerExplorerView = (DockerExplorerView) dockerExplorerBotView

0 commit comments

Comments
 (0)