You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tika.apache.org by ta...@apache.org on 2022/05/13 11:54:45 UTC

[tika] 06/10: TIKA-3762 -- upgrade to junit5 in tika-xmp

This is an automated email from the ASF dual-hosted git repository.

tallison pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tika.git

commit 6bd1bd939d728337c00ddaf2466b11aa5dbe5de4
Author: tallison <ta...@apache.org>
AuthorDate: Fri May 13 05:46:47 2022 -0400

    TIKA-3762 -- upgrade to junit5 in tika-xmp
---
 tika-xmp/pom.xml                                   |  7 ---
 .../java/org/apache/tika/xmp/TikaToXMPTest.java    | 27 ++++++----
 .../java/org/apache/tika/xmp/XMPMetadataTest.java  | 61 ++++++++++++++--------
 3 files changed, 54 insertions(+), 41 deletions(-)

diff --git a/tika-xmp/pom.xml b/tika-xmp/pom.xml
index 35b7355ee..fdd785bc9 100644
--- a/tika-xmp/pom.xml
+++ b/tika-xmp/pom.xml
@@ -99,13 +99,6 @@
       <artifactId>xmpcore</artifactId>
       <version>${xmpcore.version}</version>
     </dependency>
-    <!-- after we migrate everything to junit5, we can get rid of this -->
-    <dependency>
-      <groupId>org.junit.vintage</groupId>
-      <artifactId>junit-vintage-engine</artifactId>
-      <version>${junit5.version}</version>
-      <scope>test</scope>
-    </dependency>
   </dependencies>
 
   <description>Converts Tika metadata to XMP</description>
diff --git a/tika-xmp/src/test/java/org/apache/tika/xmp/TikaToXMPTest.java b/tika-xmp/src/test/java/org/apache/tika/xmp/TikaToXMPTest.java
index 5fdb07c54..7f92db295 100644
--- a/tika-xmp/src/test/java/org/apache/tika/xmp/TikaToXMPTest.java
+++ b/tika-xmp/src/test/java/org/apache/tika/xmp/TikaToXMPTest.java
@@ -16,11 +16,12 @@
  */
 package org.apache.tika.xmp;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 
 import org.apache.tika.exception.TikaException;
 import org.apache.tika.metadata.Metadata;
@@ -29,8 +30,6 @@ import org.apache.tika.metadata.TikaCoreProperties;
 import org.apache.tika.xmp.convert.ITikaToXMPConverter;
 import org.apache.tika.xmp.convert.MSOfficeXMLConverter;
 import org.apache.tika.xmp.convert.TikaToXMP;
-import org.junit.Before;
-import org.junit.Test;
 
 import com.adobe.internal.xmp.XMPConst;
 import com.adobe.internal.xmp.XMPException;
@@ -38,6 +37,8 @@ import com.adobe.internal.xmp.XMPIterator;
 import com.adobe.internal.xmp.XMPMeta;
 import com.adobe.internal.xmp.XMPMetaFactory;
 import com.adobe.internal.xmp.properties.XMPProperty;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
 
 /**
  * Tests the Tika <code>Metadata</code> to XMP conversion functionatlity
@@ -49,7 +50,7 @@ public class TikaToXMPTest {
     private static final String GENERIC_MIMETYPE = "generic/mimetype";
 
     // --- Set up ---
-    @Before
+    @BeforeEach
     public void setup() {
         tikaMetadata = new Metadata();
     }
@@ -183,9 +184,11 @@ public class TikaToXMPTest {
         assertFalse( iter.hasNext() );
     }
 
-    @Test(expected = IllegalArgumentException.class)
+    @Test
     public void convert_nullInput_throw() throws TikaException {
+        assertThrows(IllegalArgumentException.class, () -> {
         TikaToXMP.convert( null );
+        });
     }
 
     @Test
@@ -216,8 +219,10 @@ public class TikaToXMPTest {
         assertNull( converter );
     }
 
-    @Test(expected = IllegalArgumentException.class)
+    @Test
     public void getConverter_nullInput_throw() throws TikaException {
-        TikaToXMP.getConverter( null );
+        assertThrows(IllegalArgumentException.class, () -> {
+            TikaToXMP.getConverter(null);
+        });
     }
 }
diff --git a/tika-xmp/src/test/java/org/apache/tika/xmp/XMPMetadataTest.java b/tika-xmp/src/test/java/org/apache/tika/xmp/XMPMetadataTest.java
index d377276fd..c2c0c1d31 100644
--- a/tika-xmp/src/test/java/org/apache/tika/xmp/XMPMetadataTest.java
+++ b/tika-xmp/src/test/java/org/apache/tika/xmp/XMPMetadataTest.java
@@ -16,6 +16,13 @@
  */
 package org.apache.tika.xmp;
 
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
 import java.util.Date;
 import java.util.Properties;
 
@@ -26,20 +33,14 @@ import org.apache.tika.metadata.Property;
 import org.apache.tika.metadata.PropertyTypeException;
 import org.apache.tika.metadata.TikaCoreProperties;
 import org.apache.tika.metadata.XMPRights;
-import org.junit.Before;
-import org.junit.Test;
 
 import com.adobe.internal.xmp.XMPConst;
 import com.adobe.internal.xmp.XMPException;
 import com.adobe.internal.xmp.XMPMeta;
 import com.adobe.internal.xmp.XMPUtils;
 import com.adobe.internal.xmp.properties.XMPProperty;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
 
 public class XMPMetadataTest {
     private Metadata tikaMetadata;
@@ -48,7 +49,7 @@ public class XMPMetadataTest {
     private static final String GENERIC_MIMETYPE = "generic/mimetype";
 
     // --- SETUP ---
-    @Before
+    @BeforeEach
     public void setUp() throws Exception {
         XMPMetadata.registerNamespace( DublinCore.NAMESPACE_URI_DC_TERMS,
                 DublinCore.PREFIX_DC_TERMS );
@@ -138,20 +139,26 @@ public class XMPMetadataTest {
         assertNull( xmpMeta.get( TikaCoreProperties.FORMAT ) );
     }
 
-    @Test(expected = PropertyTypeException.class)
+    @Test
     public void get_nullInput_throw() {
         String notInitialized = null;
-        xmpMeta.get( notInitialized );
+        assertThrows(PropertyTypeException.class, () -> {
+            xmpMeta.get(notInitialized);
+        });
     }
 
-    @Test(expected = PropertyTypeException.class)
+    @Test
     public void get_notQualifiedKey_throw() {
-        xmpMeta.get( "wrongKey" );
+        assertThrows(PropertyTypeException.class, () -> {
+            xmpMeta.get( "wrongKey" );
+        });
     }
 
-    @Test(expected = PropertyTypeException.class)
+    @Test
     public void get_unknownPrefixKey_throw() {
-        xmpMeta.get( "unknown:key" );
+        assertThrows(PropertyTypeException.class, () -> {
+            xmpMeta.get("unknown:key");
+        });
     }
 
     @Test
@@ -202,20 +209,26 @@ public class XMPMetadataTest {
         assertEquals( GENERIC_MIMETYPE, xmpMeta.get( TikaCoreProperties.FORMAT ) );
     }
 
-    @Test(expected = PropertyTypeException.class)
+    @Test
     public void set_nullInput_throw() {
         String notInitialized = null;
-        xmpMeta.set( notInitialized, "value" );
+        assertThrows(PropertyTypeException.class, () -> {
+            xmpMeta.set(notInitialized, "value");
+        });
     }
 
-    @Test(expected = PropertyTypeException.class)
+    @Test
     public void set_notQualifiedKey_throw() {
-        xmpMeta.set( "wrongKey", "value" );
+        assertThrows(PropertyTypeException.class, () -> {
+            xmpMeta.set("wrongKey", "value");
+        });
     }
 
-    @Test(expected = PropertyTypeException.class)
+    @Test
     public void set_unknownPrefixKey_throw() {
-        xmpMeta.set( "unknown:key", "value" );
+        assertThrows(PropertyTypeException.class, () -> {
+            xmpMeta.set("unknown:key", "value");
+        });
     }
 
     @Test
@@ -228,9 +241,11 @@ public class XMPMetadataTest {
         checkArrayValues( values, "keyword" );
     }
 
-    @Test(expected = PropertyTypeException.class)
+    @Test
     public void set_simplePropWithMultipleValues_throw() {
-        xmpMeta.set( TikaCoreProperties.FORMAT, new String[] { "value1", "value2" } );
+        assertThrows(PropertyTypeException.class, () -> {
+            xmpMeta.set(TikaCoreProperties.FORMAT, new String[]{"value1", "value2"});
+        });
     }
 
     @Test