| 
21 | 21 |  */  | 
22 | 22 | 
 
  | 
23 | 23 | import de.ibmix.magkit.test.jcr.NodeStubbingOperation;  | 
 | 24 | +import info.magnolia.jcr.decoration.ContentDecoratorPropertyWrapper;  | 
24 | 25 | import info.magnolia.jcr.wrapper.HTMLEscapingPropertyWrapper;  | 
25 | 26 | import org.junit.After;  | 
26 | 27 | import org.junit.Before;  | 
 | 
30 | 31 | import javax.jcr.Node;  | 
31 | 32 | import javax.jcr.Property;  | 
32 | 33 | import javax.jcr.RepositoryException;  | 
 | 34 | +import javax.jcr.Value;  | 
33 | 35 | import java.util.Calendar;  | 
34 | 36 | import java.util.Collection;  | 
35 | 37 | import java.util.TimeZone;  | 
 | 
55 | 57 | import static de.ibmix.magkit.test.jcr.NodeMockUtils.mockNode;  | 
56 | 58 | import static de.ibmix.magkit.test.jcr.NodeStubbingOperation.stubProperty;  | 
57 | 59 | import static de.ibmix.magkit.test.jcr.PropertyMockUtils.mockProperty;  | 
 | 60 | +import static de.ibmix.magkit.test.jcr.PropertyStubbingOperation.stubValues;  | 
58 | 61 | import static de.ibmix.magkit.test.jcr.ValueMockUtils.mockBinary;  | 
59 | 62 | import static org.hamcrest.MatcherAssert.assertThat;  | 
60 | 63 | import static org.hamcrest.core.Is.is;  | 
61 | 64 | import static org.hamcrest.core.IsNull.notNullValue;  | 
62 | 65 | import static org.hamcrest.core.IsNull.nullValue;  | 
63 | 66 | import static org.mockito.ArgumentMatchers.anyString;  | 
 | 67 | +import static org.mockito.Mockito.doReturn;  | 
64 | 68 | import static org.mockito.Mockito.doThrow;  | 
65 | 69 | 
 
  | 
66 | 70 | /**  | 
@@ -464,4 +468,27 @@ public void getBinaryValuesTest() throws RepositoryException {  | 
464 | 468 |         assertThat(getBinaryValues(mockProperty("test", b, a)).get(0), is(b));  | 
465 | 469 |         assertThat(getBinaryValues(mockProperty("test", b, a)).get(1), is(a));  | 
466 | 470 |     }  | 
 | 471 | + | 
 | 472 | +    @Test  | 
 | 473 | +    public void getValue() throws RepositoryException {  | 
 | 474 | +        assertThat(PropertyUtils.getValue(null), nullValue());  | 
 | 475 | + | 
 | 476 | +        Property p = mockProperty("test");  | 
 | 477 | +        assertThat(PropertyUtils.getValue(p), nullValue());  | 
 | 478 | + | 
 | 479 | +        // Test nor exception on empty multi value property:  | 
 | 480 | +        stubValues(new Value[0]).of(p);  | 
 | 481 | +        doReturn(true).when(p).isMultiple();  | 
 | 482 | +        assertThat(PropertyUtils.getValue(p), nullValue());  | 
 | 483 | + | 
 | 484 | +        stubValues("first").of(p);  | 
 | 485 | +        assertThat(PropertyUtils.getValue(p).getString(), is("first"));  | 
 | 486 | + | 
 | 487 | +        stubValues("first", "second", "third").of(p);  | 
 | 488 | +        assertThat(PropertyUtils.getValue(p).getString(), is("first"));  | 
 | 489 | + | 
 | 490 | +        // Test no NullPointerException on empty PropertyWrapper:  | 
 | 491 | +        Property wrapper = new ContentDecoratorPropertyWrapper<>(null, null);  | 
 | 492 | +        assertThat(PropertyUtils.getValue(wrapper), nullValue());  | 
 | 493 | +    }  | 
467 | 494 | }  | 
0 commit comments