diff options
author | dbranekov | 2013-02-11 14:45:43 +0000 |
---|---|---|
committer | dbranekov | 2013-02-11 14:45:43 +0000 |
commit | 8e218f42bf6f48378014692c4e7b2a2103127a42 (patch) | |
tree | 5cee2e68d9caa97a08c358d7b612c3e67609af1e | |
parent | 41165fdba2fce7d619283f9418c423f9d61f94a1 (diff) | |
download | org.eclipse.e4.search-8e218f42bf6f48378014692c4e7b2a2103127a42.tar.gz org.eclipse.e4.search-8e218f42bf6f48378014692c4e7b2a2103127a42.tar.xz org.eclipse.e4.search-8e218f42bf6f48378014692c4e7b2a2103127a42.zip |
[bug 400423] Clear selection after deleting a destinationI20130222-1100I20130222-1020I20130222-1000I20130220-1200I20130220-1100I20130219-2200I20130215-1230I20130215-0900I20130214-2200I20130213-0835I20130212-2200I20130212-1030
5 files changed, 62 insertions, 37 deletions
diff --git a/bundles/org.eclipse.platform.discovery.destprefs/src/org/eclipse/platform/discovery/destprefs/internal/prefpage/ui/DestinationConfiguratorsPresenter.java b/bundles/org.eclipse.platform.discovery.destprefs/src/org/eclipse/platform/discovery/destprefs/internal/prefpage/ui/DestinationConfiguratorsPresenter.java index 0d06d14..e574b47 100644 --- a/bundles/org.eclipse.platform.discovery.destprefs/src/org/eclipse/platform/discovery/destprefs/internal/prefpage/ui/DestinationConfiguratorsPresenter.java +++ b/bundles/org.eclipse.platform.discovery.destprefs/src/org/eclipse/platform/discovery/destprefs/internal/prefpage/ui/DestinationConfiguratorsPresenter.java @@ -68,21 +68,21 @@ public class DestinationConfiguratorsPresenter implements IDestinationConfigurat @Override
public void selectionChanged(DestinationConfiguratorSelection selection) {
- ContractChecker.nullCheckParam(selection.destProviderId);
-
- destinationProviderId = selection.destProviderId;
- destination = selection.destination;
-
+ destination = selection.destination;
+ destinationProviderId = selection.destProviderId;
+ if(destination != null) {
+ ContractChecker.nullCheckField(destinationProviderId, "destinationProviderId");
+ }
+
+ view.setAddEnabled(destinationProviderId != null);
if(destination==null) {
- view.setAddEnabled(true);
view.setEditEnabled(false);
view.setRemoveEnabled(false);
view.setTestEnabled(false);
} else{
- view.setAddEnabled(true);
view.setEditEnabled(true);
view.setRemoveEnabled(true);
- view.setTestEnabled(getConfigDescription(destinationProviderId).createConfigurator().getSearchDestinationTester()!=null);
+ view.setTestEnabled(getConfigDescription(destinationProviderId).createConfigurator().getSearchDestinationTester()!=null);
}
}
@@ -140,5 +140,4 @@ public class DestinationConfiguratorsPresenter implements IDestinationConfigurat IStatus result = tester.test(view.getShell(), (T)destination);
view.setStatus(result);
}
-
}
diff --git a/bundles/org.eclipse.platform.discovery.destprefs/src/org/eclipse/platform/discovery/destprefs/internal/prefpage/ui/DestinationsPreferencePage.java b/bundles/org.eclipse.platform.discovery.destprefs/src/org/eclipse/platform/discovery/destprefs/internal/prefpage/ui/DestinationsPreferencePage.java index 264d061..76149a4 100644 --- a/bundles/org.eclipse.platform.discovery.destprefs/src/org/eclipse/platform/discovery/destprefs/internal/prefpage/ui/DestinationsPreferencePage.java +++ b/bundles/org.eclipse.platform.discovery.destprefs/src/org/eclipse/platform/discovery/destprefs/internal/prefpage/ui/DestinationsPreferencePage.java @@ -112,6 +112,7 @@ public class DestinationsPreferencePage extends PreferencePage implements IWorkb @Override public void selectionChanged(final SelectionChangedEvent event) { if (event.getSelection().isEmpty()) { + presenter.selectionChanged(new DestinationConfiguratorSelection(null, null)); return; } diff --git a/tests/org.eclipse.platform.discovery.destprefs.test.unit/META-INF/MANIFEST.MF b/tests/org.eclipse.platform.discovery.destprefs.test.unit/META-INF/MANIFEST.MF index 901003b..d08a750 100644 --- a/tests/org.eclipse.platform.discovery.destprefs.test.unit/META-INF/MANIFEST.MF +++ b/tests/org.eclipse.platform.discovery.destprefs.test.unit/META-INF/MANIFEST.MF @@ -19,4 +19,5 @@ Require-Bundle: org.junit, org.eclipse.platform.discovery.util, org.eclipse.ui, org.eclipse.ui.forms, - org.eclipse.swtbot.eclipse.finder + org.eclipse.swtbot.eclipse.finder, + org.apache.log4j diff --git a/tests/org.eclipse.platform.discovery.destprefs.test.unit/src/org/eclipse/platform/discovery/destprefs/test/unit/prefpage/DestinationConfiguratorsPresenterTest.java b/tests/org.eclipse.platform.discovery.destprefs.test.unit/src/org/eclipse/platform/discovery/destprefs/test/unit/prefpage/DestinationConfiguratorsPresenterTest.java index ac06d8a..746bff3 100644 --- a/tests/org.eclipse.platform.discovery.destprefs.test.unit/src/org/eclipse/platform/discovery/destprefs/test/unit/prefpage/DestinationConfiguratorsPresenterTest.java +++ b/tests/org.eclipse.platform.discovery.destprefs.test.unit/src/org/eclipse/platform/discovery/destprefs/test/unit/prefpage/DestinationConfiguratorsPresenterTest.java @@ -183,7 +183,15 @@ public class DestinationConfiguratorsPresenterTest { Mockito.verify(expectedConfigurator).deleteDestination(Mockito.same(viewShell), Mockito.same(fixture.destination1));
Mockito.verify(view).setStatus(Mockito.same(result));
Mockito.verify(view, Mockito.times(2)).setInput(Mockito.argThat(matchesFixture()));
-
+ }
+
+ @Test
+ public void testClearSelection() {
+ presenter.selectionChanged(new DestinationConfiguratorSelection(null, null));
+ Mockito.verify(view).setAddEnabled(Mockito.eq(false));
+ Mockito.verify(view).setEditEnabled(Mockito.eq(false));
+ Mockito.verify(view).setRemoveEnabled(Mockito.eq(false));
+ Mockito.verify(view).setTestEnabled(Mockito.eq(false));
}
@Test
diff --git a/tests/org.eclipse.platform.discovery.destprefs.test.unit/src/org/eclipse/platform/discovery/destprefs/test/unit/prefpage/ui/DestinationsPreferencePageTest.java b/tests/org.eclipse.platform.discovery.destprefs.test.unit/src/org/eclipse/platform/discovery/destprefs/test/unit/prefpage/ui/DestinationsPreferencePageTest.java index d9c83dc..67591b9 100644 --- a/tests/org.eclipse.platform.discovery.destprefs.test.unit/src/org/eclipse/platform/discovery/destprefs/test/unit/prefpage/ui/DestinationsPreferencePageTest.java +++ b/tests/org.eclipse.platform.discovery.destprefs.test.unit/src/org/eclipse/platform/discovery/destprefs/test/unit/prefpage/ui/DestinationsPreferencePageTest.java @@ -47,7 +47,7 @@ public class DestinationsPreferencePageTest { private static final String DESTINATION_PROVIDER_ID = "my.dest.provider.id"; private static final String DESTINATION_NAME = "My Destination"; private String currentDestinationName; - + private DestinationsPreferencePagePageObject pageObject; @Mock private IDestinationConfiguratorsPresenter presenter; @@ -65,7 +65,9 @@ public class DestinationsPreferencePageTest { MockitoAnnotations.initMocks(this); stubDestinations(); pageObject = new DestinationsPreferencePagePageObject(presenter); - + + pageObject.open(); + pageObject.setInput(createPageInput()); Mockito.doAnswer(new Answer<Void>() { @Override public Void answer(InvocationOnMock invocation) throws Throwable { @@ -76,9 +78,7 @@ public class DestinationsPreferencePageTest { return null; } }).when(presenter).selectionChanged(Mockito.any(DestinationConfiguratorSelection.class)); - - pageObject.open(); - pageObject.setInput(createPageInput()); + } private void stubDestinations() { @@ -89,7 +89,8 @@ public class DestinationsPreferencePageTest { return currentDestinationName; } }); - Mockito.stub(destinationProvider.getSearchDestinations()).toReturn(new HashSet<ISearchDestination>(Arrays.asList(new ISearchDestination[]{destination}))); + Mockito.stub(destinationProvider.getSearchDestinations()).toReturn( + new HashSet<ISearchDestination>(Arrays.asList(new ISearchDestination[] { destination }))); Mockito.stub(destinationProviderDescr.createProvider()).toReturn(destinationProvider); Mockito.stub(destinationProviderDescr.getId()).toReturn(DESTINATION_PROVIDER_ID); Mockito.stub(category.getId()).toReturn(CATEGORY_ID); @@ -158,7 +159,7 @@ public class DestinationsPreferencePageTest { public void testSetOkStatus() throws InterruptedException { setStatusTest(createStatus(IStatus.OK, "Success")); } - + @Test public void testSelectCategory() { pageObject.getCategory(CATEGORY_NAME).select(); @@ -170,24 +171,24 @@ public class DestinationsPreferencePageTest { selectTheDestination(); Mockito.verify(presenter, Mockito.atLeastOnce()).selectionChanged(Mockito.argThat(selectionMatcher(DESTINATION_PROVIDER_ID, destination))); } - + @Test public void testAddDestination() { selectTheDestination(); Mockito.doAnswer(new Answer<Void>() { @Override public Void answer(InvocationOnMock invocation) throws Throwable { - pageObject.setInput(createPageInput()); + pageObject.setInput(createPageInput()); return null; } }).when(presenter).addDestination(); - + pageObject.addDestination(); Mockito.verify(presenter).addDestination(); assertCategoryIsExpanded(); assertDestinationIsSelected(DESTINATION_NAME); } - + @Test public void testEditDestination() { selectTheDestination(); @@ -196,11 +197,11 @@ public class DestinationsPreferencePageTest { @Override public Void answer(InvocationOnMock invocation) throws Throwable { currentDestinationName = newDestinationName; - pageObject.setInput(createPageInput()); + pageObject.setInput(createPageInput()); return null; } }).when(presenter).editDestination(); - + pageObject.editDestination(); Mockito.verify(presenter).editDestination(); @@ -212,65 +213,80 @@ public class DestinationsPreferencePageTest { final CategoryPageObject category = pageObject.getCategory(CATEGORY_NAME); assertTrue("Category does not display destinations after edit", category.isDestinationsVisible()); } - + private void assertDestinationIsSelected(final String destinationName) { final DestinationPageObject destination = pageObject.getCategory(CATEGORY_NAME).getDestination(destinationName); assertTrue("Destination is not selected", destination.isSelected()); } - + @Test public void testRemoveDestination() { selectTheDestination(); Mockito.doAnswer(new Answer<Void>() { @Override public Void answer(InvocationOnMock invocation) throws Throwable { - pageObject.setInput(createPageInput()); + pageObject.setInput(createPageInput()); return null; } }).when(presenter).removeDestination(); - + pageObject.removeDestination(); Mockito.verify(presenter).removeDestination(); assertCategoryIsExpanded(); + Mockito.verify(presenter).selectionChanged(Mockito.argThat(emptySelectionMatcher())); + } - + + private Matcher<DestinationConfiguratorSelection> emptySelectionMatcher() { + return new BaseMatcher<DestinationConfiguratorSelection>() { + @Override + public boolean matches(Object item) { + final DestinationConfiguratorSelection selection = (DestinationConfiguratorSelection) item; + return selection.destination == null && selection.destProviderId == null; + } + + @Override + public void describeTo(Description description) { + } + }; + } + @Test public void testTestDestination() { selectTheDestination(); pageObject.testDestination(); Mockito.verify(presenter).testDestination(); } - + @Test public void testSelectionPreservedOnDestinationEdit() { selectTheDestination(); final String newDestinationName = "ModifiedDestinationName"; - + Mockito.doAnswer(new Answer<Void>() { @Override public Void answer(InvocationOnMock invocation) throws Throwable { currentDestinationName = newDestinationName; - pageObject.setInput(createPageInput()); + pageObject.setInput(createPageInput()); return null; } }).when(presenter).editDestination(); pageObject.editDestination(); - final DestinationPageObject selectedDestination = pageObject.getCategory(CATEGORY_NAME).getDestination(newDestinationName); assertTrue("Modified destination lost its selection", selectedDestination.isSelected()); } - + private void selectTheDestination() { pageObject.getCategory(CATEGORY_NAME).getDestination(DESTINATION_NAME).select(); } - + private Matcher<DestinationConfiguratorSelection> selectionMatcher(String destinationProviderId, final ISearchDestination destination) { return new BaseMatcher<DestinationConfiguratorSelection>() { @Override public boolean matches(Object item) { - final DestinationConfiguratorSelection selection = (DestinationConfiguratorSelection)item; - return selection.destProviderId.equals(DESTINATION_PROVIDER_ID) && (selection.destination == destination); + final DestinationConfiguratorSelection selection = (DestinationConfiguratorSelection) item; + return selection.destProviderId != null && selection.destProviderId.equals(DESTINATION_PROVIDER_ID) && (selection.destination == destination); } @Override |