### Question:
ModuleGenerator { public void writeModule() { try { if (model.getOutputType() == NAMESPACE_AMBIENT_TYPE || model.getOutputType() == MODULE) writePackageJson(); tsdGenerator.writeTypes(); } catch (IOException e) { LOG.log(Level.SEVERE, "Caught Exception", e); this.env.getMessager().printMessage(Diagnostic.Kind.ERROR, "Could not write output file(s) " + e.getMessage()); } } ModuleGenerator(TypeScriptRenderModel model, ProcessingEnvironment env); void writeModule();  }### Answer:
@Test @DisplayName("testing handling exceptions when writing module") void writeModule() throws Exception { TypeScriptRenderModel model = new TypeScriptRenderModel(TypeScriptModel.newModelWithDefaultModule()); ProcessingEnvironment env = mock(ProcessingEnvironment.class); Filer filer = mock(Filer.class); Messager messager = mock(Messager.class); when(env.getMessager()).thenReturn(messager); when(filer.createSourceFile(any(),any(),any(),any())).thenThrow(new IOException("mocked IO Error")); when(filer.createResource(any(),any(),any())).thenThrow(new IOException("mocked IO Error")); when(env.getFiler()).thenReturn(filer); ModuleGenerator testee = new ModuleGenerator(model,env); testee.writeModule(); verify(messager).printMessage(any(),any()); }