PropertyDelegator extends BaseDelegator implements IPropertyDelegator { @Override public String setProperty( final String name, final String value, final PropertyOptions opts) throws P4JavaException { if (isBlank(name)) { if (opts == null || isBlank(opts.getName())) { throw new IllegalArgumentException("Property/option name shouldn't null or empty"); } } if (isBlank(value)) { if (opts == null || isBlank(opts.getValue())) { throw new IllegalArgumentException("Property/option value shouldn't null or empty"); } } PropertyOptions propertyOptions = opts; if (isNull(opts)) { propertyOptions = new PropertyOptions(); } if (isNotBlank(name)) { propertyOptions.setName(name); } if (isNotBlank(value)) { propertyOptions.setValue(value); } List<Map<String, Object>> resultMaps = execMapCmdList( PROPERTY, processParameters(propertyOptions, null, new String[]{"-a"}, server), null); return parseCommandResultMapAsString(resultMaps); } PropertyDelegator(IOptionsServer server); @Override String setProperty(
            final String name,
            final String value,
            final PropertyOptions opts); @Override List<IProperty> getProperty(final GetPropertyOptions opts); @Override String deleteProperty(final String name, final PropertyOptions opts);  }
@Test public void testSetPropertyShouldReturnNonBlankPropertyNameWhenPropertyOptionsIsNull() throws Exception { name = "not blank name"; when(server.execMapCmdList(eq(PROPERTY.toString()), any(String[].class), eq(null))) .thenReturn(resultMaps); propertyOptions = null; String setProperty = propertyDelegator.setProperty(name, value, propertyOptions); assertThat(setProperty, nullValue()); }
@Test public void testSetPropertyShouldReturnNonBlankPropertyNameWhenPropertyOptionsIsNonNull() throws Exception { name = "not blank name"; when(server.execMapCmdList(eq(PROPERTY.toString()), any(String[].class), eq(null))) .thenReturn(resultMaps); when(propertyOptions.getName()).thenReturn(name); when(propertyOptions.getValue()).thenReturn(value); String setProperty = propertyDelegator.setProperty(name, value, propertyOptions); assertThat(setProperty, nullValue()); verify(propertyOptions).setName(name); verify(propertyOptions).setValue(value); }
@Test public void testSetPropertyShouldReturnNonBlankPropertyNameWhenPropertyOptionsIsNull() throws Exception { name = "not blank name"; when(server.execMapCmdList(eq(PROPERTY.toString()), any(String[].class), eq((Map<String, Object>)null))) .thenReturn(resultMaps); propertyOptions = null; String setProperty = propertyDelegator.setProperty(name, value, propertyOptions); assertThat(isNoneBlank(setProperty), is(true)); }
@Test public void testSetPropertyShouldReturnNonBlankPropertyNameWhenPropertyOptionsIsNonNull() throws Exception { name = "not blank name"; when(server.execMapCmdList(eq(PROPERTY.toString()), any(String[].class), eq((Map<String, Object>)null))) .thenReturn(resultMaps); when(propertyOptions.getName()).thenReturn(name); when(propertyOptions.getValue()).thenReturn(value); String setProperty = propertyDelegator.setProperty(name, value, propertyOptions); assertThat(isNoneBlank(setProperty), is(true)); verify(propertyOptions).setName(name); verify(propertyOptions).setValue(value); }
@Test public void testSetPropertyShouldReturnNonBlankPropertyNameWhenPropertyOptionsIsNull() throws Exception { name = "not blank name"; when(server.execMapCmdList(eq(PROPERTY.toString()), any(String[].class), eq(null))) .thenReturn(resultMaps); propertyOptions = null; String setProperty = propertyDelegator.setProperty(name, value, propertyOptions); assertThat(isNoneBlank(setProperty), is(true)); }
@Test public void testSetPropertyShouldReturnNonBlankPropertyNameWhenPropertyOptionsIsNonNull() throws Exception { name = "not blank name"; when(server.execMapCmdList(eq(PROPERTY.toString()), any(String[].class), eq(null))) .thenReturn(resultMaps); when(propertyOptions.getName()).thenReturn(name); when(propertyOptions.getValue()).thenReturn(value); String setProperty = propertyDelegator.setProperty(name, value, propertyOptions); assertThat(isNoneBlank(setProperty), is(true)); verify(propertyOptions).setName(name); verify(propertyOptions).setValue(value); }