From 83d8443fef41488ac1dbfa250f947ec26ecd29be Mon Sep 17 00:00:00 2001 From: dupirefr Date: Sat, 27 Jul 2019 11:24:45 +0200 Subject: [PATCH] [BAEL-3090] Added test + removed cursor --- patterns/design-patterns-2/pom.xml | 7 +++++++ .../main/java/com/baeldung/memento/TextEditor.java | 8 ++++++++ .../main/java/com/baeldung/memento/TextWindow.java | 12 ++++-------- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/patterns/design-patterns-2/pom.xml b/patterns/design-patterns-2/pom.xml index 392035ab84..574edecb36 100644 --- a/patterns/design-patterns-2/pom.xml +++ b/patterns/design-patterns-2/pom.xml @@ -31,6 +31,12 @@ commons-lang3 ${commons-lang3.version} + + org.assertj + assertj-core + ${assertj.version} + test + @@ -38,5 +44,6 @@ 1.8 1.8 16.0.2 + 3.12.2 diff --git a/patterns/design-patterns-2/src/main/java/com/baeldung/memento/TextEditor.java b/patterns/design-patterns-2/src/main/java/com/baeldung/memento/TextEditor.java index cf08e2b226..37ac962773 100644 --- a/patterns/design-patterns-2/src/main/java/com/baeldung/memento/TextEditor.java +++ b/patterns/design-patterns-2/src/main/java/com/baeldung/memento/TextEditor.java @@ -9,6 +9,14 @@ public class TextEditor { this.textWindow = textWindow; } + public void write(String text) { + textWindow.addText(text); + } + + public String print() { + return textWindow.getCurrentText(); + } + public void hitSave() { savedTextWindow = textWindow.save(); } diff --git a/patterns/design-patterns-2/src/main/java/com/baeldung/memento/TextWindow.java b/patterns/design-patterns-2/src/main/java/com/baeldung/memento/TextWindow.java index 5fdfda1998..08778561b0 100644 --- a/patterns/design-patterns-2/src/main/java/com/baeldung/memento/TextWindow.java +++ b/patterns/design-patterns-2/src/main/java/com/baeldung/memento/TextWindow.java @@ -3,11 +3,13 @@ package com.baeldung.memento; public class TextWindow { private StringBuilder currentText; - private Coordinates cursorPosition; public TextWindow() { this.currentText = new StringBuilder(); - this.cursorPosition = new Coordinates(0, 0); + } + + public String getCurrentText() { + return currentText.toString(); } public void addText(String text) { @@ -20,11 +22,5 @@ public class TextWindow { public void restore(TextWindowState save) { currentText = new StringBuilder(save.getText()); - cursorPosition = atTextEnd(); - } - - private Coordinates atTextEnd() { - String[] lines = currentText.toString().split("\n"); - return new Coordinates(lines[lines.length - 1].length(), lines.length); } }