备忘录模式测试

This commit is contained in:
2020-07-21 16:06:27 +08:00
parent 189102cd00
commit 71eb26b66a

View File

@@ -0,0 +1,56 @@
package top.fjy8018.designpattern.pattern.behavior.memento;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
/**
* @author F嘉阳
* @date 2020/3/6 17:07
*/
@Slf4j
class ArticleMementoTest {
@Test
void getTitle() {
ArticleMementoManager articleMementoManager = new ArticleMementoManager();
Article article = new Article("如影随行的设计模式A", "手记内容A", "手记图片A");
// 存档
ArticleMemento articleMemento = article.saveToMemento();
articleMementoManager.addMemento(articleMemento);
log.info("标题:" + article.getTitle() + " 内容:" + article.getContent() + " 图片:" + article.getImgs() + " 暂存成功");
log.info("手记完整信息:" + article);
log.info("修改手记start");
article.setTitle("如影随行的设计模式B");
article.setContent("手记内容B");
article.setImgs("手记图片B");
log.info("修改手记end");
log.info("手记完整信息:" + article);
articleMemento = article.saveToMemento();
articleMementoManager.addMemento(articleMemento);
article.setTitle("如影随行的设计模式C");
article.setContent("手记内容C");
article.setImgs("手记图片C");
log.info("暂存回退start");
// 取档
log.info("回退出栈1次");
articleMemento = articleMementoManager.getMemento();
article.undoFromMemento(articleMemento);
log.info("回退出栈2次");
articleMemento = articleMementoManager.getMemento();
article.undoFromMemento(articleMemento);
log.info("暂存回退end");
log.info("手记完整信息:" + article);
}
}