@Test void nonInteractive() { Request request = mock(Request.class); Job job = mock(Job.class); when(job.getRequest()).thenReturn(request); when(request.isInteractive()).thenReturn(false); JobStatus status = mock(JobStatus.class); when(job.getStatus()).thenReturn(status); DocumentsDeletingEvent event = new DocumentsDeletingEvent(); this.deletingListener.onEvent(event, job, null); assertEquals("XClass deleting listener will not check the document in non-interactive mode.", logCapture.getMessage(0)); verifyZeroInteractions(status); }
@Override public void onEvent(Event event, Object source, Object data) { Job job = (Job) source; CancelableEvent cancelableEvent = (CancelableEvent) event; XClassBreakingQuestion question = this.buildQuestion(job, cancelableEvent, data); if (question == null) { return; } if (!question.getImpactedObjects().isEmpty()) { JobStatus jobStatus = job.getStatus(); try { if (this.documentAccessBridge.isAdvancedUser(job.getRequest().getProperty("user.reference"))) { question.unselectAll(); boolean ack = job.getStatus().ask(question, 5, TimeUnit.MINUTES); if (!ack) { String message = "The question has been asked, however no answer has been received."; this.logger.warn(message); cancelableEvent.cancel(message); } } else { question.setRefactoringForbidden(true); boolean ack = jobStatus.ask(question, 1, TimeUnit.MINUTES); if (!ack) { String message = "The question has been canceled because this refactoring is forbidden."; cancelableEvent.cancel(message); } } } catch (InterruptedException e) { this.logger.warn("Confirm question has been interrupted."); cancelableEvent.cancel("Question has been interrupted."); } if (jobStatus instanceof CancelableJobStatus) { CancelableJobStatus cancelableJobStatus = (CancelableJobStatus) jobStatus; if (cancelableJobStatus.isCanceled()) { cancelableEvent.cancel(); } if (cancelableEvent.isCanceled()) { cancelableJobStatus.cancel(); } } } }
XClassDeletingListener extends AbstractEventListener { @Override public void onEvent(Event event, Object source, Object data) { Job job = (Job) source; CancelableEvent cancelableEvent = (CancelableEvent) event; XClassBreakingQuestion question = this.buildQuestion(job, cancelableEvent, data); if (question == null) { return; } if (!question.getImpactedObjects().isEmpty()) { JobStatus jobStatus = job.getStatus(); try { if (this.documentAccessBridge.isAdvancedUser(job.getRequest().getProperty("user.reference"))) { question.unselectAll(); boolean ack = job.getStatus().ask(question, 5, TimeUnit.MINUTES); if (!ack) { String message = "The question has been asked, however no answer has been received."; this.logger.warn(message); cancelableEvent.cancel(message); } } else { question.setRefactoringForbidden(true); boolean ack = jobStatus.ask(question, 1, TimeUnit.MINUTES); if (!ack) { String message = "The question has been canceled because this refactoring is forbidden."; cancelableEvent.cancel(message); } } } catch (InterruptedException e) { this.logger.warn("Confirm question has been interrupted."); cancelableEvent.cancel("Question has been interrupted."); } if (jobStatus instanceof CancelableJobStatus) { CancelableJobStatus cancelableJobStatus = (CancelableJobStatus) jobStatus; if (cancelableJobStatus.isCanceled()) { cancelableEvent.cancel(); } if (cancelableEvent.isCanceled()) { cancelableJobStatus.cancel(); } } } } }
XClassDeletingListener extends AbstractEventListener { @Override public void onEvent(Event event, Object source, Object data) { Job job = (Job) source; CancelableEvent cancelableEvent = (CancelableEvent) event; XClassBreakingQuestion question = this.buildQuestion(job, cancelableEvent, data); if (question == null) { return; } if (!question.getImpactedObjects().isEmpty()) { JobStatus jobStatus = job.getStatus(); try { if (this.documentAccessBridge.isAdvancedUser(job.getRequest().getProperty("user.reference"))) { question.unselectAll(); boolean ack = job.getStatus().ask(question, 5, TimeUnit.MINUTES); if (!ack) { String message = "The question has been asked, however no answer has been received."; this.logger.warn(message); cancelableEvent.cancel(message); } } else { question.setRefactoringForbidden(true); boolean ack = jobStatus.ask(question, 1, TimeUnit.MINUTES); if (!ack) { String message = "The question has been canceled because this refactoring is forbidden."; cancelableEvent.cancel(message); } } } catch (InterruptedException e) { this.logger.warn("Confirm question has been interrupted."); cancelableEvent.cancel("Question has been interrupted."); } if (jobStatus instanceof CancelableJobStatus) { CancelableJobStatus cancelableJobStatus = (CancelableJobStatus) jobStatus; if (cancelableJobStatus.isCanceled()) { cancelableEvent.cancel(); } if (cancelableEvent.isCanceled()) { cancelableJobStatus.cancel(); } } } } XClassDeletingListener(); }
XClassDeletingListener extends AbstractEventListener { @Override public void onEvent(Event event, Object source, Object data) { Job job = (Job) source; CancelableEvent cancelableEvent = (CancelableEvent) event; XClassBreakingQuestion question = this.buildQuestion(job, cancelableEvent, data); if (question == null) { return; } if (!question.getImpactedObjects().isEmpty()) { JobStatus jobStatus = job.getStatus(); try { if (this.documentAccessBridge.isAdvancedUser(job.getRequest().getProperty("user.reference"))) { question.unselectAll(); boolean ack = job.getStatus().ask(question, 5, TimeUnit.MINUTES); if (!ack) { String message = "The question has been asked, however no answer has been received."; this.logger.warn(message); cancelableEvent.cancel(message); } } else { question.setRefactoringForbidden(true); boolean ack = jobStatus.ask(question, 1, TimeUnit.MINUTES); if (!ack) { String message = "The question has been canceled because this refactoring is forbidden."; cancelableEvent.cancel(message); } } } catch (InterruptedException e) { this.logger.warn("Confirm question has been interrupted."); cancelableEvent.cancel("Question has been interrupted."); } if (jobStatus instanceof CancelableJobStatus) { CancelableJobStatus cancelableJobStatus = (CancelableJobStatus) jobStatus; if (cancelableJobStatus.isCanceled()) { cancelableEvent.cancel(); } if (cancelableEvent.isCanceled()) { cancelableJobStatus.cancel(); } } } } XClassDeletingListener(); @Override void onEvent(Event event, Object source, Object data); }
XClassDeletingListener extends AbstractEventListener { @Override public void onEvent(Event event, Object source, Object data) { Job job = (Job) source; CancelableEvent cancelableEvent = (CancelableEvent) event; XClassBreakingQuestion question = this.buildQuestion(job, cancelableEvent, data); if (question == null) { return; } if (!question.getImpactedObjects().isEmpty()) { JobStatus jobStatus = job.getStatus(); try { if (this.documentAccessBridge.isAdvancedUser(job.getRequest().getProperty("user.reference"))) { question.unselectAll(); boolean ack = job.getStatus().ask(question, 5, TimeUnit.MINUTES); if (!ack) { String message = "The question has been asked, however no answer has been received."; this.logger.warn(message); cancelableEvent.cancel(message); } } else { question.setRefactoringForbidden(true); boolean ack = jobStatus.ask(question, 1, TimeUnit.MINUTES); if (!ack) { String message = "The question has been canceled because this refactoring is forbidden."; cancelableEvent.cancel(message); } } } catch (InterruptedException e) { this.logger.warn("Confirm question has been interrupted."); cancelableEvent.cancel("Question has been interrupted."); } if (jobStatus instanceof CancelableJobStatus) { CancelableJobStatus cancelableJobStatus = (CancelableJobStatus) jobStatus; if (cancelableJobStatus.isCanceled()) { cancelableEvent.cancel(); } if (cancelableEvent.isCanceled()) { cancelableJobStatus.cancel(); } } } } XClassDeletingListener(); @Override void onEvent(Event event, Object source, Object data);  }