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.kuali.rice.krad.uif.component.Component;
19 import org.kuali.rice.krad.uif.element.Label;
20 import org.kuali.rice.krad.uif.element.Message;
21 import org.kuali.rice.krad.uif.service.ViewHelperService;
22 import org.kuali.rice.krad.uif.view.View;
23
24 import org.junit.Test;
25
26 import static junit.framework.Assert.*;
27 import static org.mockito.Mockito.*;
28
29
30
31
32
33 public class FieldBaseTest {
34
35 @Test
36
37
38
39
40
41 public void testRequiredMessageDisplay() {
42
43
44 View mockView = mock(View.class);
45 ViewHelperService mockViewHelperService = mock(ViewHelperService.class);
46 when(mockView.getViewHelperService()).thenReturn(mockViewHelperService);
47 Object nullModel = null;
48 Component mockComponent = mock(Component.class);
49
50
51 Label mockLabel = mock(Label.class);
52
53 Message requiredMessage = new Message();
54 requiredMessage.setMessageText("*");
55 requiredMessage.setRender(true);
56 when(mockLabel.getRequiredMessage()).thenReturn(requiredMessage);
57
58 try {
59 FieldBase fieldBase = new FieldBase();
60 fieldBase.setFieldLabel(mockLabel);
61 fieldBase.setRequired(true);
62
63
64 fieldBase.setReadOnly(false);
65 fieldBase.performFinalize(mockView, nullModel, mockComponent);
66 assertTrue(fieldBase.getFieldLabel().getRequiredMessage().isRender());
67
68
69 fieldBase.setReadOnly(true);
70 fieldBase.performFinalize(mockView, nullModel, mockComponent);
71 assertFalse(fieldBase.getFieldLabel().getRequiredMessage().isRender());
72 } catch(Exception ex) {
73 fail("Unit Test Exception - " + ex.getMessage());
74 }
75 }
76 }