Skip to content

Commit

Permalink
Fix tests in LaunchConfigurationTabGroupViewerTest eclipse-platform#1075
Browse files Browse the repository at this point in the history


- Check for the activation (instead of the initialization) of other tabs
testOnlyDefaultTabInOtherConfigIsActivated and
reactivate the test.
- Provide meaningful toString() method for SpyTab to improve assertion
messages.
- Use extra parameter when calling the "matches" method to improve
readability

Fixes eclipse-platform#1075
  • Loading branch information
fedejeanne committed Mar 27, 2024
1 parent f17f1a1 commit ead8cf6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.eclipse.debug.ui.ILaunchConfigurationTabGroup;
import org.eclipse.swt.widgets.Display;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;

public class LaunchConfigurationTabGroupViewerTest {
Expand Down Expand Up @@ -70,8 +69,8 @@ public void testAllTabsAreInitializedByDefault() {

final ILaunchConfigurationTab[] tabs = runOnDialog(createAndSelect1LaunchConfig);

for (int i = 0; i < tabs.length; i++) {
assertThat(((SpyTab) tabs[i])).withFailMessage("tab %s was not initialized", i).matches(SpyTab::isInitialized);
for (ILaunchConfigurationTab tab : tabs) {
assertThat(((SpyTab) tab)).matches(SpyTab::isInitialized, "should have been initialized");
}
}

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

final ILaunchConfigurationTab[] tabs = runOnDialog(createAndSelect1LaunchConfig);
assertThat(((SpyTab) tabs[0])).matches(SpyTab::isActivated, "is activated");
assertThat(((SpyTab) tabs[0])).matches(SpyTab::isActivated, "should have been activated");
}

@Test
Expand All @@ -104,12 +103,11 @@ public void testOtherTabInOtherConfigIsActivated() {

final ILaunchConfigurationTab[] tabs = runOnDialog(setActiveTab);

assertThat((SpyTab) tabs[0]).withFailMessage("the 1st tab of the other launch configuration shouldn't have been activated").matches(not(SpyTab::isActivated));
assertThat((SpyTab) tabs[secondTabIndex]).matches(SpyTab::isActivated, "is activated");
assertThat(((SpyTab) tabs[0])).matches(not(SpyTab::isActivated), "should not have been activated");
assertThat(((SpyTab) tabs[secondTabIndex])).matches(SpyTab::isActivated, "should have been activated");
}

@Test
@Ignore("https://github.com/eclipse-platform/eclipse.platform/issues/1075")
public void testOnlyDefaultTabInOtherConfigIsActivated() {
int overflowTabIndex = Integer.MAX_VALUE;

Expand All @@ -127,11 +125,13 @@ public void testOnlyDefaultTabInOtherConfigIsActivated() {

final ILaunchConfigurationTab[] tabs = runOnDialog(setActiveTab);

assertThat(((SpyTab) tabs[0])).withFailMessage("the 1st tab of the other launch configuration should have been activated").matches(SpyTab::isActivated);
// The 1st tab of the other launch configuration should have been
// activated
assertThat(((SpyTab) tabs[0])).matches(SpyTab::isActivated, "Should have been activated");

// All other tabs should not have been initialized
// All other tabs should not have been activated
for (int i = 1; i < tabs.length; i++) {
assertThat((SpyTab) tabs[i]).withFailMessage("tab %s should not have been initialized", i).matches(not(SpyTab::isInitialized));
assertThat(((SpyTab) tabs[i])).matches(not(SpyTab::isActivated), "Should not have been activated");
}
}

Expand All @@ -149,7 +149,7 @@ public void testOtherTabIsActivated() {

final ILaunchConfigurationTab[] tabs = runOnDialog(setActiveTab);

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

private ILaunchConfigurationWorkingCopy createLaunchConfigurationInstance() throws CoreException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ public abstract class SpyTab extends AbstractLaunchConfigurationTab {
private boolean initialized;
private boolean activated;

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

@Override
public void createControl(Composite parent) {
}
Expand Down

0 comments on commit ead8cf6

Please sign in to comment.