SidePanel extends JPanel implements SideModel.Listener<T> { @Override public void modelChanged(@NotNull SideModel<T> model, @NotNull SideModel.EventType unused) { myCards.removeAll(); myCards.add(mySplitter, SPLITTER); myCards.add(myEmpty, EMPTY); addVisibleTools(model.getVisibleTools(mySide)); addHiddenTools(model.getHiddenTools(mySide)); revalidate(); repaint(); } SidePanel(@NotNull Side side, @NotNull SideModel<T> model); @Override void modelChanged(@NotNull SideModel<T> model, @NotNull SideModel.EventType unused);  }
@Test public void testNoVisibleTools() { when(myModel.getVisibleTools(Side.LEFT)).thenReturn(Collections.emptyList()); when(myModel.getHiddenTools(Side.LEFT)).thenReturn(ImmutableList.of(myToolWindow1, myToolWindow2)); myPanel.modelChanged(myModel, SideModel.EventType.LOCAL_UPDATE); assertThat(myPanel.isVisible()).isFalse(); assertThat(findHiddenComponents()).containsAllOf(myToolWindowComponent1, myToolWindowComponent2); }
@Test public void testOneVisibleTool() { when(myModel.getVisibleTools(Side.LEFT)).thenReturn(Collections.singletonList(myToolWindow1)); when(myModel.getHiddenTools(Side.LEFT)).thenReturn(ImmutableList.of(myToolWindow2)); myPanel.modelChanged(myModel, SideModel.EventType.LOCAL_UPDATE); assertThat(myPanel.isVisible()).isTrue(); assertThat(findVisibleComponent()).isSameAs(myToolWindowComponent1); assertThat(findHiddenComponents()).contains(myToolWindowComponent2); }
@Test public void testTwoVisibleTools() { when(myModel.getVisibleTools(Side.LEFT)).thenReturn(ImmutableList.of(myToolWindow1, myToolWindow2)); when(myModel.getHiddenTools(Side.LEFT)).thenReturn(Collections.emptyList()); myPanel.modelChanged(myModel, SideModel.EventType.LOCAL_UPDATE); assertThat(myPanel.isVisible()).isTrue(); Component visible = findVisibleComponent(); Splitter splitter = visible instanceof Splitter ? (Splitter)visible : null; assertThat(splitter).isNotNull(); assertThat(splitter.getFirstComponent()).isEqualTo(myToolWindowComponent1); assertThat(splitter.getSecondComponent()).isEqualTo(myToolWindowComponent2); assertThat(findHiddenComponents()).containsNoneOf(myToolWindowComponent1, myToolWindowComponent2); }