BundleFilter { @Override public String toString() { final StringBuilder sb = new StringBuilder(); if (!providerList.isEmpty()) { sb.append(PROVIDER_TAG); for (int i = 0; i < providerList.size(); i++) { sb.append(providerList.get(i)); if (i < providerList.size() - 1) { sb.append(VALUE_SEPARATOR); } } } if (bundleName != null) { sb.append(PARAMETER_SEPARATOR); sb.append(BUNDLE_TAG); sb.append(bundleName); sb.append(VALUE_SEPARATOR); sb.append(bundleVersion); } if (processorName != null) { sb.append(PARAMETER_SEPARATOR); sb.append(PROCESSOR_TAG); sb.append(processorName); sb.append(VALUE_SEPARATOR); sb.append(processorVersion); } if (userName != null) { sb.append(PARAMETER_SEPARATOR); sb.append(USER_TAG); sb.append(userName); } return sb.toString(); } BundleFilter(); boolean isProviderSupported(String provider); int getNumSupportedProvider(); String getBundleName(); String getBundleVersion(); String getProcessorName(); String getProcessorVersion(); String getUserName(); BundleFilter withProvider(String provider); BundleFilter withTheUser(String userName); BundleFilter withTheBundle(String bundleName, String bundleVersion); BundleFilter withTheProcessor(String processorName, String processorVersion); @Override String toString(); static BundleFilter fromString(String text); static final String PROVIDER_SYSTEM; static final String PROVIDER_USER; static final String PROVIDER_ALL_USERS; static final String DUMMY_PROCESSOR_NAME; }
@Test public void testToString() throws Exception { final BundleFilter filter = new BundleFilter(); assertNotNull(filter.withProvider(BundleFilter.PROVIDER_ALL_USERS)); assertNotNull(filter.withProvider(BundleFilter.PROVIDER_USER)); assertNotNull(filter.withTheBundle("testname", "9.9")); assertNotNull(filter.withTheProcessor("proc", "1.7-SNAPSHOT")); assertNotNull(filter.withTheUser("Marco")); assertEquals("provider=ALL_USER,USER;bundle=testname,9.9;processor=proc,1.7-SNAPSHOT;user=Marco", filter.toString()); assertTrue(filter.isProviderSupported(BundleFilter.PROVIDER_ALL_USERS)); assertTrue(filter.isProviderSupported(BundleFilter.PROVIDER_USER)); assertFalse(filter.isProviderSupported(BundleFilter.PROVIDER_SYSTEM)); assertEquals("testname", filter.getBundleName()); assertEquals("9.9", filter.getBundleVersion()); assertEquals("proc", filter.getProcessorName()); assertEquals("1.7-SNAPSHOT", filter.getProcessorVersion()); assertEquals("Marco", filter.getUserName()); }