IDEA-161498 Several errors in maven integration plugin

This commit is contained in:
Denis Fokin
2016-09-26 17:05:22 +03:00
parent e4082dec4f
commit 0a17ed74ca
2 changed files with 55 additions and 0 deletions
@@ -104,6 +104,10 @@ public class LaterInvocator {
}
}
public static void removeModalityStateListener(@NotNull ModalityStateListener listener) {
ourModalityStateMulticaster.removeListener(listener);
}
@NotNull
static ModalityStateEx modalityStateForWindow(@NotNull Window window) {
int index = ourModalEntities.indexOf(window);
@@ -224,6 +228,8 @@ public class LaterInvocator {
return;
}
ourModalityStateMulticaster.getMulticaster().beforeModalityStateChanged(true);
List<Dialog> modalEntitiesList = projectToModalEntities.getOrDefault(project, ContainerUtil.createLockFreeCopyOnWriteList());
projectToModalEntities.put(project, modalEntitiesList);
modalEntitiesList.add(dialog);
@@ -15,15 +15,20 @@
*/
package com.intellij.openapi.application.impl;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.application.ModalityState;
import com.intellij.openapi.application.ModalityStateListener;
import com.intellij.testFramework.PlatformTestCase;
import com.intellij.testFramework.SkipInHeadlessEnvironment;
import com.intellij.util.containers.*;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import java.awt.*;
import java.util.*;
import java.util.HashMap;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Consumer;
import static com.intellij.openapi.application.impl.LaterInvocator.enterModal;
@@ -165,6 +170,50 @@ public class PerProjectLaterInvocatorTest extends PlatformTestCase {
.continueEDT()
.ifExceptions(exception -> fail(exception.toString()));
}
public void testModalityStateChangedListener () {
boolean [] enteringOrder = new boolean [] {true, true, false, false};
AtomicInteger enteringIndex = new AtomicInteger(-1);
ModalityStateListener modalityStateListener = entering -> {
if (entering != enteringOrder[enteringIndex.incrementAndGet()])
throw new RuntimeException("Trying to enter a modal state. Wrong order of the modalityStateListener invocations. Step #" + enteringIndex.get());
};
Disposable emptyDisposal = () -> {};
LaterInvocator.addModalityStateListener(modalityStateListener, emptyDisposal);
Runnable removeModalityListener = () -> {
LaterInvocator.removeModalityStateListener(modalityStateListener);
};
Testable.creatTestable()
.suspendEDT()
.execute(() -> invokeLater(NumberedRunnable.withNumber(1), ModalityState.NON_MODAL))
.flushEDT()
.execute(() -> enterModal(myApplicationModalDialog))
.flushEDT()
.execute(() -> invokeLater(NumberedRunnable.withNumber(2), ModalityState.current()))
.flushEDT()
.execute(() -> enterModal(myProject, myPerProjectModalDialog))
.flushEDT()
.execute(() -> invokeLater(NumberedRunnable.withNumber(3), ModalityState.NON_MODAL))
.flushEDT()
.execute(() -> invokeLater(NumberedRunnable.withNumber(4), ModalityState.current()))
.flushEDT()
.execute(() -> leaveModal(myProject, myPerProjectModalDialog))
.flushEDT()
.execute(() -> invokeLater(NumberedRunnable.withNumber(5), ModalityState.NON_MODAL))
.flushEDT()
.execute(() -> leaveModal(myApplicationModalDialog))
.flushEDT()
.continueEDT()
.execute(removeModalityListener)
.ifExceptions(exception -> fail(exception.toString()));
}
}