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(); } }
public void testTagGetterSetter() { ClaimListController claimListController = new ClaimListController(); String tag1 = "tag1"; String tag2 = "tag2"; String unusedTag = "unused tag"; int claimId = claimListController.addClaim( "Claim 1", new GregorianCalendar().getTime(), new GregorianCalendar().getTime(), "description", new User("Jim", "123")); try { claimListController.addTagToClaim(claimId, tag1); claimListController.addTagToClaim(claimId, tag2); ArrayList<String> tagList = claimListController.getTagListFromClaim(claimId); assertTrue("Wrong number of tags inside taglist", tagList.size() == 2); assertTrue("tag1 is not added", tagList.contains(tag1)); assertTrue("tag2 is not added", tagList.contains(tag2)); assertFalse("unusedTag should not be inside the taglist", tagList.contains(unusedTag)); } catch (AlreadyExistsException e) { // tag already existed. Do nothing } }
// 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); } } } }
public void testFilterByStatus() { ClaimListController claimListController = new ClaimListController(); 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")); int claim3Id = claimListController.addClaim( "Claim 3", new GregorianCalendar().getTime(), new GregorianCalendar().getTime(), "description", new User("Jim", "123")); Claim claim2 = claimListController.getClaim(claim2Id); Claim claim3 = claimListController.getClaim(claim3Id); claim2.setStatus("Approved"); claim3.setStatus("Approved"); ArrayList<Claim> approvedClaims = claimListController.filterByStatus("Approved"); assertEquals("The number of 'Approved' claims doesn't match", 2, approvedClaims.size()); }
// US01.05.01 public void testRemoveClaim() { ClaimListController clc = new ClaimListController(); clc.clear(); Date date1 = new Date(); Date date2 = new Date(); User user = new User("name", "123"); clc.addClaim("Claim", date1, date2, "description", user); assertEquals("claim was not added", 1, clc.size()); if (clc.getClaim(0).editable()) { clc.removeClaim(0); assertEquals("claim was not removed", 0, clc.size()); } else { // cannot remove claim, do nothing } }
public void testFilterByClaimant() { ClaimListController claimListController = new ClaimListController(); User claimantA = new User("Jim", "123"); User claimantB = new User("Bob", "123"); claimListController.addClaim( "Claim 1", new GregorianCalendar().getTime(), new GregorianCalendar().getTime(), "description", claimantA); claimListController.addClaim( "Claim 2", new GregorianCalendar().getTime(), new GregorianCalendar().getTime(), "description", claimantB); claimListController.addClaim( "Claim 3", new GregorianCalendar().getTime(), new GregorianCalendar().getTime(), "description", claimantB); ArrayList<Claim> claimsBelongToClaimantA = claimListController.filterByClaimant(claimantA); for (int i = 0; i < claimsBelongToClaimantA.size(); i++) { assertEquals( "filterByClaimant(claimantA) returned a claim that doesn't belong to claimantA", claimsBelongToClaimantA.get(i).getClaimant(), claimantA); } ArrayList<Claim> claimsBelongToClaimantB = claimListController.filterByClaimant(claimantB); for (int i = 0; i < claimsBelongToClaimantB.size(); i++) { assertEquals( "filterByClaimant(claimantB) returned a claim that doesn't belong to claimantB", claimsBelongToClaimantB.get(i).getClaimant(), claimantB); } }