@Test public void blanksInterpretedAsBlanks() { HelpUrlBuilder builder = createBuilder().key("key"); HelpUrlMatcher matcher = new HelpUrlMatcher().key("key"); assertThat(builder.build(), matcher); List<String> emptys = Lists.newArrayList(null, "", " ", "\t\r\n"); for (String empty : emptys) { builder.title(empty); matcher.title(empty); assertThat(builder.build(), matcher); } for (String empty : emptys) { builder.alt(empty); matcher.alt(empty); assertThat(builder.build(), matcher); } for (String empty : emptys) { builder.url(empty); matcher.url(empty); assertThat(builder.build(), matcher); } }
@Test public void ableToCreateUrlWithPrefixAndSuffix() { HelpUrlBuilder builder = createBuilder("prefix", "suffix").key("key").url("url"); final HelpUrlMatcher matcher = new HelpUrlMatcher().key("key").url("prefixurlsuffix"); assertThat(builder.build(), matcher); builder = createBuilder(" ", "suffix").key("key").url("url"); matcher.url(" urlsuffix"); assertThat(builder.build(), matcher); builder = createBuilder("start", null).key("key").url("url"); matcher.url("starturl"); assertThat(builder.build(), matcher); }
@Test public void ableToCreateUrlWithAnchors() { HelpUrlBuilder builder = createBuilder("prefix", "suffix").key("key").url("url#anchor"); final HelpUrlMatcher matcher = new HelpUrlMatcher().key("key").url("prefixurlsuffix#anchor"); assertThat(builder.build(), matcher); builder.url("url#"); matcher.url("prefixurlsuffix#"); assertThat(builder.build(), matcher); builder = createBuilder("prefix", null).key("key").url("url#anchor"); matcher.url("prefixurl#anchor"); assertThat(builder.build(), matcher); builder = createBuilder("prefix", null).key("key").url("empty#"); matcher.url("prefixempty#"); assertThat(builder.build(), matcher); builder = createBuilder("prefix", "suffix").key("key").url("#"); matcher.url("prefixsuffix#"); assertThat(builder.build(), matcher); builder = createBuilder().key("key").url("#ignoreme"); matcher.url("#ignoreme"); assertThat(builder.build(), matcher); }
@Test public void ableToCreateSimpleUrl() { HelpUrlBuilder builder = createBuilder().key("key").alt("alt").title("title").url("url"); final HelpUrlMatcher matcher = new HelpUrlMatcher().url("url").key("key").alt("alt").title("title"); assertThat(builder.build(), matcher); assertThat(builder.build(), matcher); builder.title("newtitle"); matcher.title("newtitle"); assertThat(builder.build(), matcher); builder.alt("newalt"); matcher.alt("newalt"); assertThat(builder.build(), matcher); builder.key("newKey"); matcher.key("newKey"); assertThat(builder.build(), matcher); builder.url("newUrl"); matcher.url("newUrl"); assertThat(builder.build(), matcher); builder.local(true); matcher.local(true); assertThat(builder.build(), matcher); }
// HIROL-62 @Test public void ableToCreateUrlsWithBlankParameters() { List<String> emptys = Lists.newArrayList(null, "", " ", "\t\r\n"); for (String prefix : emptys) { for (String suffix : emptys) { final HelpUrlBuilder builder = createBuilder(prefix, suffix).key("key"); HelpUrlMatcher matcher = new HelpUrlMatcher().key("key"); if (prefix == null && suffix == null) { assertThat(builder.build(), matcher); } else { StringBuilder expectedUrl = new StringBuilder(); if (prefix != null) { expectedUrl.append(prefix); } if (suffix != null) { expectedUrl.append(suffix); } assertThat(builder.build(), matcher.url(expectedUrl.toString())); } } } }
@Test public void ableToCopyBuilderClonesBuilderAndIsIndependent() { HelpUrlBuilder builder = createBuilder().key("key").alt("alt").title("title").url("url"); final HelpUrlMatcher matcher = new HelpUrlMatcher().url("url").key("key").alt("alt").title("title"); final HelpUrlBuilder builderCopy = builder.copy(); final HelpUrlMatcher matcherCopy = matcher.copy(); assertThat(builder.build(), matcher); assertThat(builderCopy.build(), matcher); builder.title("newtitle"); matcher.title("newtitle"); assertThat(builder.build(), matcher); assertThat(builderCopy.build(), matcherCopy); builder.alt("newalt"); matcher.alt("newalt"); assertThat(builder.build(), matcher); assertThat(builderCopy.build(), matcherCopy); builder.key("newKey"); matcher.key("newKey"); assertThat(builder.build(), matcher); assertThat(builderCopy.build(), matcherCopy); builder.url("newUrl"); matcher.url("newUrl"); assertThat(builder.build(), matcher); assertThat(builderCopy.build(), matcherCopy); builder.local(true); matcher.local(true); assertThat(builder.build(), matcher); assertThat(builderCopy.build(), matcherCopy); builderCopy.url("url2").title("title2").local(false); matcherCopy.url("url2").title("title2").local(false); assertThat(builder.build(), matcher); assertThat(builderCopy.build(), matcherCopy); }