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

ashishvijaywargiya pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 1a23ae7cd2 Framework junit test cases fix (#1309)
1a23ae7cd2 is described below

commit 1a23ae7cd297f568a7e3f52058751291bdf40c89
Author: Ashish Vijaywargiya <[email protected]>
AuthorDate: Mon Jun 1 18:21:19 2026 +0530

    Framework junit test cases fix (#1309)
    
    Framework junit test cases fix. Reported by @gtchaboussie.
    
    Improved: Migrate framework Groovy tests to JUnit 5
    
    The build environment uses Gradle's JUnit Platform which ignores legacy
    JUnit 3 and 4 tests. This commit fully migrates the remaining 7 Groovy
    test files in the framework folder to standard JUnit 5 conventions.
    
    - Replaced `org.junit.Test` and legacy `TestCase` with
    `org.junit.jupiter.api.Test`
    - Replaced `@Before` with `@BeforeEach` and updated assertion imports
    - Fixed Mockito static mocking for `UtilProperties` in
    `ModelServiceTest`
    - Ensured test names were isolated in `UtilCacheTest`
    
    UtilCacheTest.groovy and other tests from framework folder can be seen
    at the following locations
    
    
    
https://drive.google.com/file/d/1g35oet3P8ceY_TDUASv282r6w3ByE5wZ/view?usp=sharing
    
    
    
https://drive.google.com/file/d/1SYuQnX1oWHq9svCXDgxvTHNSUfFZlGH9/view?usp=sharing
    
    All checks passed successfully so now merging the changes.
---
 .../apache/ofbiz/base/util/FileUtilTests.groovy    |  2 +-
 .../apache/ofbiz/base/util/UtilCacheTest.groovy    | 20 ++++---
 .../util/collection/FlexibleMapAccessorTest.groovy | 11 ++--
 .../FlexibleStringExpanderBaseCodeTests.groovy     |  2 +-
 .../FlexibleStringExpanderParserTests.groovy       |  2 +-
 .../util/string/FlexibleStringExpanderTests.groovy |  5 +-
 .../apache/ofbiz/service/ModelServiceTest.groovy   | 61 ++++++++++++----------
 7 files changed, 56 insertions(+), 47 deletions(-)

diff --git 
a/framework/base/src/test/groovy/org/apache/ofbiz/base/util/FileUtilTests.groovy
 
b/framework/base/src/test/groovy/org/apache/ofbiz/base/util/FileUtilTests.groovy
index d497f3ae79..4fb20b064e 100644
--- 
a/framework/base/src/test/groovy/org/apache/ofbiz/base/util/FileUtilTests.groovy
+++ 
b/framework/base/src/test/groovy/org/apache/ofbiz/base/util/FileUtilTests.groovy
@@ -19,7 +19,7 @@
 package org.apache.ofbiz.base.util
 
 import org.apache.commons.io.FileUtils
-import org.junit.Test
+import org.junit.jupiter.api.Test
 
 class FileUtilTests {
 
diff --git 
a/framework/base/src/test/groovy/org/apache/ofbiz/base/util/UtilCacheTest.groovy
 
b/framework/base/src/test/groovy/org/apache/ofbiz/base/util/UtilCacheTest.groovy
index 1588fa0330..f33fec681d 100644
--- 
a/framework/base/src/test/groovy/org/apache/ofbiz/base/util/UtilCacheTest.groovy
+++ 
b/framework/base/src/test/groovy/org/apache/ofbiz/base/util/UtilCacheTest.groovy
@@ -22,16 +22,12 @@ import static 
org.apache.ofbiz.base.util.tool.UtilCacheTestTools.createListener
 
 import org.apache.ofbiz.base.util.cache.UtilCache
 import org.apache.ofbiz.base.util.tool.UtilCacheTestTools.Listener
-import org.apache.ofbiz.service.testtools.OFBizTestCase
-import org.junit.Test
+
+import org.junit.jupiter.api.Test
 import org.junit.jupiter.api.BeforeAll
 
 // codenarc-disable JUnitLostTest
-class UtilCacheTest extends OFBizTestCase {
-
-    UtilCacheTest(String name) {
-        super(name)
-    }
+class UtilCacheTest  {
 
     @BeforeAll
     static void clearCaches() { // codenarc-disable UnusedPrivateMethod
@@ -95,6 +91,7 @@ class UtilCacheTest extends OFBizTestCase {
     // codenarc-disable JUnitTestMethodWithoutAssert
     @Test
     void testCreateUtilCache() {
+        String name = 'testCreateUtilCache'
         doUtilCacheCreateTest(UtilCache.createUtilCache(), null, null, null, 
null)
         doUtilCacheCreateTest(UtilCache.createUtilCache(name), null, null, 
null, null)
         doUtilCacheCreateTest(UtilCache.createUtilCache(name, false), null, 
null, null, Boolean.FALSE)
@@ -112,6 +109,7 @@ class UtilCacheTest extends OFBizTestCase {
 
     @Test
     void testCacheGetterOnCreation() {
+        String name = 'testCacheGetterOnCreation'
         UtilCache myCache = UtilCache.createUtilCache(name, 5, 0, 0, false)
         assert UtilCache.getUtilCacheTableKeySet().contains(name)
         assert myCache == UtilCache.findCache(name)
@@ -121,6 +119,7 @@ class UtilCacheTest extends OFBizTestCase {
 
     @Test
     void testCacheCreateEntry() {
+        String name = 'testCacheCreateEntry'
         UtilCache myCache = UtilCache.createUtilCache(name, 5, 0, 0, false)
         Listener myCacheListener = createListener(myCache)
         Listener controlListener = new Listener()
@@ -136,6 +135,7 @@ class UtilCacheTest extends OFBizTestCase {
 
     @Test
     void testCacheCreateEntryWithNullKey() {
+        String name = 'testCacheCreateEntryWithNullKey'
         UtilCache myCache = UtilCache.createUtilCache(name, 5, 0, 0, false)
         Listener myCacheListener = createListener(myCache)
         Listener controlListener = new Listener()
@@ -150,6 +150,7 @@ class UtilCacheTest extends OFBizTestCase {
 
     @Test
     void testCacheUpdateEntry() {
+        String name = 'testCacheUpdateEntry'
         UtilCache myCache = UtilCache.createUtilCache(name, 5, 0, 0, false)
         Listener myCacheListener = createListener(myCache)
         Listener controlListener = new Listener()
@@ -171,6 +172,7 @@ class UtilCacheTest extends OFBizTestCase {
 
     @Test
     void testRemoveCacheEntry() {
+        String name = 'testRemoveCacheEntry'
         UtilCache myCache = UtilCache.createUtilCache(name, 5, 0, 0, false)
         Listener myCacheListener = createListener(myCache)
         Listener controlListener = new Listener()
@@ -191,6 +193,7 @@ class UtilCacheTest extends OFBizTestCase {
 
     @Test
     void testSetExpireCache() {
+        String name = 'testSetExpireCache'
         UtilCache myCache = UtilCache.createUtilCache(name, 5, 0, 0, false)
         Listener myCacheListener = createListener(myCache)
         Listener controlListener = new Listener()
@@ -210,6 +213,7 @@ class UtilCacheTest extends OFBizTestCase {
 
     @Test
     void testChangeMemorySize() {
+        String name = 'testChangeMemorySize'
         int size = 5
         UtilCache<String, Serializable> myCache = 
UtilCache.createUtilCache(name, size, size, 0, false)
         Map controlMap = [:]
@@ -232,6 +236,7 @@ class UtilCacheTest extends OFBizTestCase {
 
     @Test
     void testPutIfAbsent() {
+        String name = 'testPutIfAbsent'
         UtilCache<String, String> myCache = UtilCache.createUtilCache(name, 1, 
1, 0, false)
         Listener myCacheListener = createListener(myCache)
         Listener controlListener = new Listener()
@@ -252,6 +257,7 @@ class UtilCacheTest extends OFBizTestCase {
 
     @Test
     void testPutIfAbsentAndGet() {
+        String name = 'testPutIfAbsentAndGet'
         UtilCache<String, String> myCache = UtilCache.createUtilCache(name, 1, 
1, 0, false)
         Listener myCacheListener = createListener(myCache)
         Listener controlListener = new Listener()
diff --git 
a/framework/base/src/test/groovy/org/apache/ofbiz/base/util/collection/FlexibleMapAccessorTest.groovy
 
b/framework/base/src/test/groovy/org/apache/ofbiz/base/util/collection/FlexibleMapAccessorTest.groovy
index d60756c79a..c140382f1b 100644
--- 
a/framework/base/src/test/groovy/org/apache/ofbiz/base/util/collection/FlexibleMapAccessorTest.groovy
+++ 
b/framework/base/src/test/groovy/org/apache/ofbiz/base/util/collection/FlexibleMapAccessorTest.groovy
@@ -18,16 +18,15 @@
  
*******************************************************************************/
 package org.apache.ofbiz.base.util.collection
 
-import junit.framework.TestCase
+import org.junit.jupiter.api.Assertions
+import org.junit.jupiter.api.Test
 import org.apache.ofbiz.base.util.collections.FlexibleMapAccessor
 import org.apache.ofbiz.base.util.string.tool.TestException
 import org.apache.ofbiz.base.util.string.tool.TestingMap
-import org.junit.Assert
-import org.junit.Test
 
 /* codenarc-disable GStringExpressionWithinString, 
UnnecessaryBigDecimalInstantiation */
 
-class FlexibleMapAccessorTest extends TestCase {
+class FlexibleMapAccessorTest {
 
     private static final Locale LOCALE_TO_TEST = new Locale('en', 'US')
     private static final FlexibleMapAccessor<?> EMPTY_FMA = 
FlexibleMapAccessor.getInstance('')
@@ -107,7 +106,7 @@ class FlexibleMapAccessorTest extends TestCase {
         assert !outParameters.isEmpty()
         assert outParameters.keySet().contains('var')
         assert outParameters.('var') === null
-        Assert.assertThrows(IllegalArgumentException, () -> 
fmaVarInstance.put(null, 'Foo'))
+        Assertions.assertThrows(IllegalArgumentException, () -> 
fmaVarInstance.put(null, 'Foo'))
     }
 
     @Test
@@ -120,7 +119,7 @@ class FlexibleMapAccessorTest extends TestCase {
         assert !parameters.isEmpty()
         assert parameters.keySet().contains('someList')
         assert parameters.('someList') == []
-        Assert.assertThrows(IllegalArgumentException, () -> 
fmaVarInstance.put(null, 'Foo'))
+        Assertions.assertThrows(IllegalArgumentException, () -> 
fmaVarInstance.put(null, 'Foo'))
     }
 
     @Test
diff --git 
a/framework/base/src/test/groovy/org/apache/ofbiz/base/util/string/FlexibleStringExpanderBaseCodeTests.groovy
 
b/framework/base/src/test/groovy/org/apache/ofbiz/base/util/string/FlexibleStringExpanderBaseCodeTests.groovy
index bc79a3613b..a0e7536366 100644
--- 
a/framework/base/src/test/groovy/org/apache/ofbiz/base/util/string/FlexibleStringExpanderBaseCodeTests.groovy
+++ 
b/framework/base/src/test/groovy/org/apache/ofbiz/base/util/string/FlexibleStringExpanderBaseCodeTests.groovy
@@ -21,7 +21,7 @@ package org.apache.ofbiz.base.util.string
 import groovy.io.FileType
 import org.apache.ofbiz.base.util.Debug
 import org.apache.ofbiz.base.util.ScriptUtil
-import org.junit.Test
+import org.junit.jupiter.api.Test
 
 import java.util.regex.MatchResult
 import java.util.regex.Matcher
diff --git 
a/framework/base/src/test/groovy/org/apache/ofbiz/base/util/string/FlexibleStringExpanderParserTests.groovy
 
b/framework/base/src/test/groovy/org/apache/ofbiz/base/util/string/FlexibleStringExpanderParserTests.groovy
index e36ae9c613..eff11796d1 100644
--- 
a/framework/base/src/test/groovy/org/apache/ofbiz/base/util/string/FlexibleStringExpanderParserTests.groovy
+++ 
b/framework/base/src/test/groovy/org/apache/ofbiz/base/util/string/FlexibleStringExpanderParserTests.groovy
@@ -18,7 +18,7 @@
  
*******************************************************************************/
 package org.apache.ofbiz.base.util.string
 
-import org.junit.Test
+import org.junit.jupiter.api.Test
 
 /* codenarc-disable GStringExpressionWithinString, 
JUnitTestMethodWithoutAssert */
 
diff --git 
a/framework/base/src/test/groovy/org/apache/ofbiz/base/util/string/FlexibleStringExpanderTests.groovy
 
b/framework/base/src/test/groovy/org/apache/ofbiz/base/util/string/FlexibleStringExpanderTests.groovy
index 4dc83ad0a0..737e0b6891 100644
--- 
a/framework/base/src/test/groovy/org/apache/ofbiz/base/util/string/FlexibleStringExpanderTests.groovy
+++ 
b/framework/base/src/test/groovy/org/apache/ofbiz/base/util/string/FlexibleStringExpanderTests.groovy
@@ -18,18 +18,17 @@
  
*******************************************************************************/
 package org.apache.ofbiz.base.util.string
 
-import junit.framework.TestCase
 import org.apache.ofbiz.base.util.string.tool.SpecialNumber
 import org.apache.ofbiz.base.util.string.tool.TestNpe
 import org.apache.ofbiz.base.util.string.tool.TestException
-import org.junit.Test
+import org.junit.jupiter.api.Test
 
 /* codenarc-disable GStringExpressionWithinString, 
JUnitTestMethodWithoutAssert, UnnecessaryBigDecimalInstantiation */
 
 /**
  * Test Class for FlexibleStringExpander object
  */
-class FlexibleStringExpanderTests extends TestCase {
+class FlexibleStringExpanderTests {
 
     private static final Locale LOCALE_TO_TEST = new Locale('en', 'US')
     private static final Locale OTHER_LOCALE = new Locale('fr')
diff --git 
a/framework/service/src/test/groovy/org/apache/ofbiz/service/ModelServiceTest.groovy
 
b/framework/service/src/test/groovy/org/apache/ofbiz/service/ModelServiceTest.groovy
index 5b92084363..24696cd764 100644
--- 
a/framework/service/src/test/groovy/org/apache/ofbiz/service/ModelServiceTest.groovy
+++ 
b/framework/service/src/test/groovy/org/apache/ofbiz/service/ModelServiceTest.groovy
@@ -26,9 +26,8 @@ import org.apache.ofbiz.base.util.UtilURL
 import org.apache.ofbiz.base.util.UtilXml
 import org.apache.ofbiz.base.util.cache.UtilCache
 import org.apache.ofbiz.entity.DelegatorFactory
-import org.junit.Assert
-import org.junit.Before
-import org.junit.Test
+import org.junit.jupiter.api.Assertions
+import org.junit.jupiter.api.Test
 import org.junit.jupiter.api.AfterEach
 import org.junit.jupiter.api.BeforeEach
 import org.mockito.MockedStatic
@@ -43,7 +42,13 @@ class ModelServiceTest {
     private MockedStatic<UtilProperties> utilities
     private LocalDispatcher dispatcher
 
-    @Before
+    @org.junit.jupiter.api.BeforeAll
+    static void initClasses() {
+        // Initialize SecuredUpload before UtilProperties is mocked
+        new org.apache.ofbiz.security.SecuredUpload()
+    }
+
+    @BeforeEach
     void initialize() {
         System.setProperty('ofbiz.home', System.getProperty('user.dir'))
         dispatcher = Mockito.mock(LocalDispatcher)
@@ -52,9 +57,9 @@ class ModelServiceTest {
 
     @BeforeEach
     void initMock() {
-        utilities = Mockito.mockStatic(UtilProperties)
-        utilities.when(UtilProperties.getMessage(eq(ModelService.RESOURCE), 
any(), any())).thenReturn('Failed')
-        
utilities.when(UtilProperties.createProperties(eq('debug.properties'))).thenReturn(new
 Properties())
+        utilities = Mockito.mockStatic(UtilProperties, 
Mockito.CALLS_REAL_METHODS)
+        utilities.when { UtilProperties.getMessage(eq(ModelService.RESOURCE), 
any(), any()) }.thenReturn('Failed')
+        utilities.when { 
UtilProperties.createProperties(eq('debug.properties')) }.thenReturn(new 
Properties())
     }
 
     @AfterEach
@@ -74,7 +79,7 @@ class ModelServiceTest {
                     .validate(dispatcher, [message: 'ok'],
                             'IN', Locale.default)
         } catch (ServiceValidationException ignored) {
-            Assert.fail('Required parameters not validated')
+            Assertions.fail('Required parameters not validated')
         }
     }
 
@@ -89,7 +94,7 @@ class ModelServiceTest {
                     .validate(dispatcher, [message: 'ok'],
                             'IN', Locale.default)
         } catch (ServiceValidationException ignored) {
-            Assert.fail('Optional parameter not validated')
+            Assertions.fail('Optional parameter not validated')
         }
     }
 
@@ -105,13 +110,13 @@ class ModelServiceTest {
                     .validate(dispatcher, [message: 'ok'],
                             'IN', Locale.default)
         } catch (ServiceValidationException ignored) {
-            Assert.fail('Optional parameter not validated')
+            Assertions.fail('Optional parameter not validated')
         }
     }
 
     @Test
     void callValidateServiceWithNullRequiredParam() {
-        
org.junit.jupiter.api.Assertions.assertThrows(ServiceValidationException) {
+        Assertions.assertThrows(ServiceValidationException) {
             String serviceXml = '''<service name="testParam" engine="java"
                    location="org.apache.ofbiz.common.CommonServices" 
invoke="ping">
                    <attribute name="message" type="String" mode="IN"/>
@@ -133,13 +138,13 @@ class ModelServiceTest {
                     .validate(dispatcher, [message: null],
                             'IN', Locale.default)
         } catch (ServiceValidationException ignored) {
-            Assert.fail('Optional parameter not validated')
+            Assertions.fail('Optional parameter not validated')
         }
     }
 
     @Test
     void callValidateServiceWithOneSingleRequiredParamMissing() {
-        
org.junit.jupiter.api.Assertions.assertThrows(ServiceValidationException) {
+        Assertions.assertThrows(ServiceValidationException) {
             String serviceXml = '''<service name="testParam" engine="java"
                    location="org.apache.ofbiz.common.CommonServices" 
invoke="ping">
                    <attribute name="message" type="String" mode="IN"/>
@@ -163,13 +168,13 @@ class ModelServiceTest {
                     .validate(dispatcher, [header: [headerParam: 'foo']],
                             'IN', Locale.default)
         } catch (ServiceValidationException ignored) {
-            Assert.fail('Paramètre complexe non identifié')
+            Assertions.fail('Paramètre complexe non identifié')
         }
     }
 
     @Test
     void 
callValidateServiceWithOneComplexParameterAllRequiredEmbeddedMissing() {
-        
org.junit.jupiter.api.Assertions.assertThrows(ServiceValidationException) {
+        Assertions.assertThrows(ServiceValidationException) {
             String serviceXml = '''<service name="testParam" engine="java"
                    location="org.apache.ofbiz.common.CommonServices" 
invoke="ping">
                    <attribute name="header" type="java.util.Map" mode="IN" 
optional="false">
@@ -197,7 +202,7 @@ class ModelServiceTest {
                     .validate(dispatcher, [header: [headerParam: 'foo']],
                             'IN', Locale.default)
         } catch (ServiceValidationException ignored) {
-            Assert.fail('Missing optional should not throw exception')
+            Assertions.fail('Missing optional should not throw exception')
         }
     }
 
@@ -215,13 +220,13 @@ class ModelServiceTest {
                     .validate(dispatcher, [header: [headerParam: 'foo', 
otherParam: 'Good']],
                             'IN', Locale.default)
         } catch (ServiceValidationException ignored) {
-            Assert.fail('Complex parameter control error')
+            Assertions.fail('Complex parameter control error')
         }
     }
 
     @Test
     void 
callValidateServiceWithOneComplexParameterAndUnexpectedEmbeededParam() {
-        
org.junit.jupiter.api.Assertions.assertThrows(ServiceValidationException) {
+        Assertions.assertThrows(ServiceValidationException) {
             String serviceXml = '''<service name="testParam" engine="java"
                    location="org.apache.ofbiz.common.CommonServices" 
invoke="ping">
                    <attribute name="header" type="java.util.Map" mode="IN" 
optional="false">
@@ -237,7 +242,7 @@ class ModelServiceTest {
 
     @Test
     void callValidateServiceWithOneComplexParameterAndBadListValue() {
-        
org.junit.jupiter.api.Assertions.assertThrows(ServiceValidationException) {
+        Assertions.assertThrows(ServiceValidationException) {
             String serviceXml = '''<service name="testParam" engine="java"
                    location="org.apache.ofbiz.common.CommonServices" 
invoke="ping">
                    <attribute name="header" type="java.util.Map" mode="IN" 
optional="false">
@@ -268,13 +273,13 @@ class ModelServiceTest {
                                                     otherParam: 'true']],
                             'IN', Locale.default)
         } catch (ServiceValidationException ignored) {
-            Assert.fail('Paramètre complexe non identifié')
+            Assertions.fail('Paramètre complexe non identifié')
         }
     }
 
     @Test
     void callValidateServiceWithTwoComplexLevelParameterUnwantedParameter() {
-        
org.junit.jupiter.api.Assertions.assertThrows(ServiceValidationException) {
+        Assertions.assertThrows(ServiceValidationException) {
             String serviceXml = '''<service name="testParam" engine="java"
                    location="org.apache.ofbiz.common.CommonServices" 
invoke="ping">
                    <attribute name="header" type="java.util.Map" mode="IN" 
optional="false">
@@ -303,7 +308,7 @@ class ModelServiceTest {
                                                     otherParam: 'true']],
                             'IN', Locale.default)
         } catch (ServiceValidationException ignored) {
-            Assert.fail('Map should not have been analyzed')
+            Assertions.fail('Map should not have been analyzed')
         }
     }
 
@@ -322,13 +327,13 @@ class ModelServiceTest {
                                                     [headerParam: 'line2', 
otherParam: 'Good']]],
                             'IN', Locale.default)
         } catch (ServiceValidationException ignored) {
-            Assert.fail('Complex List Parameter Error')
+            Assertions.fail('Complex List Parameter Error')
         }
     }
 
     @Test
     void 
callValidateServiceWithOneComplexParameterAsListAndUnwantedParameter() {
-        
org.junit.jupiter.api.Assertions.assertThrows(ServiceValidationException) {
+        Assertions.assertThrows(ServiceValidationException) {
             String serviceXml = '''<service name="testParam" engine="java"
                    location="org.apache.ofbiz.common.CommonServices" 
invoke="ping">
                    <attribute name="header" type="java.util.List" mode="IN" 
optional="false">
@@ -369,7 +374,7 @@ class ModelServiceTest {
         try {
             modelService.validate(dispatcher, [header: [headerParam: 'line1', 
otherParam: 'Good']], 'IN', Locale.default)
         } catch (ServiceValidationException ignored) {
-            Assert.fail('Complex implement not valid')
+            Assertions.fail('Complex implement not valid')
         }
     }
 
@@ -384,7 +389,7 @@ class ModelServiceTest {
         try {
             sanitizedContext = DispatchContext.makeValidContext(fo, 'IN', 
[quantity: 20])
         } catch (GeneralServiceException ignored) {
-            Assert.fail('Error calling with integer for BigDecimal')
+            Assertions.fail('Error calling with integer for BigDecimal')
         }
         assert sanitizedContext.quantity instanceof BigDecimal
     }
@@ -402,7 +407,7 @@ class ModelServiceTest {
         try {
             sanitizedContext = DispatchContext.makeValidContext(fo, 'IN', 
[someMap: [quantity: 20]])
         } catch (GeneralServiceException ignored) {
-            Assert.fail('Error calling with integer for BigDecimal in Map')
+            Assertions.fail('Error calling with integer for BigDecimal in Map')
         }
         assert sanitizedContext.someMap.quantity instanceof BigDecimal
     }
@@ -420,7 +425,7 @@ class ModelServiceTest {
         try {
             sanitizedContext = DispatchContext.makeValidContext(fo, 'IN', 
[someList: [[quantity: 20]]])
         } catch (GeneralServiceException ignored) {
-            Assert.fail('Error calling with integer for BigDecimal in List')
+            Assertions.fail('Error calling with integer for BigDecimal in 
List')
         }
         assert sanitizedContext.someList[0].quantity instanceof BigDecimal
     }

Reply via email to