myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dennisby...@apache.org
Subject svn commit: r381032 - in /myfaces/tomahawk/trunk/core/src/test/java/org/apache/myfaces/custom/stylesheet: MockResponseWriter.java StylesheetRendererTest.java
Date Sun, 26 Feb 2006 00:17:50 GMT
Author: dennisbyrne
Date: Sat Feb 25 16:17:47 2006
New Revision: 381032

URL: http://svn.apache.org/viewcvs?rev=381032&view=rev
Log:
one less mock class
stylesheet test now asserts something

Removed:
    myfaces/tomahawk/trunk/core/src/test/java/org/apache/myfaces/custom/stylesheet/MockResponseWriter.java
Modified:
    myfaces/tomahawk/trunk/core/src/test/java/org/apache/myfaces/custom/stylesheet/StylesheetRendererTest.java

Modified: myfaces/tomahawk/trunk/core/src/test/java/org/apache/myfaces/custom/stylesheet/StylesheetRendererTest.java
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/core/src/test/java/org/apache/myfaces/custom/stylesheet/StylesheetRendererTest.java?rev=381032&r1=381031&r2=381032&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/core/src/test/java/org/apache/myfaces/custom/stylesheet/StylesheetRendererTest.java
(original)
+++ myfaces/tomahawk/trunk/core/src/test/java/org/apache/myfaces/custom/stylesheet/StylesheetRendererTest.java
Sat Feb 25 16:17:47 2006
@@ -17,111 +17,74 @@
 package org.apache.myfaces.custom.stylesheet;
 
 import java.io.IOException;
+import java.io.StringWriter;
 
-import javax.faces.FactoryFinder;
-import javax.faces.component.UIViewRoot;
-import javax.faces.context.ExternalContext;
-import javax.faces.context.FacesContext;
-import javax.faces.context.ResponseWriter;
-import javax.faces.render.RenderKit;
-import javax.faces.render.RenderKitFactory;
-
-import junit.framework.TestCase;
-
-import org.apache.myfaces.renderkit.html.HtmlRenderKitImpl;
-import org.easymock.MockControl;
-import org.easymock.classextension.MockClassControl;
-
-
-public class StylesheetRendererTest extends TestCase {
-
-  FacesContext context;
-  MockResponseWriter writer = new MockResponseWriter();
-  
-  /*
-   * Test method for 'org.apache.myfaces.custom.stylesheet.StylesheetRenderer.encodeEnd(FacesContext,
UIComponent)'
-   */
-  public void testInline() throws IOException {
-
-    Stylesheet stylesheet = new Stylesheet();
-    stylesheet.setPath("test.css");
-    stylesheet.setInline(true);
-    stylesheet.setMedia("printer");
-    stylesheet.encodeEnd(this.context);
-    this.context.renderResponse();
-    
-    System.out.println(this.writer.getContent());
-  }
-
-  public void testLink() throws IOException {
-
-    Stylesheet stylesheet = new Stylesheet();
-    stylesheet.setPath("test.css");
-    stylesheet.setMedia("printer");
-    stylesheet.encodeEnd(this.context);
-    this.context.renderResponse();
-    
-    System.out.println(this.writer.getContent());
-  }
-  private FacesContext getMockFacesContext(ResponseWriter writer) {
-
-    FactoryFinder.setFactory(FactoryFinder.RENDER_KIT_FACTORY,
-        "org.apache.myfaces.renderkit.RenderKitFactoryImpl");
-    
-    MockControl ctxControl = MockClassControl.createControl(FacesContext.class);
-    FacesContext mockFacesCtx = (FacesContext) ctxControl.getMock();
-    
-    MockControl extCtxControl = MockClassControl.createControl(ExternalContext.class);
-    ExternalContext mockExtCtx = (ExternalContext)extCtxControl.getMock();
-    mockFacesCtx.getExternalContext();
-    ctxControl.setReturnValue(mockExtCtx);
-    
-    mockFacesCtx.renderResponse();
-    ctxControl.setVoidCallable();
-    
-    mockExtCtx.getRequestContextPath();
-    extCtxControl.setReturnValue("");
-    
-    MockControl rendererKitControl = MockClassControl.createControl(HtmlRenderKitImpl.class);
-    RenderKit rKit = (RenderKit) rendererKitControl.getMock();
-    rKit.getRenderer(Stylesheet.COMPONENT_FAMILY, Stylesheet.COMPONENT_TYPE);
-    rendererKitControl.setReturnValue(new StylesheetRenderer());
-   
-    
-    
-    mockFacesCtx.getResponseWriter();
-    ctxControl.setReturnValue(writer);
-    
-    mockFacesCtx.getRenderKit();
-    ctxControl.setReturnValue(rKit);
-
-
-    MockControl viewRootControl = MockClassControl.createControl(UIViewRoot.class);
-    UIViewRoot uiViewRoot = (UIViewRoot) viewRootControl.getMock();
-    uiViewRoot.getRenderKitId();
-    viewRootControl.setReturnValue(RenderKitFactory.HTML_BASIC_RENDER_KIT);
-    
-    mockFacesCtx.getViewRoot();//(uiViewRoot);
-    ctxControl.setReturnValue(uiViewRoot);
-    
-
-    ((RenderKitFactory)FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY)).addRenderKit(
-        RenderKitFactory.HTML_BASIC_RENDER_KIT, rKit);    
-    
-    ctxControl.replay();
-    extCtxControl.replay();
-    viewRootControl.replay();
-    rendererKitControl.replay();
-    
-    return mockFacesCtx;
-  }
-
-  protected void setUp() throws Exception {
-
-    this.context = getMockFacesContext(this.writer); 
-  }
-
-  protected void tearDown() throws Exception {
-  }
+import junit.framework.Test;
+import org.apache.shale.test.base.AbstractJsfTestCase;
+import org.apache.shale.test.mock.MockResponseWriter;
+
+public class StylesheetRendererTest extends AbstractJsfTestCase
+{
+
+    private MockResponseWriter writer ;
+    private Stylesheet stylesheet ;
+    
+    public StylesheetRendererTest(String name)
+    {
+        super(name);
+    }
+    
+    public void setUp()
+    {
+        super.setUp();
+        stylesheet = new Stylesheet();
+        stylesheet.setPath("test.css");
+        stylesheet.setMedia("printer");
+        writer = new MockResponseWriter(new StringWriter(), null, null);
+        facesContext.setResponseWriter(writer);
+        facesContext.getRenderKit().addRenderer(
+                stylesheet.getFamily(), 
+                stylesheet.getRendererType(), 
+                new StylesheetRenderer());
+    }
+
+    public void tearDown()
+    {
+        super.tearDown();
+        writer = null;
+        stylesheet = null;
+    }
+
+    public static Test suite()
+    {
+        return null; // keep this method or maven won't run it
+    }
+
+    /*
+     * Test method for 'org.apache.myfaces.custom.stylesheet.StylesheetRenderer.encodeEnd(FacesContext,
UIComponent)'
+     */
+    public void testInline() throws IOException
+    {
+
+        stylesheet.setInline(true);
+        stylesheet.encodeEnd(facesContext);
+        facesContext.renderResponse();
+
+        String output = writer.getWriter().toString();
+        
+        assertTrue("looking for a <style>", output.trim().startsWith("<style"));
+        
+    }
+
+    public void testLink() throws IOException
+    {
+
+        stylesheet.encodeEnd(facesContext);
+        facesContext.renderResponse();
+
+        String output = writer.getWriter().toString();
+        
+        assertTrue("looking for a <link>", output.trim().startsWith("<link"));
+    }
 
 }



Mime
View raw message