### Question:
LicenseInfoHandler implements LicenseInfoService.Iface { protected LicenseInfoParsingResult filterLicenses(LicenseInfoParsingResult result, Set<LicenseNameWithText> licencesToExclude) { LicenseInfoParsingResult newResult = result.deepCopy(); if (result.getLicenseInfo() != null) { Set<LicenseNameWithText> filteredLicenses = nullToEmptySet(result.getLicenseInfo().getLicenseNamesWithTexts()) .stream() .filter(license -> { for (LicenseNameWithText excludeLicense : licencesToExclude) { if (LicenseNameWithTextUtils.licenseNameWithTextEquals(license, excludeLicense)) { return false; } } return true; }).collect(Collectors.toSet()); newResult.getLicenseInfo().setLicenseNamesWithTexts(filteredLicenses); } return newResult; } LicenseInfoHandler(); @VisibleForTesting protected  LicenseInfoHandler(AttachmentDatabaseHandler attachmentDatabaseHandler,
                              ComponentDatabaseHandler componentDatabaseHandler, ProjectDatabaseHandler projectDatabaseHandler); @Override LicenseInfoFile getLicenseInfoFile(Project project, User user, String outputGenerator,
                                              Map<String, Set<String>> releaseIdsToSelectedAttachmentIds, Map<String, Set<LicenseNameWithText>> excludedLicensesPerAttachment, String externalIds); @Override List<OutputFormatInfo> getPossibleOutputFormats(); @Override OutputFormatInfo getOutputFormatInfoForGeneratorClass(String generatorClassName); @Override List<LicenseInfoParsingResult> getLicenseInfoForAttachment(Release release, String attachmentContentId, User user); @Override LicenseObligationsStatusInfo getProjectObligationStatus(Map<String, ObligationStatusInfo> obligationStatusMap, List<LicenseInfoParsingResult> licenseResults, 
            Map<String, String> excludedReleaseIdToAcceptedCLI); @Override LicenseInfoParsingResult createLicenseToObligationMapping(LicenseInfoParsingResult licenseResult, ObligationParsingResult obligationResult); @Override List<ObligationParsingResult> getObligationsForAttachment(Release release, String attachmentContentId, User user); @Override String getDefaultLicenseInfoHeaderText(); @Override String getDefaultObligationsText();  }### Answer:
@Test public void testThatLicensesAreFilteredAndOriginalObejctIsNotTouched() { LicenseInfoParsingResult parsingResults = new LicenseInfoParsingResult(); LicenseInfo licenseInfo = new LicenseInfo(); licenseInfo.setLicenseNamesWithTexts(ImmutableSet.of( createLicense("l1", null, null), createLicense("l1", "t1", null), createLicense("l2", "t2", null), createLicense("l3", "t3", null), createLicense("l3", "t3", "a3"), createLicense(null, "t4", null), createLicense("l4", "t4", null), createLicense(null, null, "a5"), createLicense("l5", null, "a5"), createLicense("l", "t", "a6"), createLicense("l", "t", "a7"), createLicense("l8", null, null), createLicense("l8", "t8", null), createLicense("l9", "t9", "a9"), createLicense(null, "t9", "a9") )); parsingResults.setLicenseInfo(licenseInfo); LicenseInfoParsingResult filteredResult = handler.filterLicenses(parsingResults, ImmutableSet.of( createLicense("l1", "t1", null), createLicense("l3", "t3", "a3"), createLicense(null, "t4", null), createLicense(null, null, "a5"), createLicense("l", "t", "a6"), createLicense("l8", null, null), createLicense(null, "t9", "a9") )); Assert.assertThat(filteredResult.getLicenseInfo().getLicenseNamesWithTexts(), Matchers.containsInAnyOrder( createLicense("l1", null, null), createLicense("l2", "t2", null), createLicense("l3", "t3", null), createLicense("l4", "t4", null), createLicense("l5", null, "a5"), createLicense("l", "t", "a7"), createLicense("l8", "t8", null), createLicense("l9", "t9", "a9") )); }