Skip to content
This repository has been archived by the owner on Sep 4, 2023. It is now read-only.

Commit

Permalink
fix: fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pas-n committed Mar 15, 2023
1 parent 58eff82 commit 20624e6
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 37 deletions.
6 changes: 3 additions & 3 deletions src/main/java/de/adito/aditoweb/nbm/groupedtabs/NbUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ public static TopComponent getActiveTopComponent()
/**
* Returns a Stream over all TopComponents that are in the same group as {@code pTcWithinMode}
*
* @param pTcWithinMode a TopComponent
* @param pTopComponentWithinMode a TopComponent
* @return Stream of TopComponents inside the mode of {@code pTcWithinMode}
*/
public static Stream<TopComponent> getTopComponentsInMode(@NotNull TopComponent pTcWithinMode)
public static Stream<TopComponent> getTopComponentsInMode(@NotNull TopComponent pTopComponentWithinMode)
{
// get all TopCompoments from each group to find the mode containing pTopComponent
return WindowManager.getDefault().getModes().stream()
Expand All @@ -50,7 +50,7 @@ public static Stream<TopComponent> getTopComponentsInMode(@NotNull TopComponent

// filter if TopComponents contain the current TopComponent
.map(pTcs -> pTcs.collect(Collectors.toList()))
.filter(pTcs -> pTcs.contains(pTcWithinMode))
.filter(pTcs -> pTcs.contains(pTopComponentWithinMode))

// flatmap Stream<List<TopComponent>>
.findFirst()
Expand Down
23 changes: 12 additions & 11 deletions src/test/java/de/adito/aditoweb/nbm/groupedtabs/NbUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import java.util.*;
import java.util.stream.*;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;

/**
Expand All @@ -26,14 +26,15 @@ class NbUtilsTest
@Test
void shouldReturnListOfTopComponentsInMode()
{
final TopComponent tc1inMode1 = mock(TopComponent.class);
final TopComponent tc2InMode1 = mock(TopComponent.class);
final TopComponent firstTcInFirstMode = mock(TopComponent.class);
final TopComponent secondTcInFirstMode = mock(TopComponent.class);
final Mode mode1 = mock(Mode.class);
when(mode1.getTopComponents()).thenReturn(new TopComponent[]{tc1inMode1, tc2InMode1});
when(mode1.getTopComponents()).thenReturn(new TopComponent[]{firstTcInFirstMode, secondTcInFirstMode});

final TopComponent tc1InMode2 = mock(TopComponent.class);
final TopComponent tc2InMode2 = mock(TopComponent.class);
final TopComponent firstTcInSecondMode = mock(TopComponent.class);
final TopComponent secondTcInSecondMode = mock(TopComponent.class);
final Mode mode2 = mock(Mode.class);
when(mode2.getTopComponents()).thenReturn(new TopComponent[]{firstTcInSecondMode, secondTcInSecondMode});

final WindowManager windowManager = mock(WindowManager.class);
//noinspection rawtypes,unchecked
Expand All @@ -43,11 +44,11 @@ void shouldReturnListOfTopComponentsInMode()
{
windowManagerMockedStatic.when(WindowManager::getDefault).thenReturn(windowManager);

Set<TopComponent> tcsInMode1 = NbUtils.getTopComponentsInMode(tc2InMode1).collect(Collectors.toSet());
assertEquals(Set.of(tc1inMode1, tc2InMode1), tcsInMode1);
Set<TopComponent> tcsInMode1 = NbUtils.getTopComponentsInMode(secondTcInFirstMode).collect(Collectors.toSet());
assertEquals(Set.of(firstTcInFirstMode, secondTcInFirstMode), tcsInMode1);

Set<TopComponent> tcsInMode2 = NbUtils.getTopComponentsInMode(tc1InMode2).collect(Collectors.toSet());
assertEquals(Set.of(tc1InMode2, tc2InMode2), tcsInMode2);
Set<TopComponent> tcsInMode2 = NbUtils.getTopComponentsInMode(firstTcInSecondMode).collect(Collectors.toSet());
assertEquals(Set.of(firstTcInSecondMode, secondTcInSecondMode), tcsInMode2);
}
}

Expand Down Expand Up @@ -77,6 +78,6 @@ void shouldResolveDataObjectOfTopComponentWithoutDataObjectCorrectly()
when(tcWithoutDataObject.getLookup()).thenReturn(Lookups.fixed());

List<Pair<TopComponent, DataObject>> grouped = NbUtils.resolveDataObjects(tcWithoutDataObject).collect(Collectors.toList());
assertEquals(List.of(), grouped);
assertTrue(grouped.isEmpty());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,32 +26,32 @@ class CloseGroupActionTest
@Test
void shouldCloseAllTopComponentsInGroup()
{
final DataObject tc1InMode1Do = mock(DataObject.class);
final TopComponent tc1InMode1 = mock(TopComponent.class);
when(tc1InMode1.getLookup()).thenReturn(Lookups.fixed(tc1InMode1Do));
final DataObject firstTcInFirstModeDo = mock(DataObject.class);
final TopComponent firstTcInFirstMode = mock(TopComponent.class);
when(firstTcInFirstMode.getLookup()).thenReturn(Lookups.fixed(firstTcInFirstModeDo));

final Mode mode1 = mock(Mode.class);
when(mode1.getTopComponents()).thenReturn(new TopComponent[]{tc1InMode1});
when(mode1.getTopComponents()).thenReturn(new TopComponent[]{firstTcInFirstMode});


final DataObject tc1InMode2Do = mock(DataObject.class);
final TopComponent tc1InMode2 = mock(TopComponent.class);
when(tc1InMode2.getLookup()).thenReturn(Lookups.fixed(tc1InMode2Do));
final DataObject firstTcInSecondModeDo = mock(DataObject.class);
final TopComponent firstTcInSecondMode = mock(TopComponent.class);
when(firstTcInSecondMode.getLookup()).thenReturn(Lookups.fixed(firstTcInSecondModeDo));

final DataObject tc2InMode2Do = mock(DataObject.class);
final TopComponent tc2InMode2 = mock(TopComponent.class);
when(tc2InMode2.getLookup()).thenReturn(Lookups.fixed(tc2InMode2Do));
final DataObject secondTcInSecondModeDo = mock(DataObject.class);
final TopComponent secondTcInSecondMode = mock(TopComponent.class);
when(secondTcInSecondMode.getLookup()).thenReturn(Lookups.fixed(secondTcInSecondModeDo));

final DataObject tc3InMode2Do = mock(DataObject.class);
final TopComponent tc3InMode2 = mock(TopComponent.class);
when(tc3InMode2.getLookup()).thenReturn(Lookups.fixed(tc3InMode2Do));
final DataObject tc3InSecondModeDo = mock(DataObject.class);
final TopComponent tc3InSecondMode = mock(TopComponent.class);
when(tc3InSecondMode.getLookup()).thenReturn(Lookups.fixed(tc3InSecondModeDo));

final Mode mode2 = mock(Mode.class);
when(mode2.getTopComponents()).thenReturn(new TopComponent[]{tc1InMode2, tc2InMode2, tc3InMode2});
when(mode2.getTopComponents()).thenReturn(new TopComponent[]{firstTcInSecondMode, secondTcInSecondMode, tc3InSecondMode});


final TopComponent.Registry registry = mock(TopComponent.Registry.class);
when(registry.getActivated()).thenReturn(tc2InMode2);
when(registry.getActivated()).thenReturn(secondTcInSecondMode);

final WindowManager windowManager = mock(WindowManager.class);
when(windowManager.getRegistry()).thenReturn(registry);
Expand All @@ -63,10 +63,10 @@ void shouldCloseAllTopComponentsInGroup()
windowManagerMockedStatic.when(WindowManager::getDefault).thenReturn(windowManager);

final IDataObjectGroupProvider groupProvider = mock(IDataObjectGroupProvider.class);
when(groupProvider.group(tc1InMode1Do)).thenReturn(Optional.of("AAA"));
when(groupProvider.group(tc1InMode2Do)).thenReturn(Optional.of("AAA"));
when(groupProvider.group(tc2InMode2Do)).thenReturn(Optional.of("AAA"));
when(groupProvider.group(tc3InMode2Do)).thenReturn(Optional.of("BBB"));
when(groupProvider.group(firstTcInFirstModeDo)).thenReturn(Optional.of("AAA"));
when(groupProvider.group(firstTcInSecondModeDo)).thenReturn(Optional.of("AAA"));
when(groupProvider.group(secondTcInSecondModeDo)).thenReturn(Optional.of("AAA"));
when(groupProvider.group(tc3InSecondModeDo)).thenReturn(Optional.of("BBB"));

try (MockedStatic<IDataObjectGroupProvider> groupProviderMockedStatic = mockStatic(IDataObjectGroupProvider.class))
{
Expand All @@ -77,10 +77,10 @@ void shouldCloseAllTopComponentsInGroup()
action.actionPerformed(eventMock);
verifyNoInteractions(eventMock);

verify(tc1InMode1, times(0)).close();
verify(tc1InMode2, times(1)).close();
verify(tc2InMode2, times(1)).close();
verify(tc3InMode2, times(0)).close();
verify(firstTcInFirstMode, never()).close();
verify(firstTcInSecondMode).close();
verify(secondTcInSecondMode).close();
verify(tc3InSecondMode, never()).close();
}
}
}
Expand Down

0 comments on commit 20624e6

Please sign in to comment.