1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.uif.field;
17
18 import org.junit.Before;
19 import org.junit.Test;
20 import org.kuali.rice.krad.uif.component.Component;
21 import org.kuali.rice.krad.uif.element.Label;
22 import org.kuali.rice.krad.uif.element.Message;
23 import org.kuali.rice.krad.uif.lifecycle.ViewLifecycle;
24 import org.kuali.rice.krad.uif.service.ViewHelperService;
25 import org.kuali.rice.krad.uif.view.View;
26 import org.mockito.Mockito;
27
28 import static org.junit.Assert.assertFalse;
29 import static org.junit.Assert.assertTrue;
30 import static org.mockito.Mockito.mock;
31 import static org.mockito.Mockito.when;
32
33
34
35
36
37
38 public class FieldBaseTest {
39
40 View view = null;
41
42 @Before
43 public void setUp() {
44 view = Mockito.mock(View.class);
45 ViewHelperService mockViewHelperService = mock(ViewHelperService.class);
46 when(view.getViewHelperService()).thenReturn(mockViewHelperService);
47 when(view.copy()).thenReturn(view);
48 }
49
50 @Test
51
52
53
54
55
56 public void testRequiredMessageDisplay() throws Exception {
57
58
59
60
61
62
63
64
65 ViewLifecycle.encapsulateLifecycle(view, null, null, null, new Runnable() {
66 @Override
67 public void run() {
68 Object nullModel = null;
69 Component mockComponent = mock(Component.class);
70
71
72 Label mockLabel = new Label();
73 Message message = new Message();
74 message.setMessageText("*");
75 message.setRender(true);
76
77 FieldBase fieldBase = new FieldBase();
78 fieldBase.setFieldLabel(mockLabel);
79 fieldBase.setRequired(true);
80 fieldBase.setReadOnly(false);
81
82 FieldBase fieldBaseCopy = fieldBase.<FieldBase>copy();
83 fieldBaseCopy.performFinalize(nullModel, mockComponent);
84 assertTrue(fieldBaseCopy.getFieldLabel().isRenderRequiredIndicator());
85
86
87 fieldBaseCopy = fieldBase.<FieldBase>copy();
88 fieldBaseCopy.setReadOnly(true);
89 fieldBaseCopy.performFinalize(nullModel, mockComponent);
90 assertFalse(fieldBaseCopy.getFieldLabel().isRenderRequiredIndicator());
91 }
92 });
93
94 }
95 }