private UserManager.UserAttribute mockUserAttribute(String name, String defaultValue, boolean isMandatory, boolean isEditable) { UserManager.UserAttribute attr = mock(UserManager.UserAttribute.class); when(attr.getName()).thenReturn(name); when(attr.getDefaultValue()).thenReturn(defaultValue); when(attr.isMandatory()).thenReturn(isMandatory); when(attr.isEditable()).thenReturn(isEditable); return attr; } }
private UserManager.UserAttribute mockUserAttribute(String name, String defaultValue, boolean isMandatory, boolean isEditable) { UserManager.UserAttribute attr = mock(UserManager.UserAttribute.class); when(attr.getName()).thenReturn(name); when(attr.getDefaultValue()).thenReturn(defaultValue); when(attr.isMandatory()).thenReturn(isMandatory); when(attr.isEditable()).thenReturn(isEditable); return attr; } }
@Override public UserManager.UserAttribute answer(InvocationOnMock invocationOnMock) throws Throwable { final String _name = (String) invocationOnMock.getArguments()[0]; final Boolean _isMandatory = (Boolean) invocationOnMock.getArguments()[1]; final Boolean _isEditable = (Boolean) invocationOnMock.getArguments()[2]; final String _defaultValue = (String) invocationOnMock.getArguments()[3]; final UserManager.UserAttribute attribute = mock(UserManager.UserAttribute.class); when(attribute.getName()).thenReturn(_name); when(attribute.isMandatory()).thenReturn(_isMandatory); when(attribute.isEditable()).thenReturn(_isEditable); when(attribute.getDefaultValue()).thenReturn(_defaultValue); return attribute; } }).when(userSystemManager).createUserAttribute(anyString(),
UserManager.UserAttribute attr2 = mock(UserManager.UserAttribute.class); when(attr2.getName()).thenReturn("attr2"); when(attr2.getDefaultValue()).thenReturn("v2"); when(attr2.isEditable()).thenReturn(true); when(attr2.isMandatory()).thenReturn(true);
when(USER_ID.isMandatory()).thenReturn(true); when(USER_ID.isEditable()).thenReturn(false); when(USER_ID.getDefaultValue()).thenReturn(null); attributes.add(USER_ID); when(USER_FIST_NAME.isMandatory()).thenReturn(true); when(USER_FIST_NAME.isEditable()).thenReturn(true); when(USER_FIST_NAME.getDefaultValue()).thenReturn("First name"); attributes.add(USER_FIST_NAME); when(USER_LAST_NAME.isMandatory()).thenReturn(true); when(USER_LAST_NAME.isEditable()).thenReturn(true); when(USER_LAST_NAME.getDefaultValue()).thenReturn("Last name"); attributes.add(USER_LAST_NAME); when(USER_ENABLED.isMandatory()).thenReturn(true); when(USER_ENABLED.isEditable()).thenReturn(true); when(USER_ENABLED.getDefaultValue()).thenReturn("true"); attributes.add(USER_ENABLED); when(USER_EMAIL.isMandatory()).thenReturn(false); when(USER_EMAIL.isEditable()).thenReturn(true); when(USER_EMAIL.getDefaultValue()).thenReturn(""); attributes.add(USER_EMAIL);
when(USER_ID.isMandatory()).thenReturn(true); when(USER_ID.isEditable()).thenReturn(false); when(USER_ID.getDefaultValue()).thenReturn(null); attributes.add(USER_ID); when(USER_FIST_NAME.isMandatory()).thenReturn(true); when(USER_FIST_NAME.isEditable()).thenReturn(true); when(USER_FIST_NAME.getDefaultValue()).thenReturn("First name"); attributes.add(USER_FIST_NAME); when(USER_LAST_NAME.isMandatory()).thenReturn(true); when(USER_LAST_NAME.isEditable()).thenReturn(true); when(USER_LAST_NAME.getDefaultValue()).thenReturn("Last name"); attributes.add(USER_LAST_NAME); when(USER_ENABLED.isMandatory()).thenReturn(true); when(USER_ENABLED.isEditable()).thenReturn(true); when(USER_ENABLED.getDefaultValue()).thenReturn("true"); attributes.add(USER_ENABLED); when(USER_EMAIL.isMandatory()).thenReturn(false); when(USER_EMAIL.isEditable()).thenReturn(true); when(USER_EMAIL.getDefaultValue()).thenReturn(""); attributes.add(USER_EMAIL);
when(USER_ID.isMandatory()).thenReturn(true); when(USER_ID.isEditable()).thenReturn(false); when(USER_ID.getDefaultValue()).thenReturn(null); attributes.add(USER_ID); when(USER_FIST_NAME.isMandatory()).thenReturn(true); when(USER_FIST_NAME.isEditable()).thenReturn(true); when(USER_FIST_NAME.getDefaultValue()).thenReturn("First name"); attributes.add(USER_FIST_NAME); when(USER_LAST_NAME.isMandatory()).thenReturn(true); when(USER_LAST_NAME.isEditable()).thenReturn(true); when(USER_LAST_NAME.getDefaultValue()).thenReturn("Last name"); attributes.add(USER_LAST_NAME); when(USER_ENABLED.isMandatory()).thenReturn(true); when(USER_ENABLED.isEditable()).thenReturn(true); when(USER_ENABLED.getDefaultValue()).thenReturn("true"); attributes.add(USER_ENABLED); when(USER_EMAIL.isMandatory()).thenReturn(false); when(USER_EMAIL.isEditable()).thenReturn(true); when(USER_EMAIL.getDefaultValue()).thenReturn(""); attributes.add(USER_EMAIL);
@Test public void testGetValue() { UserManager.UserAttribute attribute1 = mock(UserManager.UserAttribute.class); when(attribute1.getName()).thenReturn("attr1"); when(attribute1.getDefaultValue()).thenReturn("v1"); when(attribute1.isEditable()).thenReturn(true); when(attribute1.isMandatory()).thenReturn(true); UserManager.UserAttribute attribute2 = mock(UserManager.UserAttribute.class); when(attribute2.getName()).thenReturn("attr2"); when(attribute2.getDefaultValue()).thenReturn("v2"); when(attribute2.isEditable()).thenReturn(true); when(attribute2.isMandatory()).thenReturn(true); Map<UserManager.UserAttribute, String> attrs = new HashMap<UserManager.UserAttribute, String>(1); attrs.put(attribute1, "value1"); attrs.put(attribute2, "value2"); presenter.attributes = attrs; Map<String, String> result = presenter.getValue(); assertNotNull(result); assertTrue(result.size() == 2); assertEquals("value1", result.get("attr1")); assertEquals("value2", result.get("attr2")); }
@Before public void setup() { when(newUserAttributeEditor.clear()).thenReturn(newUserAttributeEditor); when(userSystemManager.isUserCapabilityEnabled(any(Capability.class))).thenReturn(true); attribute = mock(UserManager.UserAttribute.class); when(attribute.getName()).thenReturn("attr1"); when(attribute.getDefaultValue()).thenReturn("v1"); when(attribute.isEditable()).thenReturn(true); when(attribute.isMandatory()).thenReturn(true); when(userSystemManager.getUserSupportedAttribute("attr1")).thenReturn(attribute); when(view.getColumnCount()).thenReturn(0); presenter = new UserAttributesEditor(userSystemManager, confirmBox, createUserAttributeEventEvent, updateUserAttributeEventEvent, deleteUserAttributeEventEvent, errorEvent, newUserAttributeEditor, view); }
public User createNewUser(final String identifier) { User user = userSystemManager.createUser(identifier); final Collection<UserManager.UserAttribute> attrs = userSystemManager.getUserSupportedAttributes(); if (attrs != null) { for (UserManager.UserAttribute attribute : attrs) { final String name = attribute.getName(); final boolean isMandatory = attribute.isMandatory(); final boolean isEditable = attribute.isEditable(); if (isMandatory && isEditable && name != null) { final String defaultValue = attribute.getDefaultValue(); user.setProperty(name, defaultValue); } } } return user; }
public User createNewUser(final String identifier) { User user = userSystemManager.createUser(identifier); final Collection<UserManager.UserAttribute> attrs = userSystemManager.getUserSupportedAttributes(); if (attrs != null) { for (UserManager.UserAttribute attribute : attrs) { final String name = attribute.getName(); final boolean isMandatory = attribute.isMandatory(); final boolean isEditable = attribute.isEditable(); if (isMandatory && isEditable && name != null) { final String defaultValue = attribute.getDefaultValue(); user.setProperty(name, defaultValue); } } } return user; }