1 16 package org.apache.myfaces.el; 17 18 import javax.faces.el.MethodBinding; 19 20 21 26 public class MethodBindingTest extends ELBaseTest 27 { 28 30 public MethodBindingTest(String name) 31 { 32 super(name); 33 } 34 35 37 public void testGetType() throws Exception 38 { 39 MethodBinding mb; 40 41 mb = _application.createMethodBinding("#{a.getName}", new Class [] {}); 42 assertSame(String .class, mb.getType(_facesContext)); 43 44 mb = _application.createMethodBinding("#{a.getInt}", new Class [] {}); 45 assertSame(Integer .class, mb.getType(_facesContext)); 46 47 mb = _application.createMethodBinding("#{theA.theB.getName}", new Class [] {}); 48 assertSame(String .class, mb.getType(_facesContext)); 49 50 mb = _application.createMethodBinding("#{testmap.toString}", new Class [] {}); 51 assertSame(String .class, mb.getType(_facesContext)); 52 53 mb = _application.createMethodBinding("#{ testmap [ 0 ] [ 1 ] . toString}", new Class [] {}); 54 assertSame(String .class, mb.getType(_facesContext)); 55 56 mb = _application.createMethodBinding("#{true ? a.getName : a.getInt}", new Class [] {}); 57 assertSame(String .class, mb.getType(_facesContext)); 58 59 mb = _application.createMethodBinding("#{false ? a.getName : a.getInt}", new Class [] {}); 60 assertSame(Integer .class, mb.getType(_facesContext)); 61 62 try 63 { 64 mb = _application.createMethodBinding("#{testmap}", new Class [] {}); 65 mb.getType(_facesContext); 66 assertTrue(false); 67 } 68 catch (Exception e) { 69 } 71 } 72 73 public void testInvoke() throws Exception 74 { 75 MethodBinding mb; 76 77 mb = _application.createMethodBinding("#{a.getName}", new Class [] {}); 78 assertSame(A.NAME, mb.invoke(_facesContext, null)); 79 80 mb = _application.createMethodBinding("#{theA.theB.getName}", new Class [] {}); 81 assertSame(B.NAME, mb.invoke(_facesContext, null)); 82 83 mb = _application.createMethodBinding("#{true ? a.getName : a.getInt}", new Class [] {}); 84 assertSame(A.NAME, mb.invoke(_facesContext, null)); 85 86 mb = _application.createMethodBinding("#{false ? a.getName : a.getInt}", new Class [] {}); 87 assertEquals(new Integer (0), mb.invoke(_facesContext, null)); 88 89 mb = _application.createMethodBinding("#{false ? a.getName : true ? a.getInt : zzz}", new Class [] {}); 90 assertEquals(new Integer (0), mb.invoke(_facesContext, null)); 91 } 92 } 93 | Popular Tags |