diff --git a/designer-base/src/main/java/com/fr/design/formula/FunctionConstants.java b/designer-base/src/main/java/com/fr/design/formula/FunctionConstants.java index 0166c269be..eee75a2220 100644 --- a/designer-base/src/main/java/com/fr/design/formula/FunctionConstants.java +++ b/designer-base/src/main/java/com/fr/design/formula/FunctionConstants.java @@ -102,11 +102,11 @@ public final class FunctionConstants { } private static boolean isCustomFormulaPath(String classFilePath) { - return !isJarPath(classFilePath) && isDebugMode(); + return !isJarPath(classFilePath) && isNotDebugMode(); } - private static boolean isDebugMode() { - return !GeneralUtils.readBuildNO().contains("-"); + private static boolean isNotDebugMode() { + return GeneralUtils.readBuildNO().contains("-"); } private static boolean isJarPath(String classFilePath) { diff --git a/designer-base/src/test/java/com/fr/design/formula/FunctionConstantsTest.java b/designer-base/src/test/java/com/fr/design/formula/FunctionConstantsTest.java index 33cfd577da..75c9c9e5ba 100644 --- a/designer-base/src/test/java/com/fr/design/formula/FunctionConstantsTest.java +++ b/designer-base/src/test/java/com/fr/design/formula/FunctionConstantsTest.java @@ -1,14 +1,24 @@ package com.fr.design.formula; +import com.fr.general.GeneralUtils; +import com.fr.invoke.Reflect; +import org.easymock.EasyMock; 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 static junit.framework.Assert.fail; import static junit.framework.TestCase.assertEquals; import static junit.framework.TestCase.assertTrue; +import static org.junit.Assert.assertFalse; /** * Created by plough on 2018/12/7. */ +@RunWith(PowerMockRunner.class) +@PrepareForTest(GeneralUtils.class) public class FunctionConstantsTest { @Test public void testNewInstanceFail() throws Exception { @@ -37,4 +47,30 @@ public class FunctionConstantsTest { NameAndFunctionList commonFunctionList = FunctionConstants.COMMON; assertEquals(9, commonFunctionList.getDescriptions().length); } + + @Test + public void testIsCustomFormulaPathRunWithCode() { + PowerMock.mockStatic(GeneralUtils.class); + EasyMock.expect(GeneralUtils.readBuildNO()).andReturn("不是安装版本").anyTimes(); + PowerMock.replayAll(); + + String classFilePath = "/Users/plough/.m2/repository/com/fr/core/fine-core/10.0-RELEASE-SNAPSHOT/fine-core-10.0-RELEASE-20181211.024527-499.jar!/com/fr/function"; + assertFalse(Reflect.on(FunctionConstants.class).call("isCustomFormulaPath", classFilePath).get()); + + classFilePath = "/Users/plough/work/new_10_release_finereport/engine-settings/env/webroot/WEB-INF/classes/com/fr/function"; + assertFalse(Reflect.on(FunctionConstants.class).call("isCustomFormulaPath", classFilePath).get()); + } + + @Test + public void testIsCustomFormulaPathRunWithJar() { + PowerMock.mockStatic(GeneralUtils.class); + EasyMock.expect(GeneralUtils.readBuildNO()).andReturn("Build#release-2018.12.10.12.11.09.95").anyTimes(); + PowerMock.replayAll(); + + String classFilePath = "file:/Applications/FineReport_10.0_12_10/webapps/webroot/WEB-INF/lib/fine-report-engine-10.0.jar!/com/fr/function"; + assertFalse(Reflect.on(FunctionConstants.class).call("isCustomFormulaPath", classFilePath).get()); + + classFilePath = "/Applications/FineReport_10.0_12_10/webapps/webroot/WEB-INF/classes/com/fr/function"; + assertTrue(Reflect.on(FunctionConstants.class).call("isCustomFormulaPath", classFilePath).get()); + } }