BakeoutController  0.1
A Controller for the Omicron vacuum chamber
TestingConfiguration.java
1 package unit.ui;
2 
3 import kernel.Kernel;
5 import org.jmock.Expectations;
6 import org.jmock.Mockery;
7 import org.jmock.integration.junit4.JUnit4Mockery;
8 import org.jmock.lib.concurrent.Synchroniser;
9 import org.springframework.context.annotation.*;
11 
12 import java.util.ArrayList;
13 import java.util.List;
14 
19 @Configuration
20 @Import(UserInterfaceConfiguration.class)
21 @Lazy
22 public class TestingConfiguration {
23 
27  private volatile Kernel mockKernel;
28 
32  private volatile Mockery mockingContext;
33 
37  @Bean
38  @Scope("singleton")
39  public Mockery mockingContext(){
40  if(mockingContext == null) {
41  mockingContext = new SynchronizedJUnit4Mockery();
42  }
43  return mockingContext;
44  }
45 
49  @Bean
50  @Scope("prototype")
51  public static List<String> testData(){
52  List<String> testData = new ArrayList<>();
53  testData.add("/dev/ttyUSB0");
54  return testData;
55  }
56 
60  @Bean
61  @Scope("singleton")
63  return mockingContext().mock(CommPortReporter.class);
64  }
65 
69  @Bean
70  @Scope("singleton")
71  public Kernel kernel(){
72  mockKernel = mockingContext().mock(Kernel.class);
73  mockingContext().checking(new ExpectationsForKernel());
74  return mockKernel;
75  }
76 
82  private class SynchronizedJUnit4Mockery extends JUnit4Mockery {
86  public SynchronizedJUnit4Mockery(){
87  setThreadingPolicy(new Synchroniser());
88  }
89  }
90 
95  private class ExpectationsForKernel extends Expectations {
99  public ExpectationsForKernel(){
100  expectationsForPortReporter();
101  expectationsForSerialPortNames();
102  }
103 
107  private void expectationsForPortReporter(){
108  allowing(mockKernel).getCommPortReporter();
109  will(returnValue(portReporter()));
110  }
111 
116  private void expectationsForSerialPortNames(){
117  allowing(portReporter()).getSerialPortNames();
118  will(returnValue(testData()));
119  }
120  }
121 }
static List< String > testData()
Git Repo