BakeoutController-Basic  0.1
A Controller for the Omicron vacuum chamber
DevicesTestCase.java
1 package unit.devices;
2 
3 import devices.PowerSupply;
4 import org.junit.Before;
5 import unit.UnitTestCase;
6 
7 import java.io.*;
8 
12 public abstract class DevicesTestCase extends UnitTestCase {
13  protected DeviceCommunicator communicatorForDevice;
14 
15  @Before
16  public void setUpDevicesTestCase() throws IOException {
17  initializeDeviceCommunicator();
18  }
19 
20  private void initializeDeviceCommunicator(){
21  this.communicatorForDevice = new CommunicationMonitor();
22  }
23 
24  protected class CommunicationMonitor implements DeviceCommunicator {
25  private InputStream inputStream;
26  private OutputStream outputStream;
27 
28  protected CommunicationMonitor(){
29  this.inputStream = new ByteArrayInputStream(
30  PowerSupply.OK_RESPONSE.getBytes()
31  );
32  this.outputStream = new ByteArrayOutputStream();
33  }
34 
35  @Override public InputStream getInputStream(){
36  return this.inputStream;
37  }
38 
39  @Override public OutputStream getOutputStream(){
40  return this.outputStream;
41  }
42 
43  @Override public void setInputStreamData(String dataForDeviceToRead){
44  this.inputStream = new ByteArrayInputStream(
45  dataForDeviceToRead.getBytes()
46  );
47  }
48 
49  @Override public String getOutputStreamData(){
50  String data = this.outputStream.toString();
51  this.outputStream = new ByteArrayOutputStream();
52  return data;
53  }
54 
55  @Override public void clear(){
56  this.inputStream = new ByteArrayInputStream(
57  PowerSupply.OK_RESPONSE.getBytes()
58  );
59  this.outputStream = new ByteArrayOutputStream();
60  }
61  }
62 }
void setInputStreamData(String dataForDeviceToRead)
Git Repo