Search in sources :

Example 1 with PositionEvent

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++;
    }
}
Also used : IPosition(org.eclipse.scanning.api.points.IPosition) InOrder(org.mockito.InOrder) IPositionListenable(org.eclipse.scanning.api.scan.event.IPositionListenable) IPositionListener(org.eclipse.scanning.api.scan.event.IPositionListener) Scalar(org.eclipse.scanning.api.points.Scalar) PositionEvent(org.eclipse.scanning.api.scan.PositionEvent) Test(org.junit.Test)

Example 2 with PositionEvent

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++;
    }
}
Also used : IPosition(org.eclipse.scanning.api.points.IPosition) InOrder(org.mockito.InOrder) IPositionListenable(org.eclipse.scanning.api.scan.event.IPositionListenable) IPositionListener(org.eclipse.scanning.api.scan.event.IPositionListener) PositionEvent(org.eclipse.scanning.api.scan.PositionEvent) Test(org.junit.Test)

Aggregations

IPosition (org.eclipse.scanning.api.points.IPosition)2 PositionEvent (org.eclipse.scanning.api.scan.PositionEvent)2 IPositionListenable (org.eclipse.scanning.api.scan.event.IPositionListenable)2 IPositionListener (org.eclipse.scanning.api.scan.event.IPositionListener)2 Test (org.junit.Test)2 InOrder (org.mockito.InOrder)2 Scalar (org.eclipse.scanning.api.points.Scalar)1