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.ScriptBeanDefinitionParser; import pl.chilldev.web.spring.model.Script; @RunWith(MockitoJUnitRunner.class) public class ScriptBeanDefinitionParserTest { @Mock private Element element; @Test public void parse() { GenericBeanDefinition bean = new GenericBeanDefinition(); ScriptBeanDefinitionParser parser = new ScriptBeanDefinitionParser(bean); String src = "foo.js"; String type = "application/javascript"; String flow = "ASYNC"; String charset = "utf-8"; when(this.element.hasAttribute("charset")).thenReturn(true); when(this.element.getAttribute("charset")).thenReturn(charset); when(this.element.hasAttribute("flow")).thenReturn(true); when(this.element.getAttribute("flow")).thenReturn(flow); when(this.element.hasAttribute("type")).thenReturn(true); when(this.element.getAttribute("type")).thenReturn(type); when(this.element.getAttribute("src")).thenReturn(src); parser.parse(this.element, null); List<BeanDefinition> scripts = (List<BeanDefinition>) bean.getPropertyValues() .getPropertyValue(ScriptBeanDefinitionParser.PROPERTY_SCRIPTS).getValue(); BeanDefinition script = scripts.get(0); ConstructorArgumentValues arguments = script.getConstructorArgumentValues(); assertEquals("ScriptBeanDefinitionParser.parse() should register script with it's location.", src, arguments.getIndexedArgumentValue(0, null).getValue()); assertEquals("ScriptBeanDefinitionParser.parse() should register script with it's MIME type.", type, arguments.getIndexedArgumentValue(1, null).getValue()); assertEquals("ScriptBeanDefinitionParser.parse() should register script with it's loading flow.", flow, arguments.getIndexedArgumentValue(2, null).getValue()); assertEquals("ScriptBeanDefinitionParser.parse() should register script with it's charset.", charset, arguments.getIndexedArgumentValue(3, null).getValue()); } }