ZxcvbnPasswordMeter { public PasswordStrength getStrength(String password) { if (!hasInitialized) { this.initialize(); } Context context = Context.enter(); Scriptable scope = context.newObject(global); scope.setParentScope(global); StringWriter stringWriter = new StringWriter(); scope.put("writer", scope, stringWriter); scope.put("password", scope, password); String inputsAsArrayString = '[' + Joiner.on(",").join( FluentIterable.from(inputs).transform(new Function<String, String>() { public String apply(String input) { return "'" + input + "'"; } })) + ']'; context.evaluateString(scope, "var dump = function(o) { return JSON.stringify(o) };", "dump.js", 1, null); context.evaluateString(scope, "var result = zxcvbn(password, " + inputsAsArrayString + ");" + "writer.write(JSON.stringify(result))", "eval-zxcvbn.js", 1, null); ObjectMapper mapper = new ObjectMapper(); final JsonNode node; try { node = mapper.readTree(stringWriter.toString()); PasswordStrength result = mapper.readValue(new TreeTraversingParser(node), PasswordStrength.class); return result; } catch (IOException e) { throw new RuntimeException("Failed to check password strength", e); } }  ZxcvbnPasswordMeter inputs(String... input); void initialize(); PasswordStrength getStrength(String password);  }
@Test public void testZxcvbnPasswordStrength() { PasswordStrength result = checker.getStrength("toto"); Assert.assertEquals("toto", result.getPassword()); Assert.assertTrue(result.getEntropy() < 5); }