javaunohelper/JunitTest_juh.mk                                                 
      |    4 
 javaunohelper/test/com/sun/star/lib/uno/helper/InterfaceContainer_Test.java    
      |    1 
 
javaunohelper/test/com/sun/star/lib/uno/helper/MultiTypeInterfaceContainer_Test.java
 |  167 +++-------
 javaunohelper/test/com/sun/star/lib/uno/helper/WeakBase_Test.java              
      |  147 ++------
 4 files changed, 100 insertions(+), 219 deletions(-)

New commits:
commit f6001fb30c516ec6da39b0ca4058f8b28058df1f
Author: Robert Antoni Buj i Gelonch <robert....@gmail.com>
Date:   Wed Sep 24 13:57:50 2014 +0200

    javaunohelper: WeakBase_Test & MultiTypeInterfaceContainer_Test -> JUnit
    
    Integrate WeakBase_Test and MultiTypeInterfaceContainer_Test in juh tests.
    Remove unused import in InterfaceContainer_Test.
    Remove getImplementationId() test in WeakBase_Test. Deprecated as of
    the commit: 90b27c9493f4225e1612364b5813971b45b681a6
    
    $ make JunitTest_juh
    
    Change-Id: I1205c001e7f15bc5a28289051194fb225e114f13
    Reviewed-on: https://gerrit.libreoffice.org/11630
    Reviewed-by: David Ostrovsky <da...@ostrovsky.org>
    Tested-by: David Ostrovsky <da...@ostrovsky.org>

diff --git a/javaunohelper/JunitTest_juh.mk b/javaunohelper/JunitTest_juh.mk
index 3ba2f4e..0aaaa3a 100644
--- a/javaunohelper/JunitTest_juh.mk
+++ b/javaunohelper/JunitTest_juh.mk
@@ -35,13 +35,17 @@ $(eval $(call gb_JunitTest_add_sourcefiles,juh,\
     javaunohelper/test/com/sun/star/lib/uno/helper/AWeakBase \
     javaunohelper/test/com/sun/star/lib/uno/helper/ComponentBase_Test \
     javaunohelper/test/com/sun/star/lib/uno/helper/InterfaceContainer_Test \
+    
javaunohelper/test/com/sun/star/lib/uno/helper/MultiTypeInterfaceContainer_Test 
\
     javaunohelper/test/com/sun/star/lib/uno/helper/ProxyProvider \
+    javaunohelper/test/com/sun/star/lib/uno/helper/WeakBase_Test \
 ))
 
 $(eval $(call gb_JunitTest_add_classes,juh,\
     com.sun.star.comp.helper.ComponentContext_Test \
     com.sun.star.lib.uno.helper.ComponentBase_Test \
     com.sun.star.lib.uno.helper.InterfaceContainer_Test \
+    com.sun.star.lib.uno.helper.MultiTypeInterfaceContainer_Test \
+    com.sun.star.lib.uno.helper.WeakBase_Test \
 ))
 
 # vim:set noet sw=4 ts=4:
diff --git 
a/javaunohelper/test/com/sun/star/lib/uno/helper/InterfaceContainer_Test.java 
b/javaunohelper/test/com/sun/star/lib/uno/helper/InterfaceContainer_Test.java
index c98ceab..7459fae 100644
--- 
a/javaunohelper/test/com/sun/star/lib/uno/helper/InterfaceContainer_Test.java
+++ 
b/javaunohelper/test/com/sun/star/lib/uno/helper/InterfaceContainer_Test.java
@@ -40,7 +40,6 @@ import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 import org.junit.Before;
 import org.junit.Test;
-import org.junit.rules.ExpectedException;
 
 public class InterfaceContainer_Test
 {
diff --git 
a/javaunohelper/test/com/sun/star/lib/uno/helper/MultiTypeInterfaceContainer_Test.java
 
b/javaunohelper/test/com/sun/star/lib/uno/helper/MultiTypeInterfaceContainer_Test.java
index 6f805d5..c483a04 100644
--- 
a/javaunohelper/test/com/sun/star/lib/uno/helper/MultiTypeInterfaceContainer_Test.java
+++ 
b/javaunohelper/test/com/sun/star/lib/uno/helper/MultiTypeInterfaceContainer_Test.java
@@ -30,6 +30,12 @@ import java.util.List;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import org.junit.Before;
+import org.junit.Test;
+
 public class MultiTypeInterfaceContainer_Test
 {
     private static final Logger logger = 
Logger.getLogger(MultiTypeInterfaceContainer_Test.class.getName());
@@ -47,8 +53,8 @@ public class MultiTypeInterfaceContainer_Test
     //contains original object + proxies + null value
     List<Object> list3;
 
-    /** Creates a new instance of MultiTypeInterfaceContainer_Test */
-    public MultiTypeInterfaceContainer_Test()
+    /** Class variables are initialized before each Test method */
+    @Before public void setUp() throws Exception
     {
         obj1= new AWeakBase();
         obj2= new AWeakBase();
@@ -58,17 +64,25 @@ public class MultiTypeInterfaceContainer_Test
         proxyObj1Weak1= ProxyProvider.createProxy(obj1, XWeak.class);
         proxyObj3Weak1= ProxyProvider.createProxy(obj3, XWeak.class);
         proxyObj3Weak2= ProxyProvider.createProxy(obj3, XWeak.class);
+        assertNotNull(proxyObj1Weak1);
+        assertNotNull(proxyObj3Weak1);
+        assertNotNull(proxyObj3Weak2);
+
         proxyObj2TypeProv= ProxyProvider.createProxy(obj2, 
XTypeProvider.class);
         proxyObj3TypeProv= ProxyProvider.createProxy(obj3, 
XTypeProvider.class);
+        assertNotNull(proxyObj2TypeProv);
+        assertNotNull(proxyObj3TypeProv);
 
         list1= new ArrayList<Object>();
         list1.add(obj1);
         list1.add(obj2);
         list1.add(obj3);
+
         list2= new ArrayList<Object>();
         list2.add(obj1);
         list2.add(proxyObj2TypeProv);
         list2.add(proxyObj3TypeProv);
+
         list3= new ArrayList<Object>();
         list3.add(obj1);
         list3.add(null);
@@ -76,25 +90,26 @@ public class MultiTypeInterfaceContainer_Test
         list3.add(proxyObj3Weak1);
     }
 
-    public boolean addInterface()
+    @Test public void addInterface() throws Exception
     {
         logger.log(Level.INFO, "Testing 
MultiTypeInterfaceContainer.addInterface");
         MultiTypeInterfaceContainer cont= new MultiTypeInterfaceContainer();
-        boolean r[]= new boolean[200];
-        int i= 0;
 
         int ci= 0;
         ci= cont.addInterface(new Type(XInterface.class), obj1);
         ci= cont.addInterface(new Type(XInterface.class), obj2);
         ci= cont.addInterface(new Type(XInterface.class), obj3);
-        r[i++]= ci == 3;
+        assertEquals(ci, 3);
+
         ci= cont.addInterface(new Type(XWeak.class), obj1);
         ci= cont.addInterface(new Type(XWeak.class), obj2);
-        r[i++]= ci ==2;
+        assertEquals(ci, 2);
+
         ci= cont.addInterface(null,obj1);
-        r[i++]= ci == 1;
+        assertEquals(ci, 1);
+
         ci= cont.addInterface(new Type(XTypeProvider.class), null);
-        r[i++]= ci == 0;
+        assertEquals(ci, 0);
 
         cont= new MultiTypeInterfaceContainer();
         AWeakBase[] arObj= new AWeakBase[100];
@@ -107,22 +122,14 @@ public class MultiTypeInterfaceContainer_Test
         for (int c=0; c < 100; c++)
         {
             ci= cont.removeInterface(new Type(XInterface.class), arObj[c]);
-            r[i++]= ci == 100 -c -1;
-
+            assertEquals(ci, 100 -c -1);
         }
-        boolean bOk= true;
-        for (int c= 0; c < i; c++)
-            bOk= bOk && r[c];
-        logger.log(Level.INFO, bOk ? "Ok" : "Failed");
-        return bOk;
     }
 
-    public boolean getContainedTypes()
+    @Test public void getContainedTypes() throws Exception
     {
         logger.log(Level.INFO, "Testing 
MultiTypeInterfaceContainer.getContainedTypes");
         MultiTypeInterfaceContainer cont= new MultiTypeInterfaceContainer();
-        boolean r[]= new boolean[50];
-        int i= 0;
 
         cont.addInterface(new Type(XInterface.class), obj1);
         cont.addInterface(new Type(XWeak.class), obj1);
@@ -133,39 +140,32 @@ public class MultiTypeInterfaceContainer_Test
         cont.addInterface(XSingleComponentFactory.class, obj1);
         Type[] types= cont.getContainedTypes();
         // 3 types and no XTypeProvider
-        r[i++]= types.length == 5;
+        assertEquals(types.length, 5);
         for (int c= 0; c < types.length; c++)
         {
+            boolean result= false;
             if (types[c] == null)
-                r[i++]= true;
-            else if(types[c].equals( new Type(XTypeProvider.class)))
-                r[i++]= false;
-            else if(types[c].equals(new Type(XInterface.class)))
-                r[i++]= true;
+                result= true;
+            else if (types[c].equals(new Type(XTypeProvider.class)))
+                result= false;
+            else if (types[c].equals(new Type(XInterface.class)))
+                result= true;
             else if (types[c].equals(new Type(XWeak.class)))
-                r[i++]= true;
+                result= true;
             else if (types[c].equals(new Type()))
-                r[i++]= true;
+                result= true;
             else if (types[c].equals(new Type( aObj.getClass())))
-                r[i++]= true;
+                result= true;
             else if (types[c].equals(new Type(XSingleComponentFactory.class)))
-                r[i++]= true;
-            else
-                r[i++]= false;
+                result= true;
+            assertTrue(result);
         }
-        boolean bOk= true;
-        for (int c= 0; c < i; c++)
-            bOk= bOk && r[c];
-        logger.log(Level.INFO, bOk ? "Ok" : "Failed");
-        return bOk;
     }
 
-    public boolean getContainer()
+    @Test public void getContainer() throws Exception
     {
         logger.log(Level.INFO, "Testing 
MultiTypeInterfaceContainer.getContainedTypes");
         MultiTypeInterfaceContainer cont= new MultiTypeInterfaceContainer();
-        boolean r[]= new boolean[50];
-        int i= 0;
 
         cont.addInterface(new Type(XInterface.class), obj1);
         cont.addInterface(new Type(XInterface.class), obj2);
@@ -177,61 +177,45 @@ public class MultiTypeInterfaceContainer_Test
 
         InterfaceContainer icont= null;
         icont= cont.getContainer( new Type(XTypeProvider.class));
-        r[i++]= icont.size() == 0;
+        assertEquals(icont.size(), 0);
         icont= cont.getContainer(new Type(XWeak.class));
-        r[i++]= icont.size() == 2;
+        assertEquals(icont.size(), 2);
         icont= cont.getContainer(null);
-        r[i++]= icont.size() == 1;
-
-        boolean bOk= true;
-        for (int c= 0; c < i; c++)
-            bOk= bOk && r[c];
-        logger.log(Level.INFO, bOk ? "Ok" : "Failed");
-        return bOk;
+        assertEquals(icont.size(), 1);
     }
 
-    public boolean removeInterface()
+    @Test public void removeInterface() throws Exception
     {
         logger.log(Level.INFO, "Testing 
MultiTypeInterfaceContainer.removeInterface");
         MultiTypeInterfaceContainer cont= new MultiTypeInterfaceContainer();
-        boolean r[]= new boolean[50];
-        int i= 0;
 
         int count= 0;
         count= cont.removeInterface( new Type(XTypeProvider.class), obj1);
-        r[i++]= count == 0;
+        assertEquals(count, 0);
         count= cont.removeInterface( new Type(XTypeProvider.class), null);
-        r[i++]= count == 0;
+        assertEquals(count, 0);
         count= cont.removeInterface(null, obj2);
-        r[i++]= count == 0;
+        assertEquals(count, 0);
 
         cont.addInterface(new Type(XInterface.class), obj1);
         cont.addInterface(null, obj1);
         count= cont.removeInterface(null, obj2);
         // count must still be 1
-        r[i++]= count == 1;
+        assertEquals(count, 1);
         count= cont.removeInterface(null, obj1);
-        r[i++]= count == 0;
+        assertEquals(count, 0);
         count= cont.removeInterface(new Type(XInterface.class), obj1);
-        r[i++]= count == 0;
-
-          boolean bOk= true;
-        for (int c= 0; c < i; c++)
-            bOk= bOk && r[c];
-        logger.log(Level.INFO, bOk ? "Ok" : "Failed");
-        return bOk;
+        assertEquals(count, 0);
     }
 
-    public boolean clear()
+    @Test public void clear() throws Exception
     {
         logger.log(Level.INFO, "Testing MultiTypeInterfaceContainer.clear");
         MultiTypeInterfaceContainer cont= new MultiTypeInterfaceContainer();
-        boolean r[]= new boolean[50];
-        int i= 0;
 
         cont.clear();
         Type[] types= cont.getContainedTypes();
-        r[i++]= types.length == 0;
+        assertEquals(types.length, 0);
         cont.addInterface(new Type(XInterface.class), obj1);
         cont.addInterface(new Type(XInterface.class), obj2);
         cont.addInterface(new Type(XInterface.class), obj3);
@@ -240,24 +224,17 @@ public class MultiTypeInterfaceContainer_Test
         cont.addInterface(null, obj1);
         cont.addInterface(new Type(XTypeProvider.class), null);
         types= cont.getContainedTypes();
-        r[i++]= types.length == 3;
+        assertEquals(types.length, 3);
         cont.clear();
         types= cont.getContainedTypes();
-        r[i++]= types.length == 0;
-
-        boolean bOk= true;
-        for (int c= 0; c < i; c++)
-            bOk= bOk && r[c];
-        logger.log(Level.INFO, bOk ? "Ok" : "Failed");
-        return bOk;
+        assertEquals(types.length, 0);
     }
 
-    public boolean disposeAndClear()
+    @Test public void disposeAndClear() throws Exception
     {
         logger.log(Level.INFO, "Testing 
MultiTypeInterfaceContainer.disposeAndClear");
         MultiTypeInterfaceContainer cont= new MultiTypeInterfaceContainer();
-        boolean r[]= new boolean[50];
-        int i= 0;
+
         obj1.nDisposingCalled= 0;
         obj2.nDisposingCalled= 0;
         obj3.nDisposingCalled= 0;
@@ -270,36 +247,10 @@ public class MultiTypeInterfaceContainer_Test
         cont.addInterface(new Type(XTypeProvider.class), obj1);
         cont.disposeAndClear(new com.sun.star.lang.EventObject("blabla"));
 
-        r[i++]= obj1.nDisposingCalled == 3;
-        r[i++]= obj2.nDisposingCalled == 2;
-        r[i++]= obj3.nDisposingCalled == 1;
+        assertEquals(obj1.nDisposingCalled, 3);
+        assertEquals(obj2.nDisposingCalled, 2);
+        assertEquals(obj3.nDisposingCalled, 1);
         Type[] types= cont.getContainedTypes();
-        r[i++]= types.length == 0;
-
-        boolean bOk= true;
-        for (int c= 0; c < i; c++)
-            bOk= bOk && r[c];
-        logger.log(Level.INFO, bOk ? "Ok" : "Failed");
-        return bOk;
-    }
-
-
-    public static void main(String[] args)
-    {
-        MultiTypeInterfaceContainer_Test test= new 
MultiTypeInterfaceContainer_Test();
-        boolean r[]= new boolean[50];
-        int i= 0;
-        r[i++]= test.addInterface();
-        r[i++]= test.getContainedTypes();
-        r[i++]= test.getContainer();
-        r[i++]= test.removeInterface();
-        r[i++]= test.clear();
-        r[i++]= test.disposeAndClear();
-        boolean bOk= true;
-        for (int c= 0; c < i; c++)
-            bOk= bOk && r[c];
-        logger.log(Level.INFO, "Test finished.");
-        logger.log(Level.INFO, bOk ? "No errors." : "Errors occurred!!!");
-        System.exit( bOk ? 0: -1 );
+        assertEquals(types.length, 0);
     }
 }
\ No newline at end of file
diff --git a/javaunohelper/test/com/sun/star/lib/uno/helper/WeakBase_Test.java 
b/javaunohelper/test/com/sun/star/lib/uno/helper/WeakBase_Test.java
index db86e57..ef9fdbf 100644
--- a/javaunohelper/test/com/sun/star/lib/uno/helper/WeakBase_Test.java
+++ b/javaunohelper/test/com/sun/star/lib/uno/helper/WeakBase_Test.java
@@ -18,120 +18,78 @@
 
 package com.sun.star.lib.uno.helper;
 
-import com.sun.star.uno.Type;
 import com.sun.star.bridge.XBridgeSupplier2;
-import com.sun.star.uno.XReference;
-import com.sun.star.uno.XWeak;
 import com.sun.star.lang.XTypeProvider;
 import com.sun.star.uno.XAdapter;
+import com.sun.star.uno.Type;
+import com.sun.star.uno.XReference;
+import com.sun.star.uno.XWeak;
 
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+import org.junit.Test;
+
 public class WeakBase_Test
 {
 
     private static final Logger logger = 
Logger.getLogger(WeakBase_Test.class.getName());
 
-    public boolean getTypes()
+    @Test public void getTypes() throws Exception
     {
         logger.log(Level.INFO, "Testing WeakBase.getTypes");
-        boolean[] r= new boolean[50];
-        int i= 0;
-
         SomeClass comp= new SomeClass();
+
         Type[] types= comp.getTypes(); 
//XWeak,XTypeProvider,XReference,XBridgeSupplier2
-        r[i++]= types.length == 4;
+        assertEquals(types.length, 4);
         for (int c= 0; c < types.length; c++)
         {
+            boolean result= false;
             if (types[c].equals( new Type( XWeak.class)))
-                r[i++]= true;
+                result= true;
             else if (types[c].equals(new Type(XTypeProvider.class)))
-                r[i++]= true;
+                result= true;
             else if (types[c].equals(new Type(XReference.class)))
-                r[i++]= true;
+                result= true;
             else if (types[c].equals(new Type(XBridgeSupplier2.class)))
-                r[i++]= true;
-            else
-                r[i++]= false;
-
+                result= true;
+            assertTrue(result);
         }
 
         Foo1 f1= new Foo1();
         Foo1 f2= new Foo1();
         Type[] t1= f1.getTypes();
         Type[] t2= f2.getTypes();
-        r[i++]= t1.equals(t2);
-        Foo2 f3= new Foo2();
-        boolean bOk= true;
-        for (int c= 0; c < i; c++)
-            bOk= bOk && r[c];
-        logger.log(Level.INFO, bOk ? "Ok" : "Failed");
-        return bOk;
-    }
-
-    public boolean getImplementationId()
-    {
-        logger.log(Level.INFO, "Testing WeakBase.getImplementationId");
-        boolean[] r= new boolean[50];
-        int i= 0;
-
-        SomeClass comp= new SomeClass();
-        // byte 0 - 3 contain hashcode and the remaining bytes represent the 
classname
-        byte [] ar= comp.getImplementationId();
-
-        StringBuffer buff= new StringBuffer();
-        for (int c= 0; c < ar.length - 4; c++){
-            buff.append((char) ar[4 + c]);
-        }
-        String retStr= buff.toString();
-        r[i++]= retStr.equals("com.sun.star.lib.uno.helper.SomeClass");
-
-        Foo1 f1= new Foo1();
-        Foo1 f2= new Foo1();
-        r[i++]= f1.getImplementationId().equals(f2.getImplementationId());
+        assertArrayEquals(t1, t2);
         Foo2 f3= new Foo2();
-        r[i++]= ! f1.getImplementationId().equals(f3.getImplementationId());
-        Foo3 f4= new Foo3();
-        r[i++]= ! f1.getImplementationId().equals(f4.getImplementationId());
-        boolean bOk= true;
-        for (int c= 0; c < i; c++)
-            bOk= bOk && r[c];
-        logger.log(Level.INFO, bOk ? "Ok" : "Failed");
-        return bOk;
     }
 
-    public boolean queryAdapter()
+    @Test public void queryAdapter() throws Exception
     {
         logger.log(Level.INFO, "Testing WeakBase.queryAdapter, XAdapter 
tests");
-        boolean[] r= new boolean[50];
-        int i= 0;
-
         SomeClass comp= new SomeClass();
+
         XAdapter adapter= comp.queryAdapter();
         MyRef aRef1= new MyRef();
         MyRef aRef2= new MyRef();
         adapter.addReference(aRef1);
         adapter.addReference(aRef2);
 
-        r[i++]= adapter.queryAdapted() == comp;
+        assertSame(adapter.queryAdapted(), comp);
         comp= null;
-        logger.log(Level.FINE, "Wait 5 sec");
-        for(int c= 0; c < 50; c++)
-        {
-            try
-            {
-                Thread.sleep(100);
-                System.gc();
-                System.runFinalization();
-            }catch (InterruptedException ie)
-            {
-            }
-        }
-
-        r[i++]= aRef1.nDisposeCalled == 1;
-        r[i++]= aRef2.nDisposeCalled == 1;
-        r[i++]= adapter.queryAdapted() == null;
+        logger.log(Level.FINE, "Wait 51ms (-XX:MaxGCPauseMillis=50)");
+        System.gc();
+        System.runFinalization();
+        Thread.sleep(51);
+
+        assertEquals(aRef1.nDisposeCalled, 1);
+        assertEquals(aRef2.nDisposeCalled, 1);
+        assertNull(adapter.queryAdapted());
         adapter.removeReference(aRef1); // should not do any harm
         adapter.removeReference(aRef2);
 
@@ -144,45 +102,14 @@ public class WeakBase_Test
         adapter.addReference(aRef2);
 
         adapter.removeReference(aRef1);
-        logger.log(Level.FINE, "Wait 5 sec");
+        logger.log(Level.FINE, "Wait 51ms (-XX:MaxGCPauseMillis=50)");
         comp= null;
-        for(int c= 0; c < 50; c++)
-        {
-            try
-            {
-                Thread.sleep(100);
-                System.gc();
-                System.runFinalization();
-            }catch (InterruptedException ie)
-            {
-            }
-        }
-        r[i++]= aRef1.nDisposeCalled == 0;
-        r[i++]= aRef2.nDisposeCalled == 1;
-
-        boolean bOk= true;
-        for (int c= 0; c < i; c++)
-            bOk= bOk && r[c];
-        logger.log(Level.INFO, bOk ? "Ok" : "Failed");
-        return bOk;
+        System.gc();
+        System.runFinalization();
+        Thread.sleep(51);
+        assertEquals(aRef1.nDisposeCalled, 0);
+        assertEquals(aRef2.nDisposeCalled, 1);
     }
-
-    public static void main(String[] args)
-    {
-        WeakBase_Test test= new WeakBase_Test();
-        boolean r[]= new boolean[50];
-        int i= 0;
-        r[i++]= test.getTypes();
-        r[i++]= test.getImplementationId();
-        r[i++]= test.queryAdapter();
-
-        boolean bOk= true;
-        for (int c= 0; c < i; c++)
-            bOk= bOk && r[c];
-        logger.log(Level.INFO, bOk ? "No errors." : "Errors occurred!");
-        System.exit( bOk ? 0: -1 );
-    }
-
 }
 
 interface Aint
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to