Skip to content

Commit

Permalink
Improve LaunchConfigurationTabGroupViewerTest
Browse files Browse the repository at this point in the history
Add some tests to check that no unnecessary de/activation of tabs is
happening and add some assertions to existing tests too. These
improvements are necessary in order to guarantee that fixing
eclipse-platform/eclipse.platform.swt#46 do
not change the existing behavior of LaunchConfigurationTabGroupViewer.

Contributes to
eclipse-platform#859
Contributes to
eclipse-platform/eclipse.platform.swt#46
  • Loading branch information
fedejeanne committed Apr 10, 2024
1 parent de6a702 commit 0142df2
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,21 @@ public void testAllTabsAreInitializedByDefault() {
final ILaunchConfigurationTab[] tabs = runOnDialog(createAndSelect1LaunchConfig);

for (ILaunchConfigurationTab tab : tabs) {
assertThat(((SpyTab) tab)).matches(SpyTab::isInitialized, "should have been initialized");
assertThat(((SpyTab) tab)).matches(SpyTab::isInitializedExactlyOnce, "should have been initialized exactly once");
}
}

@Test
public void testNoTabsAreDeactivatedByDefault() {
// Create a launch configuration with a unique name
ThrowingRunnable<CoreException> createAndSelect1LaunchConfig = () -> {
fLaunchConfigurationsDialog.getTabViewer().setInput(createLaunchConfigurationInstance());
};

final ILaunchConfigurationTab[] tabs = runOnDialog(createAndSelect1LaunchConfig);

for (ILaunchConfigurationTab tab : tabs) {
assertThat(((SpyTab) tab)).matches(not(SpyTab::isDeactivated), "should NOT have been deactivated");
}
}

Expand All @@ -82,7 +96,29 @@ public void testFirstTabIsActivatedByDefault() {
};

final ILaunchConfigurationTab[] tabs = runOnDialog(createAndSelect1LaunchConfig);
assertThat(((SpyTab) tabs[0])).matches(SpyTab::isActivated, "should have been activated");
SpyTab defaultTab = (SpyTab) tabs[0];
assertThat(defaultTab).matches(SpyTab::isActivatedExactlyOnce, "should have been activated exactly once");
assertThat(defaultTab).matches(not(SpyTab::isDeactivated), "should NOT have been deactivated");
}

@Test
public void testActivatingTabTwiceDoesNotDeactivateIt() {
int tabIndex = 1;

// Create a launch configuration with a unique name
ThrowingRunnable<CoreException> selectTabTwice = () -> {
fLaunchConfigurationsDialog.getTabViewer().setInput(createLaunchConfigurationInstance());

// Activate the same tab twice
fLaunchConfigurationsDialog.getTabViewer().setActiveTab(tabIndex);
fLaunchConfigurationsDialog.getTabViewer().setActiveTab(tabIndex);
};

final ILaunchConfigurationTab[] tabs = runOnDialog(selectTabTwice);

SpyTab activeTab = (SpyTab) tabs[tabIndex];
assertThat(activeTab).matches(SpyTab::isActivatedExactlyOnce, "should have been activated exactly once");
assertThat(activeTab).matches(not(SpyTab::isDeactivated), "should NOT have been deactivated");
}

@Test
Expand All @@ -104,6 +140,12 @@ public void testOtherTabInOtherConfigIsActivated() {
final ILaunchConfigurationTab[] tabs = runOnDialog(setActiveTab);

assertThat(((SpyTab) tabs[0])).matches(not(SpyTab::isActivated), "should not have been activated");

// No tab should have been deactivated in the 2nd configuration
for (ILaunchConfigurationTab tab : tabs) {
assertThat(((SpyTab) tab)).matches(not(SpyTab::isDeactivated), "should not have been deactivated");
}

assertThat(((SpyTab) tabs[secondTabIndex])).matches(SpyTab::isActivated, "should have been activated");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@
*/
public abstract class SpyTab extends AbstractLaunchConfigurationTab {

private boolean initialized;
private boolean activated;
private int initializedCount;
private int activatedCount;
private int deactivatedCount;

@Override
public String toString() {
return getClass().getSimpleName() + " [initialized=" + initialized + ", activated=" + activated + "]";
return getClass().getSimpleName() + " [initializedCount=" + initializedCount + ", activatedCount=" + activatedCount + ", deactivatedCount=" + deactivatedCount + "]";
}

@Override
Expand All @@ -41,12 +42,12 @@ public String getName() {

@Override
public void initializeFrom(ILaunchConfiguration configuration) {
initialized = true;
++initializedCount;
}

@Override
public void activated(ILaunchConfigurationWorkingCopy workingCopy) {
activated = true;
++activatedCount;
}

@Override
Expand All @@ -58,11 +59,27 @@ public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
}

public boolean isInitialized() {
return initialized;
return initializedCount > 0;
}

public boolean isInitializedExactlyOnce() {
return initializedCount == 1;
}

public boolean isActivated() {
return activated;
return activatedCount > 0;
}

public boolean isActivatedExactlyOnce() {
return activatedCount == 1;
}

public boolean isDeactivated() {
return deactivatedCount > 0;
}

public boolean isDeactivatedExactlyOnce() {
return deactivatedCount == 1;
}

// These are necessary because I need several tabs in the launch config and
Expand Down

0 comments on commit 0142df2

Please sign in to comment.