/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package javax.faces.component;
import static org.apache.myfaces.Assert.assertException;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.same;
import static org.testng.Assert.assertEquals;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import javax.faces.context.FacesContext;
import org.apache.myfaces.TestRunner;
import org.testng.annotations.Test;
/**
* @author Mathias Broekelmann (latest modification by $Author: bommel $)
* @version $Revision: 1187701 $ $Date: 2011-10-22 14:21:54 +0200 (Sat, 22 Oct 2011) $
*/
public class UIComponentTest extends UIComponentTestBase
{
/**
* Test method for {@link javax.faces.component.UIComponent#getFacetCount()}.
*/
@Test
public void testGetFacetCount() throws Exception
{
Method[] methods = {UIComponent.class.getDeclaredMethod("getFacets", (Class<?>[])null)};
UIComponent component = _mocksControl.createMock(UIComponent.class, methods);
Map<String, UIComponent> map = new HashMap<String, UIComponent>();
map.put("xxx1", new UIInput());
map.put("xxx2", new UIInput());
map.put("xxx3", new UIInput());
expect(component.getFacets()).andReturn(map);
_mocksControl.replay();
assertEquals(3, component.getFacetCount());
_mocksControl.verify();
_mocksControl.reset();
expect(component.getFacets()).andReturn(null);
_mocksControl.replay();
assertEquals(0, component.getFacetCount());
_mocksControl.verify();
}
/**
* Test method for
* {@link javax.faces.component.UIComponent#getContainerClientId(javax.faces.context.FacesContext)}.
*
* @throws Exception
*/
@Test
public void testGetContainerClientId() throws Exception
{
Collection<Method> mockedMethods = new ArrayList<Method>();
Class<UIComponent> clazz = UIComponent.class;
mockedMethods.add(clazz.getDeclaredMethod("getClientId", new Class[] { FacesContext.class }));
final UIComponent testimpl = _mocksControl.createMock(clazz, mockedMethods.toArray(new Method[mockedMethods
.size()]));
_mocksControl.checkOrder(true);
assertException(NullPointerException.class, new TestRunner()
{
public void run() throws Throwable
{
testimpl.getContainerClientId(null);
}
});
expect(testimpl.getClientId(same(_facesContext))).andReturn("xyz");
_mocksControl.replay();
assertEquals("xyz", testimpl.getContainerClientId(_facesContext));
_mocksControl.verify();
}
}