From d5d38e8a70eddb1b3dadc3f447c655b1fe7ed396 Mon Sep 17 00:00:00 2001 From: "Vassiliy.Kudryashov" Date: Tue, 4 Jul 2017 18:09:42 +0300 Subject: [PATCH] Test for FindUIHelper --- .../intellij/find/impl/FindPopupPanel.java | 1 + .../com/intellij/find/impl/FindUIHelper.java | 5 +- .../intellij/find/impl/FindUIHelperTest.java | 66 +++++++++++++++++++ 3 files changed, 69 insertions(+), 3 deletions(-) create mode 100644 platform/lang-impl/testSources/com/intellij/find/impl/FindUIHelperTest.java diff --git a/platform/lang-impl/src/com/intellij/find/impl/FindPopupPanel.java b/platform/lang-impl/src/com/intellij/find/impl/FindPopupPanel.java index 05b008b15526..b2592c7783e4 100644 --- a/platform/lang-impl/src/com/intellij/find/impl/FindPopupPanel.java +++ b/platform/lang-impl/src/com/intellij/find/impl/FindPopupPanel.java @@ -383,6 +383,7 @@ public class FindPopupPanel extends JBPanel implements FindUI, DataProvider { public void update(@NotNull AnActionEvent e) { super.update(e); e.getPresentation().setEnabled(myHelper.getModel().isOpenInNewTabEnabled()); + e.getPresentation().setVisible(myHelper.getModel().isOpenInNewTabVisible()); } }); tabResultsContextGroup.setPopup(true); diff --git a/platform/lang-impl/src/com/intellij/find/impl/FindUIHelper.java b/platform/lang-impl/src/com/intellij/find/impl/FindUIHelper.java index 641023d5ab3e..181d572324b9 100644 --- a/platform/lang-impl/src/com/intellij/find/impl/FindUIHelper.java +++ b/platform/lang-impl/src/com/intellij/find/impl/FindUIHelper.java @@ -177,9 +177,8 @@ public class FindUIHelper implements Disposable { } void setUseSeparateView(boolean separateView) { - if (myModel.isOpenInNewTabEnabled()) { - myModel.setOpenInNewTab(separateView); - } + if (!myModel.isOpenInNewTabEnabled()) throw new IllegalStateException("'Open in new Tab' is not enabled"); + myModel.setOpenInNewTab(separateView); FindSettings.getInstance().setShowResultsInSeparateView(separateView); } diff --git a/platform/lang-impl/testSources/com/intellij/find/impl/FindUIHelperTest.java b/platform/lang-impl/testSources/com/intellij/find/impl/FindUIHelperTest.java new file mode 100644 index 000000000000..6d386df6198a --- /dev/null +++ b/platform/lang-impl/testSources/com/intellij/find/impl/FindUIHelperTest.java @@ -0,0 +1,66 @@ +/* + * Copyright 2000-2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.find.impl; + +import com.intellij.find.FindManager; +import com.intellij.find.FindModel; +import com.intellij.testFramework.LightPlatformTestCase; + +public class FindUIHelperTest extends LightPlatformTestCase { + private static final Runnable STUB = () -> { + }; + + private FindUIHelper myHelper; + private FindManagerImpl myFindManager; + + @Override + protected void setUp() throws Exception { + super.setUp(); + myFindManager = ((FindManagerImpl)FindManager.getInstance(getProject())); + FindModel findModel = FindManager.getInstance(getProject()).getFindInProjectModel(); + myHelper = new FindUIHelper(getProject(), findModel, STUB); + } + + public void testBasic() { + assertFalse(myHelper.getModel().isOpenInNewTabEnabled()); + boolean initialSeparateViewState = myHelper.isUseSeparateView(); + try { + myHelper.setUseSeparateView(!initialSeparateViewState); + fail("There should be an exception"); + } + catch (IllegalStateException e) { + //it's ok + myHelper.getModel().setOpenInNewTabEnabled(true); + myHelper.setUseSeparateView(!initialSeparateViewState); + } + assertNotSame(initialSeparateViewState, myHelper.isUseSeparateView()); + myHelper.setUseSeparateView(initialSeparateViewState); + assertSame(initialSeparateViewState, myHelper.isUseSeparateView()); + + boolean initialSkipResultsWithOneUsage = myHelper.isSkipResultsWithOneUsage(); + myHelper.setSkipResultsWithOneUsage(!initialSkipResultsWithOneUsage); + assertNotSame(initialSeparateViewState, myHelper.isSkipResultsWithOneUsage()); + myHelper.setSkipResultsWithOneUsage(initialSkipResultsWithOneUsage); + assertSame(initialSeparateViewState, myHelper.isSkipResultsWithOneUsage()); + + myFindManager.changeGlobalSettings(myHelper.getModel()); + + FindModel findModel = FindManager.getInstance(getProject()).getFindInProjectModel(); + myHelper = new FindUIHelper(getProject(), findModel, STUB); + assertSame(initialSeparateViewState, myHelper.isUseSeparateView()); + assertSame(initialSeparateViewState, myHelper.isSkipResultsWithOneUsage()); + } +}