From 5290d345e872791fbc1c2d0224c172da24d1599b Mon Sep 17 00:00:00 2001 From: Harrison Date: Wed, 15 Apr 2020 09:18:07 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-29722=E3=80=90=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E5=A4=8D=E7=94=A8=E6=8F=92=E4=BB=B6=E3=80=91@harrison,?= =?UTF-8?q?=E7=A4=BE=E5=8C=BA=E7=9A=84=E5=B0=8F=E7=BA=A2=E7=82=B9=EF=BC=8C?= =?UTF-8?q?=E4=B8=8D=E8=A3=85=E6=8F=92=E4=BB=B6=E4=B9=9F=E6=9C=89=EF=BC=8C?= =?UTF-8?q?=E9=9C=80=E8=A6=81=E5=A4=84=E7=90=86=20=E5=8C=85=E6=8B=AC?= =?UTF-8?q?=E6=8F=92=E5=85=A5=E4=B9=9F=E8=A6=81=E5=A4=84=E7=90=86=E4=B8=80?= =?UTF-8?q?=E4=B8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/fr/design/menu/MenuDef.java | 6 ++- .../com/fr/design/menu/SnapChatMenuDef.java | 41 ++++++++++++------- .../fr/design/menu/SnapChatMenuDefTest.java | 30 ++++++++++++++ 3 files changed, 62 insertions(+), 15 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/menu/MenuDef.java b/designer-base/src/main/java/com/fr/design/menu/MenuDef.java index f495e03f13..10f9944947 100644 --- a/designer-base/src/main/java/com/fr/design/menu/MenuDef.java +++ b/designer-base/src/main/java/com/fr/design/menu/MenuDef.java @@ -138,9 +138,13 @@ public class MenuDef extends ShortCut { */ public void addShortCut(ShortCut... shortcut) { for (ShortCut i : shortcut) { - this.shortcutList.add(i); + addShortCut(i); } } + + public void addShortCut(ShortCut shortCut) { + this.shortcutList.add(shortCut); + } public void removeShortCut(ShortCut shortCut) { diff --git a/designer-base/src/main/java/com/fr/design/menu/SnapChatMenuDef.java b/designer-base/src/main/java/com/fr/design/menu/SnapChatMenuDef.java index defbf0dbbf..2ec3f6c7ee 100644 --- a/designer-base/src/main/java/com/fr/design/menu/SnapChatMenuDef.java +++ b/designer-base/src/main/java/com/fr/design/menu/SnapChatMenuDef.java @@ -61,23 +61,20 @@ public class SnapChatMenuDef extends MenuDef implements SnapChat { } @Override - public void addShortCut(ShortCut... shortCuts) { + public void addShortCut(ShortCut shortCut) { - if (shortCuts == null) { - return; - } - for (ShortCut shortCut : shortCuts) { - if (shortCut instanceof SnapChatUpdateAction) { - SnapChatUpdateAction action = (SnapChatUpdateAction) shortCut; - if (!action.hasRead()) { - String calcKey = calcKey(); - SnapChatConfig.getInstance().resetRead(calcKey); - } - } - } - super.addShortCut(shortCuts); + addSnapChatNotification(shortCut); + super.addShortCut(shortCut); } + @Override + public void insertShortCut(int index, ShortCut shortCut) { + + addSnapChatNotification(shortCut); + super.insertShortCut(index, shortCut); + } + + @Override public SnapChatKey key() { @@ -90,6 +87,22 @@ public class SnapChatMenuDef extends MenuDef implements SnapChat { return new SnapChatMenuListener(); } + /** + * 添加提醒 + * + * @param shortCut 快捷方式 + */ + private void addSnapChatNotification(ShortCut shortCut) { + + if (shortCut instanceof SnapChatUpdateAction) { + SnapChatUpdateAction action = (SnapChatUpdateAction) shortCut; + if (!action.hasRead()) { + String calcKey = calcKey(); + SnapChatConfig.getInstance().resetRead(calcKey); + } + } + } + private String calcKey() { return key().calc(); diff --git a/designer-base/src/test/java/com/fr/design/menu/SnapChatMenuDefTest.java b/designer-base/src/test/java/com/fr/design/menu/SnapChatMenuDefTest.java index 25671596c6..298f51a4cc 100644 --- a/designer-base/src/test/java/com/fr/design/menu/SnapChatMenuDefTest.java +++ b/designer-base/src/test/java/com/fr/design/menu/SnapChatMenuDefTest.java @@ -73,4 +73,34 @@ public class SnapChatMenuDefTest { menuDef.addShortCut(action); Assert.assertFalse(menuDef.hasRead()); } + + @Test + public void testInsertShortCut() throws Exception { + + PowerMock.suppress(MemberMatcher.constructor(UpdateAction.class)); + SnapChatConfig snapChatConfig = EasyMock.partialMockBuilder(SnapChatConfig.class) + .addMockedMethod("readXML") + .createMock(); + Whitebox.setInternalState(snapChatConfig, "markReadMap", new HashMap()); + snapChatConfig.readXML(EasyMock.anyObject(XMLableReader.class)); + EasyMock.expectLastCall().anyTimes(); + EasyMock.replay(snapChatConfig); + + PowerMock.mockStatic(SnapChatConfig.class); + EasyMock.expect(SnapChatConfig.getInstance()).andReturn(snapChatConfig).anyTimes(); + PowerMock.replayAll(); + + SnapChatMenuDef menuDef = new SnapChatMenuDef("test", SnapChatAllTypes.Menu.BBS); + ShortCut action = new SnapChatUpdateAction(SnapChatAllTypes.Menu.BBS) { + @Override + protected void actionPerformed0(ActionEvent e) { + + } + }; + + Assert.assertTrue(menuDef.hasRead()); + + menuDef.insertShortCut(0, action); + Assert.assertFalse(menuDef.hasRead()); + } } \ No newline at end of file