Java tutorial
/** * This file is part of the ChillDev-Web. * * @license http://mit-license.org/ The MIT license * @copyright 2014 by Rafa Wrzeszcz - Wrzasq.pl. */ package test.pl.chilldev.web.tags.page; import org.junit.Test; import org.junit.runner.RunWith; import static org.junit.Assert.*; import javax.servlet.jsp.JspContext; import javax.servlet.jsp.JspTagException; import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; import static org.mockito.Mockito.*; import org.springframework.mock.web.MockPageContext; import pl.chilldev.web.core.page.PageMetaModel; import pl.chilldev.web.tags.context.JspPageMetaModelResolver; import pl.chilldev.web.tags.context.PageMetaModelContextUtils; import pl.chilldev.web.tags.page.StylesheetTag; @RunWith(MockitoJUnitRunner.class) public class StylesheetTagTest { @Mock private PageMetaModel page; @Test public void doTag() throws JspTagException { JspContext context = new MockPageContext(); StylesheetTag tag = new StylesheetTag(); tag.setJspContext(context); // set up context String attribute = "foo"; context.setAttribute(attribute, this.page); // set up resolver PageMetaModelContextUtils.setPageMetaModelResolver(new JspPageMetaModelResolver(attribute)); String href = "bar"; String type = "baz"; String media = "quux"; // run the tag tag.setHref(href); tag.setType(type); tag.setMedia(media); tag.doTag(); verify(this.page).addStylesheet(href, type, media); } }