From 552e3f4d00b55845f89366623ad2c3dc7b5a40f3 Mon Sep 17 00:00:00 2001 From: Harrison Date: Mon, 13 Apr 2020 11:21:42 +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=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E4=B8=80=E4=B8=8B=E8=8F=9C=E5=8D=95=E7=9A=84=E9=80=BB=E8=BE=91?= =?UTF-8?q?=E3=80=82=20=E9=BB=98=E8=AE=A4=E6=98=AF=E5=B7=B2=E8=AF=BB?= =?UTF-8?q?=E7=8A=B6=E6=80=81=EF=BC=8C=E5=8F=AA=E6=9C=89=E5=8A=A0=E5=85=A5?= =?UTF-8?q?=E4=BA=86=E9=9D=9E=E5=B7=B2=E8=AF=BB=E7=9A=84=E6=8C=89=E9=92=AE?= =?UTF-8?q?=EF=BC=8C=E6=89=8D=E4=BC=9A=E5=B1=95=E7=A4=BA=E6=88=90=E9=9D=9E?= =?UTF-8?q?=E5=B7=B2=E8=AF=BB=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/fr/design/menu/SnapChatMenuDef.java | 28 ++++++- .../fr/design/menu/SnapChatUpdateAction.java | 9 ++- .../com/fr/design/notification/SnapChat.java | 7 ++ .../design/notification/SnapChatConfig.java | 8 +- .../fr/design/menu/SnapChatMenuDefTest.java | 76 +++++++++++++++++++ 5 files changed, 124 insertions(+), 4 deletions(-) create mode 100644 designer-base/src/test/java/com/fr/design/menu/SnapChatMenuDefTest.java 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 473c17f25..defbf0dbb 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 @@ -42,7 +42,9 @@ public class SnapChatMenuDef extends MenuDef implements SnapChat { public boolean hasRead() { String calcKey = calcKey(); - return SnapChatConfig.getInstance().hasRead(calcKey); + Boolean val = SnapChatConfig.getInstance().hasRead(calcKey); + // 默认读过了。 + return val == null ? defaultStatus() : val; } @Override @@ -52,6 +54,30 @@ public class SnapChatMenuDef extends MenuDef implements SnapChat { SnapChatConfig.getInstance().markRead(calcKey); } + @Override + public boolean defaultStatus() { + + return true; + } + + @Override + public void addShortCut(ShortCut... shortCuts) { + + 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); + } + @Override public SnapChatKey key() { diff --git a/designer-base/src/main/java/com/fr/design/menu/SnapChatUpdateAction.java b/designer-base/src/main/java/com/fr/design/menu/SnapChatUpdateAction.java index 482954546..9ade76250 100644 --- a/designer-base/src/main/java/com/fr/design/menu/SnapChatUpdateAction.java +++ b/designer-base/src/main/java/com/fr/design/menu/SnapChatUpdateAction.java @@ -32,7 +32,8 @@ public abstract class SnapChatUpdateAction extends UpdateAction implements SnapC public boolean hasRead() { String calcKey = calcKey(); - return SnapChatConfig.getInstance().hasRead(calcKey); + Boolean val = SnapChatConfig.getInstance().hasRead(calcKey); + return val == null ? defaultStatus() : val; } @Override @@ -42,6 +43,12 @@ public abstract class SnapChatUpdateAction extends UpdateAction implements SnapC SnapChatConfig.getInstance().markRead(calcKey); } + @Override + public boolean defaultStatus() { + + return false; + } + @Override public SnapChatKey key() { diff --git a/designer-base/src/main/java/com/fr/design/notification/SnapChat.java b/designer-base/src/main/java/com/fr/design/notification/SnapChat.java index 8dd6f8aa2..4f610c060 100644 --- a/designer-base/src/main/java/com/fr/design/notification/SnapChat.java +++ b/designer-base/src/main/java/com/fr/design/notification/SnapChat.java @@ -7,6 +7,13 @@ package com.fr.design.notification; **/ public interface SnapChat { + /** + * 默认状态 + * + * @return 默认状态 + */ + boolean defaultStatus(); + /** * 已读 * diff --git a/designer-base/src/main/java/com/fr/design/notification/SnapChatConfig.java b/designer-base/src/main/java/com/fr/design/notification/SnapChatConfig.java index ed6b7a6d8..c192d054c 100644 --- a/designer-base/src/main/java/com/fr/design/notification/SnapChatConfig.java +++ b/designer-base/src/main/java/com/fr/design/notification/SnapChatConfig.java @@ -31,8 +31,7 @@ public class SnapChatConfig implements XMLable { public Boolean hasRead(String key) { Map map = markReadMap; - Boolean val = map.get(key); - return val == null ? Boolean.FALSE : val; + return map.get(key); } public void markRead(String key) { @@ -40,6 +39,11 @@ public class SnapChatConfig implements XMLable { markReadMap.put(key, Boolean.TRUE); } + public void resetRead(String key) { + + markReadMap.put(key, Boolean.FALSE); + } + @Override public void readXML(XMLableReader reader) { 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 new file mode 100644 index 000000000..25671596c --- /dev/null +++ b/designer-base/src/test/java/com/fr/design/menu/SnapChatMenuDefTest.java @@ -0,0 +1,76 @@ +package com.fr.design.menu; + +import com.fr.config.dao.DaoContext; +import com.fr.config.dao.impl.LocalClassHelperDao; +import com.fr.config.dao.impl.LocalEntityDao; +import com.fr.config.dao.impl.LocalXmlEntityDao; +import com.fr.design.actions.UpdateAction; +import com.fr.design.notification.SnapChatAllTypes; +import com.fr.design.notification.SnapChatConfig; +import com.fr.stable.xml.XMLableReader; +import com.fr.store.StateHubManager; +import com.fr.store.impl.MemoryLock; +import com.fr.store.impl.MemoryStore; +import com.fr.transaction.Configurations; +import com.fr.transaction.LocalConfigurationHelper; +import org.easymock.EasyMock; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.powermock.api.easymock.PowerMock; +import org.powermock.api.support.membermodification.MemberMatcher; +import org.powermock.core.classloader.annotations.PowerMockIgnore; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import org.powermock.reflect.Whitebox; + +import java.awt.event.ActionEvent; +import java.util.HashMap; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({SnapChatConfig.class, SnapChatUpdateAction.class}) +@PowerMockIgnore({"javax.crypto.*","javax.net.ssl.*","sun.security.ssl.*","com.sun.*"}) +public class SnapChatMenuDefTest { + + @Before + public void before() throws Exception { + + DaoContext.setXmlEntityDao(new LocalXmlEntityDao()); + DaoContext.setClassHelperDao(new LocalClassHelperDao()); + DaoContext.setEntityDao(new LocalEntityDao()); + StateHubManager.setLock(new MemoryLock()); + StateHubManager.setStorage(new MemoryStore()); + Configurations.setHelper(new LocalConfigurationHelper()); + } + + @Test + public void testAddShortCut() 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.addShortCut(action); + Assert.assertFalse(menuDef.hasRead()); + } +} \ No newline at end of file