use of au.gov.asd.tac.constellation.views.dataaccess.GlobalParameters in project constellation by constellation-app.
the class GlobalParametersNGTest method getParameters.
@Test
public void getParameters() {
final PluginParameters previous = mock(PluginParameters.class);
final Lookup lookup = mock(Lookup.class);
final PluginParameter param1 = mock(PluginParameter.class);
final PluginParameter param2 = mock(PluginParameter.class);
when(param1.getId()).thenReturn("param1");
when(param2.getId()).thenReturn("param2");
when(param1.getType()).thenReturn(ActionParameterType.INSTANCE);
when(param2.getType()).thenReturn(ActionParameterType.INSTANCE);
final GlobalParameters.PositionalPluginParameter positionalParam1 = new GlobalParameters.PositionalPluginParameter(param1, 10);
final GlobalParameters.PositionalPluginParameter positionalParam2 = new GlobalParameters.PositionalPluginParameter(param2, 5);
final GlobalParameters globalParameters1 = mock(GlobalParameters.class);
final GlobalParameters globalParameters2 = mock(GlobalParameters.class);
when(globalParameters1.getParameterList(previous)).thenReturn(List.of(positionalParam1));
when(globalParameters2.getParameterList(previous)).thenReturn(List.of(positionalParam2));
lookupStaticMock.when(Lookup::getDefault).thenReturn(lookup);
doReturn(List.of(globalParameters1, globalParameters2)).when(lookup).lookupAll(GlobalParameters.class);
final PluginParameters actual = GlobalParameters.getParameters(previous);
assertEquals(actual.getParameters().size(), 2);
assertSame(actual.getParameters().get("param1"), param1);
assertSame(actual.getParameters().get("param2"), param2);
// Calling it a second time to ensure that the post process is not called more than once.
final PluginParameters actualSecondCall = GlobalParameters.getParameters(previous);
assertEquals(actualSecondCall.getParameters().size(), 2);
assertSame(actualSecondCall.getParameters().get("param1"), param1);
assertSame(actualSecondCall.getParameters().get("param2"), param2);
final ArgumentCaptor<PluginParameters> captor1 = ArgumentCaptor.forClass(PluginParameters.class);
verify(globalParameters1, times(1)).postProcess(captor1.capture());
final ArgumentCaptor<PluginParameters> captor2 = ArgumentCaptor.forClass(PluginParameters.class);
verify(globalParameters2, times(1)).postProcess(captor2.capture());
// It iterates over GlobalParameters list and calls post process on each passing the newly
// generated global parameters list. i.e. the returned value from the method. This verifies
// that it passes the same object in each call and a cursory check thats its the same plugin
// parameters object that was returned.
assertSame(captor1.getValue(), captor2.getValue());
assertEquals(captor1.getValue().getParameters().keySet(), Set.of("param1", "param2"));
}
Aggregations