BakeoutController-Basic  0.1
A Controller for the Omicron vacuum chamber
GetPressureGaugeNotInRegistry.java
1 package unit.kernel.models.pvci_pressure_gauge_factory;
2 
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;
16 
17 import java.io.IOException;
18 
19 import static org.junit.Assert.assertNotNull;
20 
26 public final class GetPressureGaugeNotInRegistry extends
28 
29  private DeviceRegistry mockController = context.mock(DeviceRegistry.class,
30  "mockController");
31 
32  private PressureGauge mockPressureGauge = context.mock(
33  PressureGauge.class);
34 
35  private ModbusTransaction mockTransaction = new MockTransaction();
36 
37  private VariableProviderContainer mockVariableRegistry = context.mock(
39  );
40 
41  private TaskRunner mockTaskRunner = context.mock(
42  TaskRunner.class
43  );
44 
45  @Before
46  public void setContext() throws Exception {
47  context.checking(new ExpectationsForTest());
48  }
49 
50  @Test
51  public void getPressureGauge() throws IOException {
52  assertNotNull(factory.getPressureGauge());
53  }
54 
55  private class MockTransaction extends ModbusSerialTransaction {
56  @Override
57  public void execute(){
58  // Don't actually run anything
59  }
60 
61  @Override
62  public ModbusResponse getResponse(){
63  return new ReadWriteMultipleResponse();
64  }
65  }
66 
67  private class ExpectationsForTest extends Expectations {
68  public ExpectationsForTest() throws Exception {
69  expectationsForKernel();
70  expectationsForDeviceRegistry();
71  expectationsForModbusConnector();
72  expectationsForMockController();
73  expectationsForVariableRegistry();
74  expectationsForTaskRunner();
75  }
76 
77  private void expectationsForKernel(){
78  oneOf(mockKernel).getDeviceRegistryView();
79  will(returnValue(mockRegistry));
80 
81  oneOf(mockKernel).getDeviceRegistryController();
82  will(returnValue(mockController));
83 
84  oneOf(mockKernel).getModbusConnector();
85  will(returnValue(mockConnector));
86 
87  oneOf(mockKernel).getVariableProvidersController();
88  will(returnValue(mockVariableRegistry));
89 
90  oneOf(mockKernel).getTaskRunner();
91  will(returnValue(mockTaskRunner));
92  }
93 
94  private void expectationsForDeviceRegistry(){
95  oneOf(mockRegistry).hasPressureGauge();
96  will(returnValue(Boolean.FALSE));
97 
98  oneOf(mockRegistry).getPressureGauge();
99  will(returnValue(mockPressureGauge));
100  }
101 
102  private void expectationsForModbusConnector() throws Exception {
103  oneOf(mockConnector).setPortConfiguration(
104  with(any(ModbusPortConfiguration.class))
105  );
106 
107  oneOf(mockConnector).getTransactionForRequest(
108  with(any(ReadWriteMultipleRequest.class))
109  );
110  will(returnValue(mockTransaction));
111 
112  oneOf(mockConnector).parseStringFromResponse(with(any
113  (ModbusResponse.class)));
114  will(returnValue("iGC3"));
115 
116  }
117 
118  private void expectationsForMockController() throws Exception {
119  oneOf(mockController).setPressureGauge(
120  with(any(PressureGauge.class))
121  );
122  }
123 
124  private void expectationsForVariableRegistry(){
125  oneOf(mockVariableRegistry).setPressureProvider(
126  with(any(VariableProvider.class))
127  );
128  }
129 
130  private void expectationsForTaskRunner(){
131  oneOf(mockTaskRunner).execute(with(any(Runnable.class)));
132  }
133  }
134 }
final Mockery context
Git Repo