public void testFilteredByTag() { ClaimListController claimListController = new ClaimListController(); int claim1Id = claimListController.addClaim( "Claim 1", new GregorianCalendar().getTime(), new GregorianCalendar().getTime(), "description", new User("Jim", "123")); int claim2Id = claimListController.addClaim( "Claim 2", new GregorianCalendar().getTime(), new GregorianCalendar().getTime(), "description", new User("Jim", "123")); Claim claim1 = claimListController.getClaim(claim1Id); Claim claim2 = claimListController.getClaim(claim2Id); try { claim1.addTag("cat"); claim2.addTag("cat"); ArrayList<String> tags = new ArrayList<String>(); tags.add("cat"); assertEquals( "there should be two claims with tag 'cat'", 2, claimListController.filterByTag("Jim", tags).size()); } catch (AlreadyExistsException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
// US03.03.01 As a claimant, I want to filter the list of expense claims by tags, to show only // those claims that have at least one tag matching any of a given set of one or more filter tags. public void testFilterByTags() throws AlreadyExistsException { String username = "******"; int max = 10; // Create user and claim list controller User u = new User(username, "Password"); ClaimListController clt = new ClaimListController(); // Populate claims list for (int i = 1; i <= max; i++) { // Add new claim to claims list int claimID = clt.addClaim(String.valueOf(i), new Date(), new Date(), "description", u); // Add tags to claim ({1, ..., i}) for (int j = 1; j <= i; j++) { clt.addTagToClaim(claimID, String.valueOf(j)); } } // Test filtering by tags for (int i = 1; i <= max; i++) { ArrayList<String> tags = new ArrayList<String>(); for (int j = i; j <= max; j++) { // Add tag to filter tags list tags.add(String.valueOf(j)); // Filtered list ArrayList<Claim> fcl = clt.filterByTag(username, tags); // Make sure the filtered tags list is correct assertEquals( "Filtered by tags list has the wrong number of claims", max - (i - 1), fcl.size()); for (Claim claim : fcl) { // Check every claim of filtered list boolean bool = false; for (String tag : claim.getTagList()) { // Compare claim's tag list with filter tag list if (tags.contains(tag)) bool = true; } // Make sure there was a common tag assertTrue("Claim has no common tags", bool); } } } }