use of au.gov.asd.tac.constellation.views.find2.components.ReplaceTab in project constellation by constellation-app.
the class ReplaceTabNGTest method testUpdateBasicReplaceParamters.
/**
* Test of updateBasicReplaceParamters method, of class ReplaceTab.
*/
@Test
public void testUpdateBasicReplaceParamters() {
System.out.println("updateBasicReplaceParamters");
final BasicFindReplaceParameters controlllerParameters = FindViewController.getDefault().getCurrentBasicReplaceParameters();
replaceTab.lookForChoiceBox.getSelectionModel().select(0);
replaceTab.getFindTextField().setText("test");
replaceTab.getReplaceTextField().setText("replace");
final GraphElementType elementType = GraphElementType.getValue(replaceTab.lookForChoiceBox.getSelectionModel().getSelectedItem());
replaceTab.currentSelectionChoiceBox.getSelectionModel().select(0);
/**
* Call the updateBasicFindParamters function. Check that each of the
* javaFX elements passes their corresponding data correctly to the
* controllers basicFindParamters
*/
replaceTab.updateBasicReplaceParamters();
/**
* All parameters should equal the current value of the basicFindTabs
* elements
*/
assertEquals(controlllerParameters.getFindString(), replaceTab.getFindTextField().getText());
assertEquals(controlllerParameters.getReplaceString(), replaceTab.getReplaceTextField().getText());
assertEquals(controlllerParameters.getGraphElement(), elementType);
assertEquals(controlllerParameters.getAttributeList(), replaceTab.getMatchingAttributeList(elementType));
assertEquals(controlllerParameters.isStandardText(), replaceTab.standardRadioBtn.isSelected());
assertEquals(controlllerParameters.isRegEx(), replaceTab.regExBtn.isSelected());
assertEquals(controlllerParameters.isIgnoreCase(), replaceTab.ignoreCaseCB.isSelected());
/**
* All 4 should be false as currentSelectionChoiceBox is set to select
* index 0 which is "Ignore"
*/
assertEquals(controlllerParameters.isFindIn(), false);
assertEquals(controlllerParameters.isAddTo(), false);
assertEquals(controlllerParameters.isRemoveFrom(), false);
assertEquals(controlllerParameters.isReplaceIn(), false);
assertEquals(controlllerParameters.isSearchAllGraphs(), replaceTab.searchAllGraphs.isSelected());
// TODO review the generated test code and remove the default call to fail.
}
use of au.gov.asd.tac.constellation.views.find2.components.ReplaceTab in project constellation by constellation-app.
the class ReplaceTabNGTest method testReplaceAllAction.
/**
* Test of replaceAllAction method, of class ReplaceTab.
*/
@Test
public void testReplaceAllAction() {
System.out.println("replaceAllAction");
setupGraph();
// Create a controller mock and do nothing on retriveMatchingElements()
FindViewController mockController = mock(FindViewController.class);
mockController.init(spyTopComponent);
doNothing().when(mockController).replaceMatchingElements(Mockito.eq(true), Mockito.eq(false));
/**
* Create a basicFindMock and adds a temporary choice box and textFild
* for the functions to work.
*/
ReplaceTab replaceMock = mock(ReplaceTab.class);
final ChoiceBox<String> lookForChoiceBox = new ChoiceBox<>();
lookForChoiceBox.getItems().add("Node");
lookForChoiceBox.getSelectionModel().select(0);
final TextField findTextField = new TextField("test");
final TextField repalceTextField = new TextField("replace");
// Mock the getters to return the newly made java fx element.
when(replaceMock.getLookForChoiceBox()).thenReturn(lookForChoiceBox);
when(replaceMock.getFindTextField()).thenReturn(findTextField);
when(replaceMock.getReplaceTextField()).thenReturn(repalceTextField);
// Do nothing on saveSelected() and updateBasicFindParamters()
doCallRealMethod().when(replaceMock).replaceAllAction();
doNothing().when(replaceMock).saveSelected(Mockito.any());
doNothing().when(replaceMock).updateBasicReplaceParamters();
/**
* Create a static mock of the FindViewController. Call the
* findAllAction() then verify that saveSelected,
* updateBasicFindParameters and retrieveMatchingElements were all
* called once.
*/
try (MockedStatic<FindViewController> mockedStatic = Mockito.mockStatic(FindViewController.class)) {
mockedStatic.when(() -> FindViewController.getDefault()).thenReturn(mockController);
replaceMock.replaceAllAction();
verify(replaceMock, times(1)).saveSelected(Mockito.eq(GraphElementType.VERTEX));
verify(replaceMock, times(1)).updateBasicReplaceParamters();
verify(mockController, times(1)).replaceMatchingElements(true, false);
}
}
Aggregations