OfficeListTag extends BodyTagSupport { void getBranchOffices(XmlBuilder html, List<OfficeHierarchyDto> officeList, Locale preferredUserLocale, String loggedInOfficeSearchId, String branchName) { html.singleTag("br"); html.startTag("span", "class", "fontnormalBold"); html.text(branchName); html.endTag("span"); html.singleTag("br"); if (officeList == null) { html.startTag("span", "class", "fontnormal"); html.text(MessageLookup.getLocalizedMessage("Office.labelNo")); html.text(" "); html.text(branchName.toLowerCase()); html.text(" "); html.text(MessageLookup.getLocalizedMessage("Office.labelPresent")); html.endTag("span"); } else { for (int i = 0; i < officeList.size(); i++) { OfficeHierarchyDto officeParent = officeList.get(i); Set<OfficeHierarchyDto> branchList = new TreeSet<OfficeHierarchyDto>(); for (OfficeHierarchyDto dataScopeBranch : officeParent.getChildren()) { if (dataScopeBranch.getSearchId().startsWith(loggedInOfficeSearchId) && dataScopeBranch.isActive()) { branchList.add(dataScopeBranch); } } if (branchList.size() > 0) { if (i > 0) { html.singleTag("br"); } html.startTag("span", "class", "fontnormal"); html.text(officeParent.getOfficeName()); html.endTag("span"); html.startTag("table", "width", "90%", "border", "0", "cellspacing", "0", "cellpadding", "0"); for (OfficeHierarchyDto office : branchList) { html.startTag("tr", "class", "fontnormal"); bullet(html); html.startTag("td", "width", "99%"); html.append(getLink(office.getOfficeId(), office.getOfficeName())); html.endTag("td"); html.endTag("tr"); } html.endTag("table"); } } } } OfficeListTag();  OfficeListTag(String action, String method, String flow); @Override int doStartTag(); String getActionName(); void setActionName(String actionName); String getMethodName(); void setMethodName(String methodName); String getOnlyBranchOffices(); void setOnlyBranchOffices(String onlyBranchOffices); String replaceSpaces(String officeName); String getFlowKey(); void setFlowKey(String flowKey);  }
@Test public void testNoBranches() throws Exception { new OfficeListTag().getBranchOffices(result, null, userContext.getPreferredLocale(), null, "Branch"); assertWellFormedFragment(result.toString()); }
@Test public void testBranches() throws Exception { createSomeOffices(); Assert.assertEquals(2, regional.getBranchOnlyChildren().size()); List<OfficeBO> officeList = new ArrayList<OfficeBO>(); officeList.add(regional); List<OfficeHierarchyDto> officeHierarchy = OfficeBO .convertToBranchOnlyHierarchyWithParentsOfficeHierarchy(officeList); new OfficeListTag().getBranchOffices(result, officeHierarchy, userContext.getPreferredLocale(), branch .getSearchId(), "Branch"); String html = result.toString(); assertWellFormedFragment(html); StringAssert.assertContains("Trinidad&amp;Tobago", html); StringAssert.assertNotContains("TheGambia", html); }