sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r1682844 - in /sling/trunk/bundles/commons/contentdetection/src/test/java/org/apache/sling/commons/contentdetection/internal: ContentAwareMimeTypeServiceImplTest.java FileNameExtractorImplTest.java
Date Mon, 01 Jun 2015 09:19:00 GMT
Author: bdelacretaz
Date: Mon Jun  1 09:18:59 2015
New Revision: 1682844

URL: http://svn.apache.org/r1682844
Log:
SLING-4757 - new tests for commons.contentdetection, contributed by Petr Shypila, thanks!

Modified:
    sling/trunk/bundles/commons/contentdetection/src/test/java/org/apache/sling/commons/contentdetection/internal/ContentAwareMimeTypeServiceImplTest.java
    sling/trunk/bundles/commons/contentdetection/src/test/java/org/apache/sling/commons/contentdetection/internal/FileNameExtractorImplTest.java

Modified: sling/trunk/bundles/commons/contentdetection/src/test/java/org/apache/sling/commons/contentdetection/internal/ContentAwareMimeTypeServiceImplTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/contentdetection/src/test/java/org/apache/sling/commons/contentdetection/internal/ContentAwareMimeTypeServiceImplTest.java?rev=1682844&r1=1682843&r2=1682844&view=diff
==============================================================================
--- sling/trunk/bundles/commons/contentdetection/src/test/java/org/apache/sling/commons/contentdetection/internal/ContentAwareMimeTypeServiceImplTest.java
(original)
+++ sling/trunk/bundles/commons/contentdetection/src/test/java/org/apache/sling/commons/contentdetection/internal/ContentAwareMimeTypeServiceImplTest.java
Mon Jun  1 09:18:59 2015
@@ -44,8 +44,6 @@ public class ContentAwareMimeTypeService
 
     private Detector mockDetector = EasyMock.createMock(Detector.class);
 
-    private Metadata mockMetadata = EasyMock.createMock(Metadata.class);
-
     private MimeTypeService mockMimeTypeService = EasyMock.createMock(MimeTypeService.class);
 
     @TestSubject
@@ -87,6 +85,32 @@ public class ContentAwareMimeTypeService
     }
 
     @Test
+    public void testGetMimeTypeByString(){
+        String mimeTypeName = "testName";
+        String mimetype = "mimeType";
+
+        EasyMock.expect(mockMimeTypeService.getMimeType(mimeTypeName)).andReturn(mimetype);
+        EasyMock.replay(mockMimeTypeService);
+
+        String another = contentAwareMimeTypeService.getMimeType(mimeTypeName);
+        Assert.assertEquals(mimetype, another);
+        EasyMock.verify(mockMimeTypeService);
+    }
+
+    @Test
+    public void testGetExtension(){
+        String mimeTypeName = "testName";
+        String extension = "java";
+
+        EasyMock.expect(mockMimeTypeService.getExtension(mimeTypeName)).andReturn(extension);
+        EasyMock.replay(mockMimeTypeService);
+
+        String another = contentAwareMimeTypeService.getExtension(mimeTypeName);
+        Assert.assertEquals(extension, another);
+        EasyMock.verify(mockMimeTypeService);
+    }
+
+    @Test
     public void testGetMimeTypeWithNullContent() throws IOException {
         //Initializations
         String filename = "test.txt";
@@ -106,7 +130,43 @@ public class ContentAwareMimeTypeService
         EasyMock.verify(mockMimeTypeService);
     }
 
+    @Test
+    public void testRegisterNewMymeType() {
+        final String mimeTypeName = "test";
+        final String[] mimeTypeExtensions = new String[]{"pict", "apt", "z"};
+
+        /* The only thing ContentAwareMimeTypeServiceImpl#registerMimeType(String name, String...
ext)
+         * method does is calls MimeTypeService registerMimeType(String name, String[] ext)
method.
+         * So we Mock it and expect that it will be called.
+         */
+        mockMimeTypeService.registerMimeType(mimeTypeName, mimeTypeExtensions);
+        EasyMock.expectLastCall();
+        EasyMock.replay(mockMimeTypeService);
+
+        contentAwareMimeTypeService.registerMimeType(mimeTypeName, mimeTypeExtensions);
+
+        EasyMock.verify(mockMimeTypeService);
+    }
+
+    @Test
+    public void testRegisterMimeType() throws IOException {
+        byte[] byteArray = new byte[]{};
+        InputStream content = new ByteArrayInputStream(byteArray);
+
+        /* The only thing ContentAwareMimeTypeServiceImpl#registerMimeType(InputStream i)
+         * method does is calls MimeTypeService#registerMimeType(InputStream i) method.
+         * So we Mock it and expect that it will be called.
+         */
+        mockMimeTypeService.registerMimeType(content);
+        EasyMock.expectLastCall();
+        EasyMock.replay(mockMimeTypeService);
+
+        contentAwareMimeTypeService.registerMimeType(content);
+
+        EasyMock.verify(mockMimeTypeService);
+    }
+
     @After
     public void tearDown() {
     }
-}
+}
\ No newline at end of file

Modified: sling/trunk/bundles/commons/contentdetection/src/test/java/org/apache/sling/commons/contentdetection/internal/FileNameExtractorImplTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/contentdetection/src/test/java/org/apache/sling/commons/contentdetection/internal/FileNameExtractorImplTest.java?rev=1682844&r1=1682843&r2=1682844&view=diff
==============================================================================
--- sling/trunk/bundles/commons/contentdetection/src/test/java/org/apache/sling/commons/contentdetection/internal/FileNameExtractorImplTest.java
(original)
+++ sling/trunk/bundles/commons/contentdetection/src/test/java/org/apache/sling/commons/contentdetection/internal/FileNameExtractorImplTest.java
Mon Jun  1 09:18:59 2015
@@ -17,17 +17,39 @@
 
 package org.apache.sling.commons.contentdetection.internal;
 
-import junit.framework.TestCase;
 import org.apache.sling.commons.contentdetection.FileNameExtractor;
 import org.junit.Assert;
+import org.junit.Test;
 
-public class FileNameExtractorImplTest extends TestCase {
+public class FileNameExtractorImplTest {
 
     FileNameExtractor fileNameExtractor = new FileNameExtractorImpl();
 
+    @Test
     public void testExtract() throws Exception {
         String rawPath = "http://midches.com/images/uploads/default/demo.jpg#anchor?query=test";
         String expectedFileName = "demo.jpg";
         Assert.assertEquals(expectedFileName, fileNameExtractor.extract(rawPath));
     }
+
+    @Test
+    public void testExtractForBackslash() throws Exception {
+        String rawPath = "C:\\Test windows%path\\demo.jpg";
+        String expectedFileName = "demo.jpg";
+        Assert.assertEquals(expectedFileName, fileNameExtractor.extract(rawPath));
+    }
+
+    @Test
+    public void testBackslashPath() throws Exception {
+        String rawPath = "C:\\Test windows%path\\demo.jpg";
+        String expectedFileName = "demo.jpg";
+        Assert.assertEquals(expectedFileName, fileNameExtractor.extract(rawPath));
+    }
+
+    @Test
+    public void testDecodedURL(){
+        String rawPath = "http://example.com/demo%20test.jpg?test=true";
+        String expectedFileName = "demo test.jpg";
+        Assert.assertEquals(expectedFileName, fileNameExtractor.extract(rawPath));
+    }
 }
\ No newline at end of file



Mime
View raw message