tapestry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From andy...@apache.org
Subject svn commit: r594630 - in /tapestry/tapestry4/trunk/tapestry-framework/src: java/org/apache/tapestry/javascript/JavascriptManagerImpl.java test/org/apache/tapestry/javascript/ test/org/apache/tapestry/javascript/TestJavascriptManagerImpl.java
Date Tue, 13 Nov 2007 20:22:54 GMT
Author: andyhot
Date: Tue Nov 13 12:22:54 2007
New Revision: 594630

URL: http://svn.apache.org/viewvc?rev=594630&view=rev
Log:
test for jsmanager

Added:
    tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/javascript/
    tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/javascript/TestJavascriptManagerImpl.java
Modified:
    tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/javascript/JavascriptManagerImpl.java

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/javascript/JavascriptManagerImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/javascript/JavascriptManagerImpl.java?rev=594630&r1=594629&r2=594630&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/javascript/JavascriptManagerImpl.java
(original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/javascript/JavascriptManagerImpl.java
Tue Nov 13 12:22:54 2007
@@ -14,9 +14,10 @@
 
 package org.apache.tapestry.javascript;
 
-import java.util.List;
 import java.util.ArrayList;
+import java.util.List;
 
+import org.apache.hivemind.HiveMind;
 import org.apache.hivemind.Location;
 import org.apache.hivemind.util.URLResource;
 import org.apache.tapestry.IAsset;
@@ -25,11 +26,20 @@
 import org.apache.tapestry.util.DescribedLocation;
 
 /**
+ * An implementation that accepts a comma separated String for
+ * files, formFiles and widgetFiles. 
+ *
  * @author Andreas Andreou
  * @since 4.1.4
  */
 public class JavascriptManagerImpl implements JavascriptManager {
 
+    public JavascriptManagerImpl() {
+        _files = new ArrayList();
+        _formFiles = new ArrayList();
+        _widgetFiles = new ArrayList();
+    }
+
     public IAsset getMainJsAsset()
     {
         return findFirst(_files);
@@ -122,7 +132,7 @@
     private IAsset findAsset(String path, String description)
     {
         IAsset asset = null;
-        if (path!=null)
+        if ( !HiveMind.isBlank(path) )
         {
             Location location = new DescribedLocation(new URLResource(path), description);
             asset = _assetSource.findAsset(null, path, null, location);
@@ -131,7 +141,7 @@
     }
 
     private IAsset findFirst(List list) {
-        if (list ==null || list.isEmpty())
+        if (list == null || list.isEmpty())
             return null;
         else
             return (IAsset) list.get(0);

Added: tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/javascript/TestJavascriptManagerImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/javascript/TestJavascriptManagerImpl.java?rev=594630&view=auto
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/javascript/TestJavascriptManagerImpl.java
(added)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/javascript/TestJavascriptManagerImpl.java
Tue Nov 13 12:22:54 2007
@@ -0,0 +1,94 @@
+package org.apache.tapestry.javascript;
+
+import java.util.Locale;
+
+import org.apache.tapestry.IAsset;
+import org.apache.tapestry.TestBase;
+import org.apache.tapestry.util.DescribedLocation;
+import org.apache.tapestry.asset.AssetSource;
+import org.apache.hivemind.Resource;
+import org.testng.annotations.Test;
+
+import static org.easymock.EasyMock.*;
+
+@Test
+public class TestJavascriptManagerImpl extends TestBase
+{
+    public void test_null_manager()
+    {
+        JavascriptManagerImpl impl = createImpl();
+        replay();
+
+        assertNullAndEmpty(impl);
+        
+        verify();
+    }
+
+    public void test_empty_manager()
+    {
+        JavascriptManagerImpl impl = createImpl("", "", "", "", "", "");
+        replay();
+
+        assertNullAndEmpty(impl);
+
+        verify();
+    }
+
+    public void test_several_files()
+    {
+        AssetSource source = newMock(AssetSource.class);
+        expectFile(source, "a.js");
+        expectFile(source, "b.js");
+        expectFile(source, "tap");
+
+        replay();
+
+        JavascriptManagerImpl impl = createImpl(source, "a.js, b.js", "", "", "", "tap",
"");
+        assertEquals(impl.getJsAssets().size(), 2);
+        assertNotNull(impl.getMainJsAsset());
+        assertNotNull(impl.getJsTapestryAsset());
+
+        verify();
+    }
+
+    private void expectFile(AssetSource source, String file) {
+        expect(source.findAsset((Resource) isNull(), eq(file),
+                (Locale) isNull(), isA(DescribedLocation.class)))
+                .andReturn(newMock(IAsset.class));
+    }
+
+    private void assertNullAndEmpty(JavascriptManagerImpl impl) {
+        assertNull(impl.getJsPath());
+        assertNull(impl.getJsTapestryAsset());
+        assertNull(impl.getJsTapestryPath());
+        assertNull(impl.getMainJsAsset());
+        assertNull(impl.getMainJsFormAsset());
+        assertNull(impl.getMainJsWidgetAsset());
+        assertTrue(impl.getJsAssets().isEmpty());
+        assertTrue(impl.getJsFormAssets().isEmpty());
+        assertTrue(impl.getJsWidgetAssets().isEmpty());
+    }
+
+    private JavascriptManagerImpl createImpl(String...params) {
+        return createImpl(newMock(AssetSource.class), params);
+    }
+
+    private JavascriptManagerImpl createImpl(AssetSource source, String... params) {
+        JavascriptManagerImpl impl = new JavascriptManagerImpl();
+        impl.setAssetSource(source);
+
+        if (params.length>0)
+            impl.setFiles(params[0]);
+        if (params.length>1)
+            impl.setFormFiles(params[1]);
+        if (params.length>2)
+            impl.setWidgetFiles(params[2]);
+        if (params.length>3)
+            impl.setPath(params[3]);
+        if (params.length>4)
+            impl.setTapestryFile(params[4]);
+        if (params.length>5)
+            impl.setTapestryPath(params[5]);
+        return impl;
+    }
+}



Mime
View raw message