@Test(dataProvider = "getDiffyTestCases" ) public void runDiffyTests( String testCaseName ) throws IOException { String testPath = "/json/defaultr/" + testCaseName; Map<String, Object> testUnit = JsonUtils.classpathToMap( testPath + ".json" ); Object input = testUnit.get( "input" ); Object spec = testUnit.get( "spec" ); Object expected = testUnit.get( "expected" ); Defaultr defaultr = new Defaultr(spec); Object actual = defaultr.transform( input ); JoltTestUtil.runDiffy( "failed case " + testPath, expected, actual ); }
@Override public Object transform( Object input ) { if ( input == null ) { input = new HashMap(); } if ( input instanceof List ) { if ( arrayRoot == null ) { throw new TransformException( "The Spec provided can not handle input that is a top level Json Array." ); } arrayRoot.applyChildren( input ); } else { mapRoot.applyChildren( input ); } return input; }
Defaultr implements SpecDriven, Transform { @Override public Object transform( Object input ) { if ( input == null ) { input = new HashMap(); } if ( input instanceof List ) { if ( arrayRoot == null ) { throw new TransformException( "The Spec provided can not handle input that is a top level Json Array." ); } arrayRoot.applyChildren( input ); } else { mapRoot.applyChildren( input ); } return input; } }
Defaultr implements SpecDriven, Transform { @Override public Object transform( Object input ) { if ( input == null ) { input = new HashMap(); } if ( input instanceof List ) { if ( arrayRoot == null ) { throw new TransformException( "The Spec provided can not handle input that is a top level Json Array." ); } arrayRoot.applyChildren( input ); } else { mapRoot.applyChildren( input ); } return input; } @Inject  Defaultr( Object spec ); }
Defaultr implements SpecDriven, Transform { @Override public Object transform( Object input ) { if ( input == null ) { input = new HashMap(); } if ( input instanceof List ) { if ( arrayRoot == null ) { throw new TransformException( "The Spec provided can not handle input that is a top level Json Array." ); } arrayRoot.applyChildren( input ); } else { mapRoot.applyChildren( input ); } return input; } @Inject  Defaultr( Object spec ); @Override Object transform( Object input ); }
Defaultr implements SpecDriven, Transform { @Override public Object transform( Object input ) { if ( input == null ) { input = new HashMap(); } if ( input instanceof List ) { if ( arrayRoot == null ) { throw new TransformException( "The Spec provided can not handle input that is a top level Json Array." ); } arrayRoot.applyChildren( input ); } else { mapRoot.applyChildren( input ); } return input; } @Inject  Defaultr( Object spec ); @Override Object transform( Object input );  }