Skip to content

Commit

Permalink
Add testing code
Browse files Browse the repository at this point in the history
  • Loading branch information
hdecarne committed Apr 14, 2019
1 parent e2ab898 commit 01dc027
Showing 1 changed file with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import java.util.Properties;

import org.eclipse.swt.widgets.ProgressBar;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
Expand All @@ -36,8 +38,10 @@
import de.carne.swt.platform.PlatformIntegration;
import de.carne.test.swt.DisableIfThreadNotSWTCapable;
import de.carne.test.swt.tester.SWTTest;
import de.carne.test.swt.tester.accessor.ButtonAccessor;
import de.carne.test.swt.tester.accessor.ControlAccessor;
import de.carne.test.swt.tester.accessor.ItemAccessor;
import de.carne.test.swt.tester.accessor.ShellAccessor;

/**
* Test {@link FileScannerMain} class.
Expand All @@ -55,7 +59,9 @@ void testFileScanner() {
Script script = script(Application::run).args("--debug");

script.add(this::doOpenFile);
script.add(this::waitScanFinished, this::doVerifyScanResult, 60 * 1000);
script.add(this::waitScanFinished, this::doVerifyScanResult, 60 * 1000l);
script.add(this::doOpenExport, true);
script.add(() -> accessShell("Export scan result"), this::doVerifyExport, 60 * 1000l);
script.add(this::doClose);
script.execute();
}
Expand All @@ -73,7 +79,7 @@ private void doOpenFile() {

private ControlAccessor<ProgressBar> waitScanFinished() {
ControlAccessor<ProgressBar> progressBarAccessor = accessShell().accessChild(ControlAccessor::wrapControl,
ProgressBar.class, (control) -> true);
ProgressBar.class, control -> true);
Optional<? extends ProgressBar> optionalProgressBar = progressBarAccessor.getOptional();

return (optionalProgressBar.isPresent() && isProgressBarMaxedOut(optionalProgressBar.get())
Expand All @@ -85,8 +91,32 @@ private boolean isProgressBarMaxedOut(ProgressBar progressBar) {
return progressBar.getSelection() >= progressBar.getMaximum();
}

private static final String ZIP_ARCHIVE_RESULT_NAME = "ZIP archive";

private void doVerifyScanResult(ControlAccessor<ProgressBar> progressBar) {
Tree resultView = accessShell().accessChild(ControlAccessor::wrapControl, Tree.class, control -> true).get();

TreeItem rootItem = resultView.getItem(0);

Assertions.assertNotNull(rootItem);
Assertions.assertTrue(rootItem.getExpanded());
Assertions.assertTrue(rootItem.getItemCount() == 1);

TreeItem zipArchiveItem = rootItem.getItem(0);

Assertions.assertEquals(ZIP_ARCHIVE_RESULT_NAME, zipArchiveItem.getText());

resultView.setSelection(zipArchiveItem);
}

private void doOpenExport() {
traceAction();

accessShell().accessMenuBar().accessMenuItem(ItemAccessor.matchText("&Export\u2026")).select();
}

private void doVerifyExport(ShellAccessor exportDialog) {
exportDialog.accessButton(ButtonAccessor.matchText("Cancel")).select();
}

private void doClose() {
Expand Down

0 comments on commit 01dc027

Please sign in to comment.