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()); + } + }