@Test(dataProvider = "edgeValues") public void testVerifyFunctionArguments(Boolean bool, String s) throws Exception { FunctionRequest request = mock(FunctionRequest.class); when(request.getNumberOfArguments()).thenReturn(testling.getExpectedNumberOfArguments()); when(request.getArguments()).thenReturn(Arrays.asList(bool, s)); testling.verifyFunctionArguments(request, testling.getExpectedNumberOfArguments(), testling.getExpectedArgumentTypes()); }
protected void verifyFunctionArguments(FunctionRequest request, int expectedNumberOfArguments, List<Class> expectedArgumentTypes) { if (request.getNumberOfArguments() != expectedNumberOfArguments) { throw new IllegalArgumentException( String.format("Wrong number of arguments for function '%s' provided. Expected: '%s', actual: '%s'.", name(), expectedNumberOfArguments, request.getNumberOfArguments()) ); } for (int i = 0; i < request.getNumberOfArguments(); i++) { final int argPos = i; final Class expectedClassDef = expectedArgumentTypes.get(argPos); Optional.ofNullable(request.getArguments().get(argPos)) .map(Object::getClass) .filter(c -> !expectedClassDef.isAssignableFrom(c)) .ifPresent(c -> { throw new IllegalArgumentException( String.format("Wrong %s. argument type for function '%s' provided. Expected: '%s', actual: '%s'.", (argPos + 1), name(), expectedClassDef, c)); }); } }
AbstractFunction extends SimpleJtwigFunction { protected void verifyFunctionArguments(FunctionRequest request, int expectedNumberOfArguments, List<Class> expectedArgumentTypes) { if (request.getNumberOfArguments() != expectedNumberOfArguments) { throw new IllegalArgumentException( String.format("Wrong number of arguments for function '%s' provided. Expected: '%s', actual: '%s'.", name(), expectedNumberOfArguments, request.getNumberOfArguments()) ); } for (int i = 0; i < request.getNumberOfArguments(); i++) { final int argPos = i; final Class expectedClassDef = expectedArgumentTypes.get(argPos); Optional.ofNullable(request.getArguments().get(argPos)) .map(Object::getClass) .filter(c -> !expectedClassDef.isAssignableFrom(c)) .ifPresent(c -> { throw new IllegalArgumentException( String.format("Wrong %s. argument type for function '%s' provided. Expected: '%s', actual: '%s'.", (argPos + 1), name(), expectedClassDef, c)); }); } } }
AbstractFunction extends SimpleJtwigFunction { protected void verifyFunctionArguments(FunctionRequest request, int expectedNumberOfArguments, List<Class> expectedArgumentTypes) { if (request.getNumberOfArguments() != expectedNumberOfArguments) { throw new IllegalArgumentException( String.format("Wrong number of arguments for function '%s' provided. Expected: '%s', actual: '%s'.", name(), expectedNumberOfArguments, request.getNumberOfArguments()) ); } for (int i = 0; i < request.getNumberOfArguments(); i++) { final int argPos = i; final Class expectedClassDef = expectedArgumentTypes.get(argPos); Optional.ofNullable(request.getArguments().get(argPos)) .map(Object::getClass) .filter(c -> !expectedClassDef.isAssignableFrom(c)) .ifPresent(c -> { throw new IllegalArgumentException( String.format("Wrong %s. argument type for function '%s' provided. Expected: '%s', actual: '%s'.", (argPos + 1), name(), expectedClassDef, c)); }); } }  }
AbstractFunction extends SimpleJtwigFunction { protected void verifyFunctionArguments(FunctionRequest request, int expectedNumberOfArguments, List<Class> expectedArgumentTypes) { if (request.getNumberOfArguments() != expectedNumberOfArguments) { throw new IllegalArgumentException( String.format("Wrong number of arguments for function '%s' provided. Expected: '%s', actual: '%s'.", name(), expectedNumberOfArguments, request.getNumberOfArguments()) ); } for (int i = 0; i < request.getNumberOfArguments(); i++) { final int argPos = i; final Class expectedClassDef = expectedArgumentTypes.get(argPos); Optional.ofNullable(request.getArguments().get(argPos)) .map(Object::getClass) .filter(c -> !expectedClassDef.isAssignableFrom(c)) .ifPresent(c -> { throw new IllegalArgumentException( String.format("Wrong %s. argument type for function '%s' provided. Expected: '%s', actual: '%s'.", (argPos + 1), name(), expectedClassDef, c)); }); } }  @Override final Object execute(FunctionRequest request); }
AbstractFunction extends SimpleJtwigFunction { protected void verifyFunctionArguments(FunctionRequest request, int expectedNumberOfArguments, List<Class> expectedArgumentTypes) { if (request.getNumberOfArguments() != expectedNumberOfArguments) { throw new IllegalArgumentException( String.format("Wrong number of arguments for function '%s' provided. Expected: '%s', actual: '%s'.", name(), expectedNumberOfArguments, request.getNumberOfArguments()) ); } for (int i = 0; i < request.getNumberOfArguments(); i++) { final int argPos = i; final Class expectedClassDef = expectedArgumentTypes.get(argPos); Optional.ofNullable(request.getArguments().get(argPos)) .map(Object::getClass) .filter(c -> !expectedClassDef.isAssignableFrom(c)) .ifPresent(c -> { throw new IllegalArgumentException( String.format("Wrong %s. argument type for function '%s' provided. Expected: '%s', actual: '%s'.", (argPos + 1), name(), expectedClassDef, c)); }); } }  @Override final Object execute(FunctionRequest request);  }