Scorer { public int score(Project project) { String jsCode = ""; jsCode += "var scoring = " + scoringProject + ";\n"; jsCode += "result.value = scoring(project);"; return ((Number) newExecutor(jsCode).bind("project", project).execute()).intValue(); }  int score(Project project); void setScoringProject(String scoringProject);  }
@Test public void testScore() throws Exception { Scorer scorer = new Scorer(); scorer.setScoringProject("function(project) { return project.forksCount > 0 ? ( " + "project.starsCount + project.forksCount + project.contributorsCount + " + "project.commitsCount / 100 ) : 0 }"); Project project = new ProjectBuilder().starsCount(20).forksCount(10).contributorsCount(5).commitsCount(230) .create(); assertEquals(20 + 10 + 5 + 2, scorer.score(project)); project.setForksCount(0); assertEquals(0, scorer.score(project)); }