From 4459e822f2338f08180fbf4522d53800f0af18dd Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Thu, 18 Jun 2015 13:06:20 +0300 Subject: [PATCH 1/2] Cleanup (assertions; junk comments) --- .../intellij/debugger/DebuggerTestCase.java | 68 +++++++------------ 1 file changed, 23 insertions(+), 45 deletions(-) diff --git a/java/testFramework/src/com/intellij/debugger/DebuggerTestCase.java b/java/testFramework/src/com/intellij/debugger/DebuggerTestCase.java index c94b71966ad3..f96692d3744f 100644 --- a/java/testFramework/src/com/intellij/debugger/DebuggerTestCase.java +++ b/java/testFramework/src/com/intellij/debugger/DebuggerTestCase.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -69,12 +69,6 @@ import java.util.StringTokenizer; public abstract class DebuggerTestCase extends ExecutionWithDebuggerToolsTestCase { protected DebuggerSession myDebuggerSession; - private StringBuffer myConsoleBuffer; - - @Override - protected void setUp() throws Exception { - super.setUp(); - } @Override protected void initApplication() throws Exception { @@ -97,11 +91,6 @@ public abstract class DebuggerTestCase extends ExecutionWithDebuggerToolsTestCas assertNull(DebuggerManagerEx.getInstanceEx(myProject).getDebugProcess(getDebugProcess().getProcessHandler())); myDebuggerSession = null; } - if(myConsoleBuffer != null) { - //println("", b); - //println("Console output:", b); - //println(myConsoleBuffer.toString(), b); - } checkTestOutput(); } @@ -121,7 +110,6 @@ public abstract class DebuggerTestCase extends ExecutionWithDebuggerToolsTestCas @Override protected void tearDown() throws Exception { FileEditorManagerEx.getInstanceEx(getProject()).closeAllFiles(); - myConsoleBuffer = null; super.tearDown(); } @@ -180,12 +168,9 @@ public abstract class DebuggerTestCase extends ExecutionWithDebuggerToolsTestCas }, ModalityState.defaultModalityState()); myDebugProcess = myDebuggerSession.getProcess(); - //myConsoleBuffer = new StringBuffer(); - myDebugProcess.addProcessListener(new ProcessAdapter() { @Override public void onTextAvailable(ProcessEvent event, Key outputType) { - //myConsoleBuffer.append(event.getText()); print(event.getText(), outputType); } }); @@ -330,6 +315,7 @@ public abstract class DebuggerTestCase extends ExecutionWithDebuggerToolsTestCas @Override public PsiFile compute() { PsiClass psiClass = JavaPsiFacade.getInstance(myProject).findClass(className, GlobalSearchScope.allScope(myProject)); + assertNotNull(psiClass); return psiClass.getContainingFile(); } }); @@ -339,10 +325,9 @@ public abstract class DebuggerTestCase extends ExecutionWithDebuggerToolsTestCas protected EvaluationContextImpl createEvaluationContext(final SuspendContextImpl suspendContext) { try { - return new EvaluationContextImpl( - suspendContext, - suspendContext.getFrameProxy(), - suspendContext.getFrameProxy().thisObject()); + StackFrameProxyImpl proxy = suspendContext.getFrameProxy(); + assertNotNull(proxy); + return new EvaluationContextImpl(suspendContext, proxy, proxy.thisObject()); } catch (EvaluateException e) { error(e); @@ -440,6 +425,7 @@ public abstract class DebuggerTestCase extends ExecutionWithDebuggerToolsTestCas public void run() { BreakpointManager breakpointManager = DebuggerManagerEx.getInstanceEx(myProject).getBreakpointManager(); PsiClass psiClass = JavaPsiFacade.getInstance(myProject).findClass("HelloWorld", GlobalSearchScope.allScope(myProject)); + assertNotNull(psiClass); Document document = PsiDocumentManager.getInstance(myProject).getDocument(psiClass.getContainingFile()); breakpointManager.addLineBreakpoint(document, 3); } @@ -481,33 +467,31 @@ public abstract class DebuggerTestCase extends ExecutionWithDebuggerToolsTestCas @Override @NotNull public Module[] getModules() { - return Module.EMPTY_ARRAY; //To change body of implemented methods use File | Settings | File Templates. + return Module.EMPTY_ARRAY; } @Override public Icon getIcon() { - return null; //To change body of implemented methods use File | Settings | File Templates. + return null; } @Override public ConfigurationFactory getFactory() { - return null; //To change body of implemented methods use File | Settings | File Templates. + return null; } @Override - public void setName(final String name) { - //To change body of implemented methods use File | Settings | File Templates. - } + public void setName(String name) { } @NotNull @Override public SettingsEditor getConfigurationEditor() { - return null; //To change body of implemented methods use File | Settings | File Templates. + throw new UnsupportedOperationException(); } @Override public Project getProject() { - return null; //To change body of implemented methods use File | Settings | File Templates. + return null; } @Override @@ -517,18 +501,18 @@ public abstract class DebuggerTestCase extends ExecutionWithDebuggerToolsTestCas } @Override - public ConfigurationPerRunnerSettings createRunnerSettings(final ConfigurationInfoProvider provider) { - return null; //To change body of implemented methods use File | Settings | File Templates. + public ConfigurationPerRunnerSettings createRunnerSettings(ConfigurationInfoProvider provider) { + return null; } @Override - public SettingsEditor getRunnerSettingsEditor(final ProgramRunner runner) { - return null; //To change body of implemented methods use File | Settings | File Templates. + public SettingsEditor getRunnerSettingsEditor(ProgramRunner runner) { + return null; } @Override public RunConfiguration clone() { - return null; //To change body of implemented methods use File | Settings | File Templates. + return null; } @Override @@ -537,28 +521,22 @@ public abstract class DebuggerTestCase extends ExecutionWithDebuggerToolsTestCas } @Override - public RunProfileState getState(@NotNull final Executor executor, @NotNull final ExecutionEnvironment env) throws ExecutionException { - return null; //To change body of implemented methods use File | Settings | File Templates. + public RunProfileState getState(@NotNull Executor executor, @NotNull ExecutionEnvironment env) throws ExecutionException { + return null; } @Override public String getName() { - return ""; //To change body of implemented methods use File | Settings | File Templates. + return ""; } @Override - public void checkConfiguration() throws RuntimeConfigurationException { - //To change body of implemented methods use File | Settings | File Templates. - } + public void checkConfiguration() throws RuntimeConfigurationException { } @Override - public void readExternal(final Element element) throws InvalidDataException { - //To change body of implemented methods use File | Settings | File Templates. - } + public void readExternal(Element element) throws InvalidDataException { } @Override - public void writeExternal(final Element element) throws WriteExternalException { - //To change body of implemented methods use File | Settings | File Templates. - } + public void writeExternal(Element element) throws WriteExternalException { } } } From 31898190f06db89cf9c7d3a836c61f290b424843 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Thu, 18 Jun 2015 13:11:09 +0300 Subject: [PATCH 2/2] tests: utility method moved to a more accessible place; duplicated code dropped --- .../src}/com/intellij/JavaTestUtil.java | 20 +++++------ .../intellij/debugger/DebuggerTestCase.java | 3 +- .../ExecutionWithDebuggerToolsTestCase.java | 34 ++----------------- 3 files changed, 14 insertions(+), 43 deletions(-) rename java/{java-tests/testSrc => testFramework/src}/com/intellij/JavaTestUtil.java (83%) diff --git a/java/java-tests/testSrc/com/intellij/JavaTestUtil.java b/java/testFramework/src/com/intellij/JavaTestUtil.java similarity index 83% rename from java/java-tests/testSrc/com/intellij/JavaTestUtil.java rename to java/testFramework/src/com/intellij/JavaTestUtil.java index 4dfce7cc9438..6e75f5193329 100644 --- a/java/java-tests/testSrc/com/intellij/JavaTestUtil.java +++ b/java/testFramework/src/com/intellij/JavaTestUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,6 +29,7 @@ import com.intellij.openapi.util.text.StringUtil; * @author Konstantin Bulenkov */ public class JavaTestUtil { + private static final String TEST_JDK_NAME = "JDK"; public static String getJavaTestDataPath() { return PathManagerEx.getTestDataPath(); @@ -43,12 +44,14 @@ public class JavaTestUtil { ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { - Sdk jdk = ProjectJdkTable.getInstance().findJdk("JDK"); + ProjectJdkTable jdkTable = ProjectJdkTable.getInstance(); + + Sdk jdk = jdkTable.findJdk(TEST_JDK_NAME); if (jdk != null) { - ProjectJdkTable.getInstance().removeJdk(jdk); + jdkTable.removeJdk(jdk); } - ProjectJdkTable.getInstance().addJdk(getTestJdk()); + jdkTable.addJdk(getTestJdk()); } }); } @@ -56,14 +59,11 @@ public class JavaTestUtil { public static Sdk getTestJdk() { try { ProjectJdkImpl jdk = (ProjectJdkImpl)JavaAwareProjectJdkTableImpl.getInstanceEx().getInternalJdk().clone(); - jdk.setName("JDK"); + jdk.setName(TEST_JDK_NAME); return jdk; } catch (CloneNotSupportedException e) { - //LOG.error(e); - return null; + throw new RuntimeException(e); } } - - -} +} \ No newline at end of file diff --git a/java/testFramework/src/com/intellij/debugger/DebuggerTestCase.java b/java/testFramework/src/com/intellij/debugger/DebuggerTestCase.java index f96692d3744f..b05fd4bfbb51 100644 --- a/java/testFramework/src/com/intellij/debugger/DebuggerTestCase.java +++ b/java/testFramework/src/com/intellij/debugger/DebuggerTestCase.java @@ -15,6 +15,7 @@ */ package com.intellij.debugger; +import com.intellij.JavaTestUtil; import com.intellij.debugger.engine.DebugProcessImpl; import com.intellij.debugger.engine.JavaDebugProcess; import com.intellij.debugger.engine.RemoteStateState; @@ -73,7 +74,7 @@ public abstract class DebuggerTestCase extends ExecutionWithDebuggerToolsTestCas @Override protected void initApplication() throws Exception { super.initApplication(); - setTestJDK(); + JavaTestUtil.setupTestJDK(); DebuggerSettings.getInstance().DEBUGGER_TRANSPORT = DebuggerSettings.SOCKET_TRANSPORT; DebuggerSettings.getInstance().SKIP_CONSTRUCTORS = false; DebuggerSettings.getInstance().SKIP_GETTERS = false; diff --git a/java/testFramework/src/com/intellij/debugger/ExecutionWithDebuggerToolsTestCase.java b/java/testFramework/src/com/intellij/debugger/ExecutionWithDebuggerToolsTestCase.java index e1ab9ff4e3cf..653a11879d00 100644 --- a/java/testFramework/src/com/intellij/debugger/ExecutionWithDebuggerToolsTestCase.java +++ b/java/testFramework/src/com/intellij/debugger/ExecutionWithDebuggerToolsTestCase.java @@ -36,10 +36,6 @@ import com.intellij.execution.process.ProcessOutputTypes; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.editor.Document; -import com.intellij.openapi.projectRoots.ProjectJdkTable; -import com.intellij.openapi.projectRoots.Sdk; -import com.intellij.openapi.projectRoots.impl.JavaAwareProjectJdkTableImpl; -import com.intellij.openapi.projectRoots.impl.ProjectJdkImpl; import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.PsiDocumentManager; import com.intellij.psi.PsiFile; @@ -400,33 +396,7 @@ public abstract class ExecutionWithDebuggerToolsTestCase extends ExecutionTestCa } } - private Sdk getTestJdk() { - try { - ProjectJdkImpl jdk = (ProjectJdkImpl)JavaAwareProjectJdkTableImpl.getInstanceEx().getInternalJdk().clone(); - jdk.setName("JDK"); - return jdk; - } - catch (CloneNotSupportedException e) { - LOG.error(e); - return null; - } - } - - protected void setTestJDK() { - ApplicationManager.getApplication().runWriteAction(new Runnable() { - @Override - public void run() { - Sdk jdk = ProjectJdkTable.getInstance().findJdk("JDK"); - if (jdk != null) { - ProjectJdkTable.getInstance().removeJdk(jdk); - } - - ProjectJdkTable.getInstance().addJdk(getTestJdk()); - } - }); - } - - private class DelayedEventsProcessListener implements DebugProcessListener { + private static class DelayedEventsProcessListener implements DebugProcessListener { private final DebugProcessAdapterImpl myTarget; public DelayedEventsProcessListener(DebugProcessAdapterImpl target) { @@ -473,7 +443,7 @@ public abstract class ExecutionWithDebuggerToolsTestCase extends ExecutionTestCa myTarget.attachException(state, exception, remoteConnection); } - private void pauseExecution() { + private static void pauseExecution() { TimeoutUtil.sleep(10); } }