public void testGenerateException4() throws Exception {
directory.delete();
directory.mkdir();
TemplateSuite suite = createMock(TemplateSuite.class);
TemplateClass clazz = createMock(TemplateClass.class);
Template template = createMock(Template.class);
@SuppressWarnings("unchecked")
Map<String, String> parameters = createMock(Map.class);
String packageName = "org.apache.tiles.autotag.test";
String runtimeClass = "org.apache.tiles.autotag.test.DoStuffRuntime";
String requestClass = "org.apache.tiles.autotag.test.DoStuffRequest";
expect(generator.getDirectoryName(directory, packageName, suite, clazz, parameters, runtimeClass, requestClass)).andReturn("mydir");
File mydir = new File(directory, "mydir");
expect(generator.getFilename(mydir , packageName, suite, clazz, parameters, runtimeClass, requestClass)).andReturn("myfile.txt");
String sampleVmPath = "/sample.vm";
expect(generator.getTemplatePath(mydir, packageName, suite, clazz, parameters, runtimeClass, requestClass)).andReturn(sampleVmPath);
expect(velocityEngine.getTemplate("/sample.vm")).andReturn(template);
template.merge(isA(VelocityContext.class), isA(FileWriter.class));
expectLastCall().andThrow(new IOException());
replay(velocityEngine, generator, suite, clazz, template, parameters);
generator.generate(directory, packageName, suite, clazz, parameters, runtimeClass, requestClass);
verify(velocityEngine, generator, suite, clazz, template, parameters);