BakeoutController-Basic  0.1
A Controller for the Omicron vacuum chamber
PortInUseExceptionTest.java
1 package unit.ui.controllers.device_setup_controller.handle_go_button_clicked;
2 
3 import gnu.io.PortInUseException;
4 import javafx.scene.text.Text;
5 import org.jetbrains.annotations.Contract;
6 import org.junit.Test;
7 
8 import java.util.Optional;
9 
10 import static org.junit.Assert.fail;
11 
15 public final class PortInUseExceptionTest extends
17  private static final String queryForMessage =
18  "#port-in-use-exception-message";
19 
20  @Contract(" -> !null")
21  @Override
22  protected ExpectationsForMockFactory getMockingExpectations(){
23  return new ExceptionExpectations();
24  }
25 
26  @Test
27  public void clickGoButton(){
28  clickOn(queryForGoButton);
29 
30  Optional<Text> message = lookup(queryForMessage).tryQuery();
31 
32  if (!message.isPresent()){
33  fail(
34  String.format(
35  "Did not find the message. I used the query %s",
36  queryForMessage
37  )
38  );
39  }
40  }
41 
42  private class ExceptionExpectations extends ExpectationsForMockFactory {
43  public ExceptionExpectations(){
44  super();
45  thrownExpectation();
46  }
47 
48  private void thrownExpectation(){
49  try {
50  oneOf(factory).makePowerSupply();
51  will(throwException(new PortInUseException()));
52  oneOf(pressureGaugeFactory).makePressureGauge();
53  } catch (Exception error){
54  error.printStackTrace();
55  }
56  }
57  }
58 }
Git Repo