@Test public void testFilterWithMultipleFilesAndMultipleLookUps() { String expectedLookUp1 = "lookUp1"; String expectedLookUp2 = "lookUp2"; ResourceBundle bundle1 = PropertyResourceBundle.getBundle("propertyServiceImplTest-withLookUps-1"); ResourceBundle bundle2 = PropertyResourceBundle.getBundle("propertyServiceImplTest-withLookUps-2"); List<ResourceBundle> bundles = new ArrayList<ResourceBundle>(); bundles.add(bundle1); bundles.add(bundle2); PropertyServiceImpl service = new PropertyServiceImpl(new ParenthesesLookUpKeyResolver()); Set<ClearProperty> properties = service.load(bundles); // test with just one lookUp 'lookUp1' List<String> lookUps = new ArrayList<String>(); lookUps.add(expectedLookUp1); lookUps.add(expectedLookUp2); Collection<ClearProperty> filteredProperties = service.filter(properties, lookUps); Assert.assertNotNull(filteredProperties); Assert.assertEquals(filteredProperties.size(), 4); for (ClearProperty filteredProperty : filteredProperties) { String key = filteredProperty.getKey(); String value = filteredProperty.getValue(); String lookUp = filteredProperty.getLookUpKey().getLookUp(); Assert.assertNotNull(filteredProperty.getLookUpKey()); Assert.assertNotNull(filteredProperty.getValue()); Assert.assertNotNull(filteredProperty.getKey()); Assert.assertNotNull(lookUp); if (!(key.equals("foo") || key.equals("stux") || key.equals("flix") || key.equals("baz"))) { Assert.fail("Key must either be foo, stux, flix, or baz"); } if (!(value.equals("bar") || value.equals("flux") || value.equals("glux") || value.equals("waldo"))) { Assert.fail("Key must either be bar, flux, glux, or waldo"); } if (!(lookUp.equals(expectedLookUp1) || lookUp.equals(expectedLookUp2))) { Assert.fail("lookUp either be lookUp1 or lookUp2"); } } }
@Test public void testFilterWithOneFileNoLookUps() { ResourceBundle bundle = PropertyResourceBundle.getBundle("propertyServiceImplTest-noLookUps-1"); Set<ClearProperty> properties = new HashSet<ClearProperty>(); Set<String> keys = bundle.keySet(); for (String key : keys) { String value = bundle.getString(key); LookUpKey lookUpKey = new LookUpKey(null, key, key); ClearProperty clearProperty = new ClearProperty(lookUpKey, value); properties.add(clearProperty); } PropertyServiceImpl service = new PropertyServiceImpl(null); Collection<ClearProperty> filteredProperties = service.filter(properties, new ArrayList<String>()); Assert.assertNotNull(filteredProperties); Assert.assertEquals(properties.size(), 3); for (ClearProperty filteredProperty : filteredProperties) { String key = filteredProperty.getKey(); String value = filteredProperty.getValue(); String lookUp = filteredProperty.getLookUpKey().getLookUp(); Assert.assertNotNull(filteredProperty.getLookUpKey()); Assert.assertNotNull(filteredProperty.getValue()); Assert.assertNotNull(filteredProperty.getKey()); Assert.assertNull(lookUp); if (!(key.equals("foo") || key.equals("baz") || key.equals("qix"))) { Assert.fail("Key must either be foo, baz, or qix"); } if (!(value.equals("bar") || value.equals("waldo") || value.equals("qux"))) { Assert.fail("Key must either be bar, waldo, or qux"); } } }