ProcessControllerFactory { public ProcessController createProcessController(final ProcessControllerParameters parameters, final int pid) { notNull(parameters, "Invalid parameters '" + parameters + "' specified"); isTrue(pid > 0, "Invalid pid '" + pid + "' specified"); if (!isAttachAPIFound()) { return new FileProcessController(parameters, pid); } return new MBeanOrFileProcessController(parameters, pid); } ProcessControllerFactory(); ProcessController createProcessController(final ProcessControllerParameters parameters,
      final int pid); ProcessController createProcessController(final ProcessControllerParameters parameters,
      final File directory, final String pidFileName); boolean isAttachAPIFound(); static final String PROPERTY_DISABLE_ATTACH_API; }
@Test public void createProcessController_withAttachAPI_returnsMBeanProcessController() throws Exception { ProcessController controller = factory.createProcessController(parameters, pid); assertThat(controller).isInstanceOf(MBeanOrFileProcessController.class); }
@Test public void createProcessController_withoutAttachAPI_returnsFileProcessController() throws Exception { System.setProperty(PROPERTY_DISABLE_ATTACH_API, "true"); factory = new ProcessControllerFactory(); ProcessController controller = factory.createProcessController(parameters, pid); assertThat(controller).isInstanceOf(FileProcessController.class); }
@Test public void createProcessController_withNullParameters_throwsNullPointerException() throws Exception { parameters = null; assertThatThrownBy(() -> factory.createProcessController(parameters, pid)) .isInstanceOf(NullPointerException.class) .hasMessageContaining("Invalid parameters 'null' specified"); }
@Test public void createProcessController_withZeroPid_throwsIllegalArgumentException() throws Exception { pid = 0; assertThatThrownBy(() -> factory.createProcessController(parameters, 0)) .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining("Invalid pid '" + 0 + "' specified"); }