use of au.gov.asd.tac.constellation.utilities.tooltip.TooltipPane in project constellation by constellation-app.
the class TooltipMouseEnteredHandlerNGTest method testHandle2.
/**
* Test of handle method, of class TooltipMouseEnteredHandler.
*/
@Test
public void testHandle2() {
System.out.println("testHandle2");
final TextArea textInputControl = spy(new TextArea());
final TooltipPane tooltipPane = spy(new TooltipPane());
try (final MockedStatic<TooltipUtilities> ttuStatic = mockStatic(TooltipUtilities.class, CALLS_REAL_METHODS);
final MockedStatic<TooltipProvider> ttpStatic = mockStatic(TooltipProvider.class, CALLS_REAL_METHODS);
final MockedStatic<TooltipMouseEnteredHandler> melStatic = mockStatic(TooltipMouseEnteredHandler.class, CALLS_REAL_METHODS)) {
// Initialise mocks
final TooltipNode ttn = mock(TooltipNode.class);
final HitInfo info = mock(HitInfo.class);
final TextInputControlSkin<?> skin = mock(TextAreaSkin.class);
final MouseEvent event = mock(MouseEvent.class);
final TooltipProvider.TooltipDefinition ttd1 = mock(TooltipProvider.TooltipDefinition.class);
final TooltipProvider.TooltipDefinition ttd2 = mock(TooltipProvider.TooltipDefinition.class);
// Create list of definitions to return.
final List<TooltipProvider.TooltipDefinition> definitions = new ArrayList<>();
definitions.add(ttd1);
definitions.add(ttd2);
// Set mock behaviour
when(tooltipPane.isEnabled()).thenReturn(true);
when(info.getCharIndex()).thenReturn(0);
when(((TextAreaSkin) skin).getIndex(Mockito.anyDouble(), Mockito.anyDouble())).thenReturn(info);
when(textInputControl.getSkin()).thenReturn(((Skin) skin));
doNothing().when(tooltipPane).showTooltip(Mockito.any(TooltipNode.class), Mockito.anyDouble(), Mockito.anyDouble());
doNothing().when(textInputControl).requestFocus();
// Set static mock behaviour
ttuStatic.when(() -> TooltipUtilities.selectActiveArea(Mockito.any(TextInputControl.class), Mockito.any(List.class))).thenAnswer((Answer<Void>) invocation -> null);
melStatic.when(() -> TooltipMouseEnteredHandler.createTooltipNode(Mockito.any(List.class))).thenReturn(ttn);
ttpStatic.when(() -> TooltipProvider.getTooltips(Mockito.anyString(), Mockito.anyInt())).thenReturn(definitions);
// Create instance
final TooltipMouseEnteredHandler instance = new TooltipMouseEnteredHandler(textInputControl, tooltipPane);
// Call tested method
instance.handle(event);
// Verify calls are made
verify(tooltipPane, times(1)).isEnabled();
verify(info, times(1)).getCharIndex();
verify(((TextAreaSkin) skin), times(1)).getIndex(Mockito.anyDouble(), Mockito.anyDouble());
verify(textInputControl, times(2)).getSkin();
verify(tooltipPane, times(1)).showTooltip(Mockito.any(TooltipNode.class), Mockito.anyDouble(), Mockito.anyDouble());
verify(textInputControl, times(1)).requestFocus();
ttuStatic.verify(() -> TooltipUtilities.selectActiveArea(Mockito.any(TextInputControl.class), Mockito.any(List.class)), times(1));
melStatic.verify(() -> TooltipMouseEnteredHandler.createTooltipNode(Mockito.any(List.class)), times(1));
}
}
use of au.gov.asd.tac.constellation.utilities.tooltip.TooltipPane in project constellation by constellation-app.
the class TooltipMouseEnteredTextAreaHandlerNGTest method testHandle2.
/**
* Test of handle method, of class TooltipMouseEnteredTextAreaHandler.
*/
@Test
public void testHandle2() {
System.out.println("handle2");
final InlineCssTextArea inlineCssTextArea = mock(InlineCssTextArea.class);
final TooltipPane tooltipPane = spy(new TooltipPane());
final Pane p1 = spy(new Pane());
final Pane p2 = spy(new Pane());
final TooltipProvider.TooltipDefinition ttd1 = spy(new TooltipProvider.TooltipDefinition(p1));
final TooltipProvider.TooltipDefinition ttd2 = spy(new TooltipProvider.TooltipDefinition(p2));
// Create list of definitions to return.
final List<TooltipProvider.TooltipDefinition> definitions = new ArrayList<>();
definitions.add(ttd1);
definitions.add(ttd2);
final TooltipNode ttn = mock(TooltipNode.class);
try (final MockedStatic<TooltipUtilities> ttuStatic = mockStatic(TooltipUtilities.class, CALLS_REAL_METHODS);
final MockedStatic<TooltipProvider> ttpStatic = mockStatic(TooltipProvider.class, CALLS_REAL_METHODS);
final MockedStatic<TooltipMouseEnteredTextAreaHandler> melStatic = mockStatic(TooltipMouseEnteredTextAreaHandler.class, CALLS_REAL_METHODS)) {
ttuStatic.when(() -> TooltipUtilities.selectActiveArea(Mockito.any(TextInputControl.class), Mockito.any(List.class))).thenAnswer((Answer<Void>) invocation -> null);
ttpStatic.when(() -> TooltipProvider.getTooltips(Mockito.eq("returnText"), Mockito.eq(10))).thenReturn(definitions);
melStatic.when(() -> TooltipMouseEnteredTextAreaHandler.createTooltipNode(Mockito.any(List.class))).thenReturn(ttn);
final MouseOverTextEvent event = mock(MouseOverTextEvent.class);
final Point2D p2d = mock(Point2D.class);
when(p2d.getX()).thenReturn(200.0d);
when(p2d.getY()).thenReturn(400.0d);
when(tooltipPane.isEnabled()).thenReturn(true);
doNothing().when(tooltipPane).showTooltip(Mockito.any(TooltipNode.class), Mockito.eq(200.0d), Mockito.eq(400.0d));
doNothing().when(inlineCssTextArea).requestFocus();
when(inlineCssTextArea.getText()).thenReturn("returnText");
when(event.getCharacterIndex()).thenReturn(10);
when(event.getScreenPosition()).thenReturn(p2d);
final TooltipMouseEnteredTextAreaHandler instance = new TooltipMouseEnteredTextAreaHandler(inlineCssTextArea, tooltipPane);
instance.handle(event);
// verify that the text area was not focused.
verify(tooltipPane, times(1)).isEnabled();
verify(event, times(1)).getCharacterIndex();
verify(inlineCssTextArea, times(1)).requestFocus();
verify(event, times(1)).getScreenPosition();
verify(p2d, times(1)).getX();
verify(p2d, times(1)).getY();
verify(tooltipPane, times(1)).showTooltip(Mockito.any(TooltipNode.class), Mockito.eq(200.0d), Mockito.eq(400.0d));
ttpStatic.verify(() -> TooltipProvider.getTooltips(Mockito.eq("returnText"), Mockito.eq(10)), times(1));
ttuStatic.verify(() -> TooltipUtilities.selectActiveArea(Mockito.any(InlineCssTextArea.class), Mockito.any(List.class)), times(1));
melStatic.verify(() -> TooltipMouseEnteredTextAreaHandler.createTooltipNode(Mockito.any(List.class)), times(1));
}
}
use of au.gov.asd.tac.constellation.utilities.tooltip.TooltipPane in project constellation by constellation-app.
the class TooltipMouseEnteredTextAreaHandlerNGTest method testHandle3.
/**
* Test of handle method, of class TooltipMouseEnteredTextAreaHandler.
*/
@Test
public void testHandle3() {
System.out.println("handle3");
final InlineCssTextArea inlineCssTextArea = mock(InlineCssTextArea.class);
final TooltipPane tooltipPane = spy(new TooltipPane());
// Create list of definitions to return.
final List<TooltipProvider.TooltipDefinition> definitions = new ArrayList<>();
final TooltipNode ttn = mock(TooltipNode.class);
try (final MockedStatic<TooltipUtilities> ttuStatic = mockStatic(TooltipUtilities.class, CALLS_REAL_METHODS);
final MockedStatic<TooltipProvider> ttpStatic = mockStatic(TooltipProvider.class, CALLS_REAL_METHODS);
final MockedStatic<TooltipMouseEnteredTextAreaHandler> melStatic = mockStatic(TooltipMouseEnteredTextAreaHandler.class, CALLS_REAL_METHODS)) {
ttuStatic.when(() -> TooltipUtilities.selectActiveArea(Mockito.any(TextInputControl.class), Mockito.any(List.class))).thenAnswer((Answer<Void>) invocation -> null);
ttpStatic.when(() -> TooltipProvider.getTooltips(Mockito.eq("returnText"), Mockito.eq(10))).thenReturn(definitions);
melStatic.when(() -> TooltipMouseEnteredTextAreaHandler.createTooltipNode(Mockito.any(List.class))).thenReturn(ttn);
final MouseOverTextEvent event = mock(MouseOverTextEvent.class);
final Point2D p2d = mock(Point2D.class);
when(p2d.getX()).thenReturn(200.0d);
when(p2d.getY()).thenReturn(400.0d);
when(tooltipPane.isEnabled()).thenReturn(true);
doNothing().when(tooltipPane).showTooltip(Mockito.any(TooltipNode.class), Mockito.eq(200.0d), Mockito.eq(400.0d));
doNothing().when(inlineCssTextArea).requestFocus();
when(inlineCssTextArea.getText()).thenReturn("returnText");
when(event.getCharacterIndex()).thenReturn(10);
when(event.getScreenPosition()).thenReturn(p2d);
final TooltipMouseEnteredTextAreaHandler instance = new TooltipMouseEnteredTextAreaHandler(inlineCssTextArea, tooltipPane);
instance.handle(event);
// verify that the text area was not focused.
verify(tooltipPane, times(1)).isEnabled();
verify(event, times(1)).getCharacterIndex();
verify(inlineCssTextArea, times(1)).requestFocus();
verify(event, times(0)).getScreenPosition();
verify(p2d, times(0)).getX();
verify(p2d, times(0)).getY();
verify(tooltipPane, times(0)).showTooltip(Mockito.any(TooltipNode.class), Mockito.eq(200.0d), Mockito.eq(400.0d));
ttpStatic.verify(() -> TooltipProvider.getTooltips(Mockito.eq("returnText"), Mockito.eq(10)), times(1));
ttuStatic.verify(() -> TooltipUtilities.selectActiveArea(Mockito.any(InlineCssTextArea.class), Mockito.any(List.class)), times(1));
melStatic.verify(() -> TooltipMouseEnteredTextAreaHandler.createTooltipNode(Mockito.any(List.class)), times(0));
}
}
use of au.gov.asd.tac.constellation.utilities.tooltip.TooltipPane in project constellation by constellation-app.
the class TooltipMouseExitedHandlerNGTest method testHandle.
/**
* Test of handle method, of class TooltipMouseExitedHandler.
*/
@Test
public void testHandle() {
System.out.println("handle");
final TooltipPane tooltipPane = spy(new TooltipPane());
when(tooltipPane.isEnabled()).thenReturn(true);
doNothing().when(tooltipPane).hideTooltip();
final TooltipMouseExitedHandler instance = new TooltipMouseExitedHandler(tooltipPane);
final MouseEvent event = mock(MouseEvent.class);
instance.handle(event);
verify(tooltipPane, times(1)).isEnabled();
verify(tooltipPane, times(1)).hideTooltip();
}
use of au.gov.asd.tac.constellation.utilities.tooltip.TooltipPane in project constellation by constellation-app.
the class TooltipMouseMovedHandlerNGTest method testHandle.
/**
* Test of handle method, of class TooltipMouseMovedHandler.
*/
@Test
public void testHandle() {
System.out.println("testHandle");
final TextArea textInputControl = spy(new TextArea());
final TooltipPane tooltipPane = spy(new TooltipPane());
try (final MockedStatic<TooltipUtilities> ttuStatic = mockStatic(TooltipUtilities.class, CALLS_REAL_METHODS)) {
ttuStatic.when(() -> TooltipUtilities.selectActiveArea(Mockito.any(TextInputControl.class), Mockito.any(List.class))).thenAnswer((Answer<Void>) invocation -> null);
when(tooltipPane.isEnabled()).thenReturn(false);
final TooltipMouseMovedHandler instance = new TooltipMouseMovedHandler(textInputControl, tooltipPane);
final MouseEvent event = mock(MouseEvent.class);
instance.handle(event);
verify(tooltipPane, times(1)).isEnabled();
verifyNoInteractions(textInputControl);
// Verify that mouseEntered did not trigger calls to the below method.
ttuStatic.verify(() -> TooltipUtilities.selectActiveArea(Mockito.any(TextInputControl.class), Mockito.any(List.class)), times(0));
}
}
Aggregations