### Question:
SaveTranscribeConfigurationAPIController { @RequestMapping(method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody public TranscribeConfiguration saveConfiguration(@RequestBody TranscribeConfiguration configuration) throws SaveConfigurationException { return getArkCaseTranscribeService().saveConfiguration(configuration); }  @RequestMapping(method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody TranscribeConfiguration saveConfiguration(@RequestBody TranscribeConfiguration configuration); ArkCaseTranscribeService getArkCaseTranscribeService(); void setArkCaseTranscribeService(ArkCaseTranscribeService arkCaseTranscribeService);  }### Answer:
@Test public void saveConfiguration() throws Exception { TranscribeConfiguration configuration = new TranscribeConfiguration(); configuration.setEnabled(true); configuration.setAutomaticEnabled(true); configuration.setNewTranscriptionForNewVersion(false); configuration.setCopyTranscriptionForNewVersion(true); configuration.setCost(new BigDecimal("0.001")); configuration.setConfidence(80); configuration.setNumberOfFilesForProcessing(10); configuration.setWordCountPerItem(30); configuration.setProvider(TranscribeServiceProvider.AWS); configuration.setProviders(Arrays.asList(TranscribeServiceProvider.AWS)); ObjectMapper objectMapper = new ObjectMapper(); when(mockAuthentication.getName()).thenReturn("user"); when(mockArkCaseTranscribeService.saveConfiguration(any(TranscribeConfiguration.class))).thenReturn(configuration); MvcResult result = mockMvc.perform(post("/api/v1/plugin/admin/transcribe/configuration") .accept(MediaType.parseMediaType("application/json;charset=UTF-8")) .contentType(MediaType.APPLICATION_JSON) .principal(mockAuthentication) .content(objectMapper.writeValueAsString(configuration))) .andReturn(); verify(mockAuthentication).getName(); verify(mockArkCaseTranscribeService).saveConfiguration(any(TranscribeConfiguration.class)); String responseString = result.getResponse().getContentAsString(); LOG.info("Results: " + responseString); assertEquals(HttpStatus.OK.value(), result.getResponse().getStatus()); TranscribeConfiguration responseConfiguration = objectMapper.readValue(responseString, TranscribeConfiguration.class); assertNotNull(responseConfiguration); assertEquals(configuration, responseConfiguration); }
@Test public void saveConfiguration_Exception() throws Exception { TranscribeConfiguration configuration = new TranscribeConfiguration(); configuration.setEnabled(true); configuration.setAutomaticEnabled(true); configuration.setNewTranscriptionForNewVersion(false); configuration.setCopyTranscriptionForNewVersion(true); configuration.setCost(new BigDecimal("0.001")); configuration.setConfidence(80); configuration.setNumberOfFilesForProcessing(10); configuration.setWordCountPerItem(30); configuration.setProvider(TranscribeServiceProvider.AWS); configuration.setProviders(Arrays.asList(TranscribeServiceProvider.AWS)); ObjectMapper objectMapper = new ObjectMapper(); SaveConfigurationException exception = new SaveConfigurationException("error"); when(mockAuthentication.getName()).thenReturn("user"); when(mockArkCaseTranscribeService.saveConfiguration(any(TranscribeConfiguration.class))).thenThrow(exception); try { mockMvc.perform(post("/api/v1/plugin/admin/transcribe/configuration") .accept(MediaType.parseMediaType("application/json;charset=UTF-8")) .contentType(MediaType.APPLICATION_JSON) .principal(mockAuthentication) .content(objectMapper.writeValueAsString(configuration))) .andReturn(); } catch (Exception e) { assertNotNull(e); assertTrue(e.getCause() instanceof SaveConfigurationException); assertEquals("error", e.getCause().getMessage()); } }