You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2017/10/18 23:18:46 UTC
[sling-org-apache-sling-commons-contentdetection] 12/39: SLING-4757
- remove Easymock, caused trouble with jacoco plugin coverage merging
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-contentdetection.git
commit 269ffcb7b000a2d979cd852f5d4da1f3c6a4b00f
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Mon Jun 1 15:26:04 2015 +0000
SLING-4757 - remove Easymock, caused trouble with jacoco plugin coverage merging
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1682931 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 21 +--
.../ContentAwareMimeTypeServiceImplTest.java | 180 +++++++--------------
2 files changed, 60 insertions(+), 141 deletions(-)
diff --git a/pom.xml b/pom.xml
index ebb4d85..20801d3 100644
--- a/pom.xml
+++ b/pom.xml
@@ -24,7 +24,7 @@
<parent>
<groupId>org.apache.sling</groupId>
<artifactId>sling</artifactId>
- <version>22</version>
+ <version>23-SNAPSHOT</version>
</parent>
<artifactId>org.apache.sling.commons.contentdetection</artifactId>
@@ -84,22 +84,9 @@
<scope>provided</scope>
</dependency>
<dependency>
- <groupId>org.easymock</groupId>
- <artifactId>easymock</artifactId>
- <version>3.3.1</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.powermock</groupId>
- <artifactId>powermock-module-junit4</artifactId>
- <version>${powermock.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.powermock</groupId>
- <artifactId>powermock-api-easymock</artifactId>
- <version>${powermock.version}</version>
- <scope>test</scope>
+ <groupId>junit-addons</groupId>
+ <artifactId>junit-addons</artifactId>
+ <version>1.4</version>
</dependency>
<dependency>
<groupId>org.apache.sling</groupId>
diff --git a/src/test/java/org/apache/sling/commons/contentdetection/internal/ContentAwareMimeTypeServiceImplTest.java b/src/test/java/org/apache/sling/commons/contentdetection/internal/ContentAwareMimeTypeServiceImplTest.java
index 6a31bb1..b00194b 100644
--- a/src/test/java/org/apache/sling/commons/contentdetection/internal/ContentAwareMimeTypeServiceImplTest.java
+++ b/src/test/java/org/apache/sling/commons/contentdetection/internal/ContentAwareMimeTypeServiceImplTest.java
@@ -17,156 +17,88 @@
package org.apache.sling.commons.contentdetection.internal;
-import org.apache.sling.commons.mime.MimeTypeService;
-import org.apache.tika.detect.Detector;
-import org.apache.tika.io.TikaInputStream;
-import org.apache.tika.metadata.Metadata;
-import org.apache.tika.mime.MediaType;
-import org.easymock.EasyMock;
-import org.easymock.EasyMockSupport;
-import org.easymock.TestSubject;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.powermock.api.easymock.PowerMock;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
-
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
-@RunWith(PowerMockRunner.class)
-@PrepareForTest(TikaInputStream.class)
-public class ContentAwareMimeTypeServiceImplTest extends EasyMockSupport {
+import junitx.util.PrivateAccessor;
- private Detector mockDetector = EasyMock.createMock(Detector.class);
-
- private MimeTypeService mockMimeTypeService = EasyMock.createMock(MimeTypeService.class);
-
- @TestSubject
- private ContentAwareMimeTypeServiceImpl contentAwareMimeTypeService = new ContentAwareMimeTypeServiceImpl();
+import org.apache.sling.commons.mime.MimeTypeService;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
- @Before
- public void setUp() throws IOException {
- contentAwareMimeTypeService.detector = mockDetector;
- contentAwareMimeTypeService.mimeTypeService = mockMimeTypeService;
- }
+public class ContentAwareMimeTypeServiceImplTest {
- @Test
- public void testGetMimeType() throws IOException {
+ private ContentAwareMimeTypeServiceImpl contentAwareMimeTypeService = null;
+ private int counterA;
+ private int counterB;
- //Initializations
- String filename = "test.txt";
- Metadata metadata = new Metadata();
- metadata.set(Metadata.RESOURCE_NAME_KEY, filename);
- byte[] byteArray = new byte[]{};
- InputStream content = new ByteArrayInputStream(byteArray);
- TikaInputStream stream = TikaInputStream.get(content);
- PowerMock.mockStatic(TikaInputStream.class);
+ final MimeTypeService mimeTypeService = new MimeTypeService() {
- //Record Expectations
- EasyMock.expect(TikaInputStream.get(content)).andReturn(stream).once();
- EasyMock.expect(mockDetector.detect(stream, metadata)).andReturn(MediaType.TEXT_PLAIN).once();
+ @Override
+ public String getMimeType(String name) {
+ return "MT_" + name;
+ }
- //Getting ready for run
- PowerMock.replay(TikaInputStream.class);
- EasyMock.replay(mockDetector);
+ @Override
+ public String getExtension(String mimeType) {
+ return "EXT_" + mimeType;
+ }
- //The test run
- String mimeType = contentAwareMimeTypeService.getMimeType(filename, content);
+ @Override
+ public void registerMimeType(String mimeType, String... extensions) {
+ counterA++;
+ }
- //Verification of expectations
- Assert.assertEquals(MediaType.TEXT_PLAIN.toString(), mimeType);
- EasyMock.verify(mockDetector);
- PowerMock.verify(TikaInputStream.class);
+ @Override
+ public void registerMimeType(InputStream mimeTabStream) throws IOException {
+ counterB++;
+ }
+ };
+
+ @Before
+ public void setup() throws NoSuchFieldException {
+ contentAwareMimeTypeService = new ContentAwareMimeTypeServiceImpl();
+ PrivateAccessor.setField(contentAwareMimeTypeService, "mimeTypeService", mimeTypeService);
}
-
+
@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);
+ String mimeTypeName = "testName.txt";
+ final String mimeType = contentAwareMimeTypeService.getMimeType(mimeTypeName);
+ Assert.assertEquals("MT_testName.txt", mimeType);
}
-
+
@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);
+ public void testGetExtension() {
+ final String ext = contentAwareMimeTypeService.getExtension("foo");
+ Assert.assertEquals("EXT_foo", ext);
}
@Test
public void testGetMimeTypeWithNullContent() throws IOException {
- //Initializations
- String filename = "test.txt";
- InputStream content = null;
-
- //Record Expectations
- EasyMock.expect(mockMimeTypeService.getMimeType(filename)).andReturn(MediaType.TEXT_PLAIN.getType()).once();
-
- //Getting ready for run
- EasyMock.replay(mockMimeTypeService);
-
- //The test run
- String mimeType = contentAwareMimeTypeService.getMimeType(filename, content);
-
- //Verification of expectations
- Assert.assertEquals(MediaType.TEXT_PLAIN.getType(), mimeType);
- EasyMock.verify(mockMimeTypeService);
+ final String filename = "test.txt";
+ final String mimeType = contentAwareMimeTypeService.getMimeType(filename, null);
+ Assert.assertEquals("MT_test.txt", mimeType);
}
@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);
+ public void testRegisterMimeTypeIsDelegatedA() {
+ final int before = counterA;
+ contentAwareMimeTypeService.registerMimeType("foo", new String[] {});
+ Assert.assertEquals("Expecting 1 call to registerMimeType(A)", before + 1, counterA);
}
@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() {
+ public void testRegisterMimeTypeIsDelegatedB() throws IOException {
+ final int before = counterB;
+ final InputStream is = new ByteArrayInputStream("x".getBytes());
+ try {
+ contentAwareMimeTypeService.registerMimeType(is);
+ } finally {
+ is.close();
+ }
+ Assert.assertEquals("Expecting 1 call to registerMimeType(B)", before + 1, counterB);
}
}
\ No newline at end of file
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.