BakeoutController-Basic  0.1
A Controller for the Omicron vacuum chamber
HandleDeviceAlreadyCreatedExceptionTest.java
1 package unit.ui.controllers.device_setup_controller.handle_go_button_clicked;
2 
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 HandleDeviceAlreadyCreatedExceptionTest extends
17  private static final String queryForMessage =
18  "#device-created-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(
53  "The device already exists"
54  )
55  ));
56  oneOf(pressureGaugeFactory).makePressureGauge();
57  } catch (Exception error){
58  error.printStackTrace();
59  }
60  }
61  }
62 }
Git Repo