use of org.eclipse.scanning.api.scan.PositionEvent in project gda-core by openGDA.
the class ScannableNexusWrapperTest method testSetPosition_withScanPosition.
@Test
public void testSetPosition_withScanPosition() throws Exception {
// Note: nexus writing tested separately by ScannableNexusWrapperScanTest
// Arrange
final double newPosition = 3.8;
final int scanIndex = 38;
IPositionListener posListener = mock(IPositionListener.class);
((IPositionListenable) scannable).addPositionListener(posListener);
final IPosition scanPosition = new Scalar<Double>("sax", scanIndex, newPosition);
assertThat(scannable.getPosition(), is(equalTo(3.7)));
// Act
scannable.setPosition(newPosition, scanPosition);
// Assert
assertThat(scannable.getPosition(), is(equalTo(newPosition)));
((IPositionListenable) scannable).removePositionListener(posListener);
ArgumentCaptor<PositionEvent> captor = ArgumentCaptor.forClass(PositionEvent.class);
InOrder order = inOrder(posListener);
order.verify(posListener).positionWillPerform(captor.capture());
order.verify(posListener).positionChanged(captor.capture());
order.verify(posListener).positionPerformed(captor.capture());
order.verifyNoMoreInteractions();
List<PositionEvent> posEvents = captor.getAllValues();
assertThat(posEvents, hasSize(3));
int i = 0;
for (PositionEvent posEvent : posEvents) {
// willPerform event doesn't have level set
assertThat(posEvent.getLevel(), is(i == 0 ? 0 : 5));
IPosition position = posEvent.getPosition();
assertThat(position.getNames(), contains(scannable.getName()));
// index not set for positionChanged
assertThat(position.getIndex("sax"), is(i == 1 ? -1 : 38));
assertThat(position.getValue(scannable.getName()), is(equalTo(Double.valueOf(newPosition))));
i++;
}
}
use of org.eclipse.scanning.api.scan.PositionEvent in project gda-core by openGDA.
the class ScannableNexusWrapperTest method testSetPosition.
@Test
public void testSetPosition() throws Exception {
// Arrange
final double newPosition = 8.3;
IPositionListener posListener = mock(IPositionListener.class);
((IPositionListenable) scannable).addPositionListener(posListener);
assertThat(scannable.getPosition(), is(equalTo(3.7)));
// Act
scannable.setPosition(newPosition);
// Assert
assertThat(scannable.getPosition(), is(equalTo(newPosition)));
((IPositionListenable) scannable).removePositionListener(posListener);
ArgumentCaptor<PositionEvent> captor = ArgumentCaptor.forClass(PositionEvent.class);
InOrder order = inOrder(posListener);
order.verify(posListener).positionWillPerform(captor.capture());
order.verify(posListener).positionChanged(captor.capture());
order.verify(posListener).positionPerformed(captor.capture());
order.verifyNoMoreInteractions();
List<PositionEvent> posEvents = captor.getAllValues();
assertThat(posEvents, hasSize(3));
int i = 0;
for (PositionEvent posEvent : posEvents) {
// willPerform event doesn't have level set
assertThat(posEvent.getLevel(), is(i == 0 ? 0 : 5));
IPosition position = posEvent.getPosition();
assertThat(position.getNames(), contains(scannable.getName()));
assertThat(position.getValue(scannable.getName()), is(equalTo(Double.valueOf(newPosition))));
i++;
}
}
Aggregations