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.spring.config; import org.junit.Test; import org.junit.runner.RunWith; import static org.junit.Assert.*; import java.util.List; import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; import static org.mockito.Mockito.*; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.config.ConstructorArgumentValues; import org.springframework.beans.factory.support.GenericBeanDefinition; import org.w3c.dom.Element; import pl.chilldev.web.spring.config.StylesheetBeanDefinitionParser; import pl.chilldev.web.spring.model.Stylesheet; @RunWith(MockitoJUnitRunner.class) public class StylesheetBeanDefinitionParserTest { @Mock private Element element; @Test public void parse() { GenericBeanDefinition bean = new GenericBeanDefinition(); StylesheetBeanDefinitionParser parser = new StylesheetBeanDefinitionParser(bean); String href = "foo.css"; String type = "text/css"; String media = "print"; when(this.element.getAttribute("href")).thenReturn(href); when(this.element.hasAttribute("media")).thenReturn(true); when(this.element.getAttribute("media")).thenReturn(media); when(this.element.hasAttribute("type")).thenReturn(true); when(this.element.getAttribute("type")).thenReturn(type); parser.parse(this.element, null); List<BeanDefinition> stylesheets = (List<BeanDefinition>) bean.getPropertyValues() .getPropertyValue(StylesheetBeanDefinitionParser.PROPERTY_STYLESHEETS).getValue(); BeanDefinition stylesheet = stylesheets.get(0); ConstructorArgumentValues arguments = stylesheet.getConstructorArgumentValues(); assertEquals("StylesheetBeanDefinitionParser.parse() should register stylesheet with it's location.", href, arguments.getIndexedArgumentValue(0, null).getValue()); assertEquals("StylesheetBeanDefinitionParser.parse() should register stylesheet with it's MIME type.", type, arguments.getIndexedArgumentValue(1, null).getValue()); assertEquals("StylesheetBeanDefinitionParser.parse() should register stylesheet with it's media query.", media, arguments.getIndexedArgumentValue(2, null).getValue()); } }