QuickLinkVisibilityControllerFactory { public static QuickLinkVisibilityController get(@Nullable String quickLinkProfileJson) { if (null == quickLinkProfileJson) { LOG.info("No quick link profile is set, will display all quicklinks."); return new ShowAllLinksVisibilityController(); } try { QuickLinksProfile profile = new QuickLinksProfileParser().parse(quickLinkProfileJson.getBytes()); return new DefaultQuickLinkVisibilityController(profile); } catch (IOException | QuickLinksProfileEvaluationException ex) { LOG.error("Unable to parse quick link profile json: " + quickLinkProfileJson, ex); return new ShowAllLinksVisibilityController(); } }  static QuickLinkVisibilityController get(@Nullable String quickLinkProfileJson);  }
@Test public void nullStringPassed() throws Exception { assertTrue( "An instance of " + ShowAllLinksVisibilityController.class.getSimpleName() + " should have been returned", QuickLinkVisibilityControllerFactory.get(null) instanceof ShowAllLinksVisibilityController); }
@Test public void invalidJsonPassed() throws Exception { assertTrue( "An instance of " + ShowAllLinksVisibilityController.class.getSimpleName() + " should have been returned", QuickLinkVisibilityControllerFactory.get("Hello world!") instanceof ShowAllLinksVisibilityController); }
@Test public void invalidProfilePassed() throws Exception { String json = Resources.toString(Resources.getResource("inconsistent_quicklinks_profile.json"), Charsets.UTF_8); assertTrue( "An instance of " + ShowAllLinksVisibilityController.class.getSimpleName() + " should have been returned", QuickLinkVisibilityControllerFactory.get(json) instanceof ShowAllLinksVisibilityController); json = Resources.toString(Resources.getResource("inconsistent_quicklinks_profile_2.json"), Charsets.UTF_8); assertTrue( "An instance of " + ShowAllLinksVisibilityController.class.getSimpleName() + " should have been returned", QuickLinkVisibilityControllerFactory.get(json) instanceof ShowAllLinksVisibilityController); }
@Test public void validProfilePassed() throws Exception { String json = Resources.toString(Resources.getResource("example_quicklinks_profile.json"), Charsets.UTF_8); assertTrue( "An instance of " + DefaultQuickLinkVisibilityController.class.getSimpleName() + " should have been returned", QuickLinkVisibilityControllerFactory.get(json) instanceof DefaultQuickLinkVisibilityController); }