JiraLinkGenerator { public String generateLink(final String issueSummary, final String issueDescription, final String issueReporter) { final Map<String, Object> map = new LinkedHashMap<String, Object>(); map.put("summary", issueSummary); map.put("description", issueDescription); map.put("reporter", issueReporter); final StringBuilder sb = new StringBuilder(); for (final Map.Entry<?, ?> entry : map.entrySet()) { if (sb.length() > 0) { sb.append("&"); } sb.append(String.format("%s=%s", urlEncodeUTF8(entry.getKey() .toString()), urlEncodeUTF8(entry.getValue().toString()))); } return String.format("%s%s", rootLink,sb.toString()); } JiraLinkGenerator(final String link); String urlEncodeUTF8(String s); String generateLink(final String issueSummary, final String issueDescription, final String issueReporter);  }
@Test public void validEncodedDataTest() { final String rootLink = "www.some-link.net&"; JiraLinkGenerator jiraLink = new JiraLinkGenerator(rootLink); String expectedString = rootLink + "summary=Summary&description=Description&reporter=Toto"; String generatedLink = jiraLink.generateLink("Summary", "Description", "Toto"); assertEquals(expectedString,generatedLink); }
@Test public void validEncodedDataTestWithSpace() { final String rootLink = "www.some-link.net&"; JiraLinkGenerator jiraLink= new JiraLinkGenerator(rootLink); String expectedString = rootLink + "summary=This+is+the+Summary&description=This+is+the+Description&reporter=Toto"; String generatedLink = jiraLink.generateLink("This is the Summary", "This is the Description", "Toto"); assertEquals(expectedString,generatedLink); }