XmlIndentation extends TransformationUtility<XmlIndentation> { @Override protected TUExecutionResult execution(File transformedAppFolder, TransformationContext transformationContext) { TUExecutionResult result = null; try { File xmlFile = getAbsoluteFile(transformedAppFolder, transformationContext); String indentation = getFirst(xmlFile); if (indentation == null) { result = TUExecutionResult.nullResult(this); } else { result = TUExecutionResult.value(this, indentation); } } catch (FileNotFoundException e) { String message = "File " + getRelativePath() + " does not exist"; TransformationUtilityException tuex = new TransformationUtilityException(message, e); result = TUExecutionResult.error(this, tuex); } catch (WstxUnexpectedCharException e) { String message = "File " + getRelativePath() + " is not recognized as a valid XML file"; TransformationUtilityException tuex = new TransformationUtilityException(message, e); result = TUExecutionResult.error(this, tuex); } catch (Exception e) { result = TUExecutionResult.error(this, e); } return result; }  static String getFirst(File xmlFile); @Override String getDescription();  }
@Test public void notExistentFileTest() { XmlIndentation xmlIndentation = new XmlIndentation().relative("cake.xml"); TUExecutionResult executionResult = xmlIndentation.execution(transformedAppFolder, transformationContext); Assert.assertEquals(executionResult.getType(), TUExecutionResult.Type.ERROR); Assert.assertEquals(executionResult.getException().getClass(), TransformationUtilityException.class); Assert.assertEquals(executionResult.getException().getMessage(), "File cake.xml does not exist"); Assert.assertNull(executionResult.getValue()); }
@Test public void notXmlFileTest() { XmlIndentation xmlIndentation = new XmlIndentation().relative("blah/bli"); TUExecutionResult executionResult = xmlIndentation.execution(transformedAppFolder, transformationContext); Assert.assertEquals(executionResult.getType(), TUExecutionResult.Type.ERROR); Assert.assertEquals(executionResult.getException().getClass(), TransformationUtilityException.class); Assert.assertEquals(executionResult.getException().getMessage(), "File blah/bli is not recognized as a valid XML file"); Assert.assertNull(executionResult.getValue()); }