From c8e3f2eebbbf2532db84cd3737820b0f8a291e6e Mon Sep 17 00:00:00 2001 From: plough Date: Tue, 16 Apr 2019 14:14:22 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-14865=20=E6=9B=B4=E6=96=B0=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E6=8E=A8=E9=80=81=3D>=E8=B7=B3=E8=BF=87=E6=8E=A8?= =?UTF-8?q?=E9=80=81=E7=89=88=E6=9C=AC&=E4=BF=AE=E5=A4=8D=E5=8D=95?= =?UTF-8?q?=E5=85=83=E6=B5=8B=E8=AF=95=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../push/DesignerPushUpdateManager.java | 5 ++- .../push/DesignerPushUpdateManagerTest.java | 44 +++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/designer-base/src/main/java/com/fr/design/update/push/DesignerPushUpdateManager.java b/designer-base/src/main/java/com/fr/design/update/push/DesignerPushUpdateManager.java index 7b9dfa757..3620b2962 100644 --- a/designer-base/src/main/java/com/fr/design/update/push/DesignerPushUpdateManager.java +++ b/designer-base/src/main/java/com/fr/design/update/push/DesignerPushUpdateManager.java @@ -166,6 +166,9 @@ public class DesignerPushUpdateManager { * 跳过当前的推送版本 */ void skipCurrentPushVersion() { - // todo + if (updateInfo == null) { + return; + } + config.setLastIgnoredVersion(updateInfo.getPushVersion()); } } diff --git a/designer-base/src/test/java/com/fr/design/update/push/DesignerPushUpdateManagerTest.java b/designer-base/src/test/java/com/fr/design/update/push/DesignerPushUpdateManagerTest.java index 38491fbe2..333580f1a 100644 --- a/designer-base/src/test/java/com/fr/design/update/push/DesignerPushUpdateManagerTest.java +++ b/designer-base/src/test/java/com/fr/design/update/push/DesignerPushUpdateManagerTest.java @@ -1,7 +1,17 @@ package com.fr.design.update.push; +import com.fr.design.event.DesignerOpenedListener; +import com.fr.design.mainframe.DesignerContext; +import com.fr.design.mainframe.DesignerFrame; import com.fr.invoke.Reflect; +import com.fr.stable.StringUtils; +import org.easymock.EasyMock; +import org.junit.BeforeClass; 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 org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; @@ -9,7 +19,21 @@ import static org.junit.Assert.assertSame; /** * Created by plough on 2019/4/8. */ +@RunWith(value = PowerMockRunner.class) +@PrepareForTest(DesignerContext.class) public class DesignerPushUpdateManagerTest { + + @BeforeClass + public static void setUp() { + DesignerFrame mockFrame = EasyMock.mock(DesignerFrame.class); + mockFrame.addDesignerOpenedListener(EasyMock.anyObject(DesignerOpenedListener.class)); + EasyMock.replay(mockFrame); + + PowerMock.mockStatic(DesignerContext.class); + EasyMock.expect(DesignerContext.getDesignerFrame()).andReturn(mockFrame).anyTimes(); + PowerMock.replayAll(); + } + @Test public void testSingleton() { DesignerPushUpdateManager m1 = DesignerPushUpdateManager.getInstance(); @@ -29,4 +53,24 @@ public class DesignerPushUpdateManagerTest { assertEquals(false, Reflect.on(pushUpdateManager).call("isAutoPushUpdateSupported", false, false).get()); } + @Test + public void testSkipCurrentPushVersion() { + DesignerPushUpdateManager pushUpdateManager = DesignerPushUpdateManager.getInstance(); + + // 1. updateInfo 为 null 的情况 + pushUpdateManager.skipCurrentPushVersion(); + assertEquals(StringUtils.EMPTY, DesignerPushUpdateConfigManager.getInstance().getLastIgnoredVersion()); + + + // 2. updateInfo 有值的情况 + final String PUSH_VERSION = "stable-2019.02.03.12.44.22"; + DesignerUpdateInfo mockInfo = EasyMock.mock(DesignerUpdateInfo.class); + EasyMock.expect(mockInfo.getPushVersion()).andReturn(PUSH_VERSION).anyTimes(); + Reflect.on(pushUpdateManager).set("updateInfo", mockInfo); + EasyMock.replay(mockInfo); + + pushUpdateManager.skipCurrentPushVersion(); + assertEquals(PUSH_VERSION, DesignerPushUpdateConfigManager.getInstance().getLastIgnoredVersion()); + } + }