From 25c480efd18b83d486cc616340f1dcd921de24c8 Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Wed, 16 Apr 2014 17:46:43 +0200 Subject: Do assert falses and reasons rather than throwing exceptions --- src/test/java/MainTest.java | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) (limited to 'src/test/java/MainTest.java') diff --git a/src/test/java/MainTest.java b/src/test/java/MainTest.java index 1ccc7e9..4c70579 100644 --- a/src/test/java/MainTest.java +++ b/src/test/java/MainTest.java @@ -49,12 +49,10 @@ public class MainTest { String itemType = thisItem.substring(0,delim); OutcomeValidator validator = validators.get(itemType); String data = Gateway.getResource().getTextResource(null, "boot/"+thisItem+(itemType.equals("OD")?".xsd":".xml")); - assert data!=null; + assert data!=null : "Boot "+itemType+" data item "+thisItem+" not found"; String errors = validator.validate(data); - if (errors.length() > 0) { - Logger.error("Kernel resource "+thisItem+" has errors :"+errors); - } - assert errors.length()==0; + + assert errors.length()==0 : "Kernel resource "+thisItem+" has errors :"+errors; if (itemType.equals("CA") || itemType.equals("EA") || itemType.equals("SM")) { Logger.msg(1, "Remarshalling "+thisItem); @@ -66,10 +64,7 @@ public class MainTest { Logger.msg("Marshall/remarshall of "+thisItem+" took "+(now-then)+"ms"); castorTime+=(now-then); errors = validator.validate(remarshalled); - if (errors.length() > 0) { - Logger.error("Remarshalled resource "+thisItem+" has errors :"+errors+"\nRemarshalled form:\n"+remarshalled); - } - assert errors.length()==0; + assert errors.length()==0 : "Remarshalled resource "+thisItem+" has errors :"+errors+"\nRemarshalled form:\n"+remarshalled; // Diff xmlDiff = new Diff(data, remarshalled); // if (!xmlDiff.identical()) { @@ -91,22 +86,19 @@ public class MainTest { OutcomeValidator valid = new OutcomeValidator(getSchema("Script", 0, "boot/OD/Script.xsd")); String testScriptString = FileStringUtility.url2String(MainTest.class.getResource("TestScript.xml")); String errors = valid.validate(testScriptString); - if (errors.length()>0) { - Logger.error("Test script not valid to schema: "+errors); - } - assert errors.length()==0; + assert errors.length()==0 : "Test script not valid to schema: "+errors; Script testScript = new Script(testScriptString); - assert testScript.getInputParams().size()==1; - assert testScript.getInputParams().get("test")!=null; + assert testScript.getInputParams().size()==1 : "Script input param count wrong"; + assert testScript.getInputParams().get("test")!=null : "Could not retrieve script input param value"; testScript.setInputParamValue("test", "Test"); - assert testScript.getInputParams().get("test").getInitialised(); + assert testScript.getInputParams().get("test").getInitialised() : "Script is not initialized when it should be"; Object result = testScript.execute(); - assert result!=null; - assert result instanceof String; - assert ((String)result).equals("TestTest"); + assert result!=null : "Script returned null result"; + assert result instanceof String : "Script failed to return a String"; + assert ((String)result).equals("TestTest") : "Script failed to produce correct result: "+result; } public void testStateMachine() throws Exception { @@ -114,6 +106,6 @@ public class MainTest { String smXml = FileStringUtility.url2String(MainTest.class.getResource("TestStateMachine.xml")); StateMachine sm = (StateMachine)Gateway.getMarshaller().unmarshall(smXml); sm.validate(); - assert sm.isCoherent(); + assert sm.isCoherent() : "Test StateMachine is reporting that it is not coherent"; } } -- cgit v1.2.3