PageRenderTime 6ms CodeModel.GetById 1ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/sitebricks/src/test/java/com/google/sitebricks/rendering/control/WidgetRegistryTest.java

http://github.com/dhanji/sitebricks
Java | 38 lines | 29 code | 6 blank | 3 comment | 0 complexity | b71395fd57497b59d1a2ca4b4e015945 MD5 | raw file
 1package com.google.sitebricks.rendering.control;
 2
 3import com.google.inject.Injector;
 4import com.google.sitebricks.MvelEvaluator;
 5import com.google.sitebricks.Renderable;
 6import com.google.sitebricks.compiler.EvaluatorCompiler;
 7import com.google.sitebricks.compiler.ExpressionCompileException;
 8import com.google.sitebricks.routing.PageBook;
 9import static org.easymock.EasyMock.createMock;
10import static org.easymock.EasyMock.createNiceMock;
11import org.testng.annotations.DataProvider;
12import org.testng.annotations.Test;
13
14/**
15 * @author Dhanji R. Prasanna (dhanji@gmail.com)
16 */
17public class WidgetRegistryTest {
18    private static final String WIDGETS_AND_KEYS = "widgetsAndKeys";
19
20    @DataProvider(name = WIDGETS_AND_KEYS)
21    public Object[][] get() {
22        return new Object[][] {
23            { "twidg", TextFieldWidget.class },
24            { "teasdasxt", RepeatWidget.class },
25            { "sastext", ShowIfWidget.class },
26        };
27    }
28
29    @Test(dataProvider = WIDGETS_AND_KEYS)
30    public final void storeRetrieveWidgets(final String key, final Class<Renderable> expected) throws ExpressionCompileException {
31        final WidgetRegistry registry = new DefaultWidgetRegistry(new MvelEvaluator(), createNiceMock(PageBook.class), createNiceMock(Injector.class));
32        registry.add(key, expected);
33
34        Renderable widget = registry.newWidget(key, "some=expression", new ProceedingWidgetChain(), createMock(EvaluatorCompiler.class));
35
36        assert expected.isInstance(widget) : "Wrong widget returned";
37    }
38}