1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package javax.faces.validator;
20
21 import static org.easymock.EasyMock.expect;
22 import static org.testng.Assert.assertEquals;
23
24 import java.util.Locale;
25
26 import javax.el.ELContext;
27 import javax.el.ExpressionFactory;
28 import javax.el.ValueExpression;
29 import javax.faces.application.Application;
30 import javax.faces.application.ViewHandler;
31 import javax.faces.component.UIViewRoot;
32
33 import org.apache.shale.test.mock.MockFacesContext12;
34 import org.easymock.classextension.EasyMock;
35 import org.easymock.classextension.IMocksControl;
36 import org.testng.annotations.Test;
37
38
39
40
41
42 public class _MessageUtilsTest
43 {
44
45
46
47
48
49 @Test
50 public void testErrorMessage()
51 {
52 UIViewRoot root = new UIViewRoot();
53 MockFacesContext12 facesContext = new MockFacesContext12();
54 IMocksControl mocksControl = EasyMock.createControl();
55 Application application = mocksControl.createMock(Application.class);
56 ViewHandler viewHandler = mocksControl.createMock(ViewHandler.class);
57 ELContext elContext = mocksControl.createMock(ELContext.class);
58 ExpressionFactory expressionFactory = mocksControl.createMock(ExpressionFactory.class);
59 ValueExpression valueExpression = mocksControl.createMock(ValueExpression.class);
60 facesContext.setApplication(application);
61 facesContext.setViewRoot(root);
62 facesContext.setELContext(elContext);
63
64 expect(application.getViewHandler()).andReturn(viewHandler);
65 expect(viewHandler.calculateLocale(facesContext)).andReturn(Locale.ENGLISH);
66 expect(application.getMessageBundle()).andReturn("javax.faces.Messages");
67 expect(application.getExpressionFactory()).andReturn(expressionFactory);
68 String s = "xxx: Validation Error: Value is greater than allowable maximum of \"xyz\"";
69 expect(expressionFactory.createValueExpression(elContext,s,String.class)).andReturn(valueExpression);
70 expect(valueExpression.getValue(elContext)).andReturn(s);
71 mocksControl.replay();
72
73 assertEquals(_MessageUtils.getErrorMessage(facesContext, "javax.faces.validator.DoubleRangeValidator.MAXIMUM",
74 new Object[] { "xyz", "xxx" }).getDetail(),
75 "xxx: Validation Error: Value is greater than allowable maximum of \"xyz\"");
76 }
77
78 }