1 package unit.kernel.models.pvci_pressure_gauge_factory;
3 import com.ghgande.j2mod.modbus.io.ModbusSerialTransaction;
4 import com.ghgande.j2mod.modbus.io.ModbusTransaction;
5 import com.ghgande.j2mod.modbus.msg.*;
13 import org.jmock.Expectations;
14 import org.junit.Before;
15 import org.junit.Test;
17 import java.io.IOException;
19 import static org.junit.Assert.assertNotNull;
35 private ModbusTransaction mockTransaction =
new MockTransaction();
46 public void setContext()
throws Exception {
47 context.checking(
new ExpectationsForTest());
51 public void getPressureGauge()
throws IOException {
55 private class MockTransaction
extends ModbusSerialTransaction {
57 public void execute(){
62 public ModbusResponse getResponse(){
63 return new ReadWriteMultipleResponse();
67 private class ExpectationsForTest
extends Expectations {
68 public ExpectationsForTest()
throws Exception {
69 expectationsForKernel();
70 expectationsForDeviceRegistry();
71 expectationsForModbusConnector();
72 expectationsForMockController();
73 expectationsForVariableRegistry();
74 expectationsForTaskRunner();
77 private void expectationsForKernel(){
78 oneOf(mockKernel).getDeviceRegistryView();
79 will(returnValue(mockRegistry));
81 oneOf(mockKernel).getDeviceRegistryController();
82 will(returnValue(mockController));
84 oneOf(mockKernel).getModbusConnector();
85 will(returnValue(mockConnector));
87 oneOf(mockKernel).getVariableProvidersController();
88 will(returnValue(mockVariableRegistry));
90 oneOf(mockKernel).getTaskRunner();
91 will(returnValue(mockTaskRunner));
94 private void expectationsForDeviceRegistry(){
95 oneOf(mockRegistry).hasPressureGauge();
96 will(returnValue(Boolean.FALSE));
98 oneOf(mockRegistry).getPressureGauge();
99 will(returnValue(mockPressureGauge));
102 private void expectationsForModbusConnector()
throws Exception {
103 oneOf(mockConnector).setPortConfiguration(
107 oneOf(mockConnector).getTransactionForRequest(
108 with(any(ReadWriteMultipleRequest.class))
110 will(returnValue(mockTransaction));
112 oneOf(mockConnector).parseStringFromResponse(with(any
113 (ModbusResponse.class)));
114 will(returnValue(
"iGC3"));
118 private void expectationsForMockController()
throws Exception {
119 oneOf(mockController).setPressureGauge(
124 private void expectationsForVariableRegistry(){
125 oneOf(mockVariableRegistry).setPressureProvider(
130 private void expectationsForTaskRunner(){
131 oneOf(mockTaskRunner).execute(with(any(Runnable.class)));
PressureGauge getPressureGauge()