### Question:
JcrUserFieldDescriptor implements UserFieldDescriptor { @Override public boolean isRequired() { try { final String value = node.getProperty(REQUIRED).getString(); return (value != null && !value.isEmpty()) && Boolean.parseBoolean(value); } catch (PathNotFoundException e) { return false; } catch (RepositoryException e) { throw new MetadataRepositoryException("Unable to access field node: " + node, e); } } JcrUserFieldDescriptor(final Node node, final PropertyDefinition definition); @Nullable @Override String getDescription(); @Nullable @Override String getDisplayName(); @Override int getOrder(); @Override boolean isRequired(); @Nonnull @Override String getSystemName(); @Override int hashCode(); @Override String toString(); static final String ORDER; static final String REQUIRED; }### Answer:
@Test @SuppressWarnings("unchecked") public void isRequired() throws Exception { final Property falseProperty = Mockito.when(Mockito.mock(Property.class).getString()).thenReturn("false").getMock(); final Property trueProperty = Mockito.when(Mockito.mock(Property.class).getString()).thenReturn("true").getMock(); final Node node = Mockito.mock(Node.class); Mockito.when(node.getProperty(JcrUserFieldDescriptor.REQUIRED)) .thenReturn(falseProperty) .thenReturn(trueProperty) .thenThrow(PathNotFoundException.class); final JcrUserFieldDescriptor userField = new JcrUserFieldDescriptor(node, Mockito.mock(PropertyDefinition.class)); Assert.assertFalse(userField.isRequired()); Assert.assertTrue(userField.isRequired()); Assert.assertFalse(userField.isRequired()); }