SetMailboxesCreationProcessor implements SetMailboxesProcessor { @Override public SetMailboxesResponse process(SetMailboxesRequest request, MailboxSession mailboxSession) { TimeMetric timeMetric = metricFactory.timer(JMAP_PREFIX + "SetMailboxesCreationProcessor"); SetMailboxesResponse.Builder builder = SetMailboxesResponse.builder(); try { Map<MailboxCreationId, MailboxId> creationIdsToCreatedMailboxId = new HashMap<>(); sortingHierarchicalCollections.sortFromRootToLeaf(request.getCreate().entrySet()) .forEach(entry -> createMailbox(entry.getKey(), entry.getValue(), mailboxSession, creationIdsToCreatedMailboxId, builder)); } catch (CycleDetectedException e) { markRequestsAsNotCreatedDueToCycle(request, builder); } timeMetric.stopAndPublish(); return builder.build(); } @Inject @VisibleForTesting  SetMailboxesCreationProcessor(MailboxManager mailboxManager, SubscriptionManager subscriptionManager, MailboxFactory mailboxFactory, Factory mailboxIdFactory, MetricFactory metricFactory); @Override SetMailboxesResponse process(SetMailboxesRequest request, MailboxSession mailboxSession);  }
@Test public void processShouldReturnNotCreatedWhenMailboxExceptionOccured() throws Exception { MailboxCreationId parentId = MailboxCreationId.of("0"); MailboxId parentMailboxId = mailboxIdFactory.fromString(parentId.getCreationId()); MailboxCreationId mailboxCreationId = MailboxCreationId.of("1"); SetMailboxesRequest request = SetMailboxesRequest.builder() .create(mailboxCreationId, MailboxCreateRequest.builder().name("name").parentId(parentId).build()) .build(); MailboxSession mailboxSession = mock(MailboxSession.class); when(mailboxManager.getMailbox(parentMailboxId, mailboxSession)) .thenThrow(new MailboxException()); SetMailboxesResponse setMailboxesResponse = sut.process(request, mailboxSession); assertThat(setMailboxesResponse.getCreated()).isEmpty(); assertThat(setMailboxesResponse.getNotCreated()).containsEntry(mailboxCreationId, SetError.builder() .type(SetError.Type.ERROR) .description("An error occurred when creating the mailbox '1'") .build()); }