diff --git a/pom.xml b/pom.xml index d459e53..b84b0f1 100644 --- a/pom.xml +++ b/pom.xml @@ -15,6 +15,11 @@ + + + src/sudoku.save + + org.apache.maven.plugins diff --git a/src/main/java/src/Model.java b/src/main/java/src/Model.java index acb087c..6fda6f3 100644 --- a/src/main/java/src/Model.java +++ b/src/main/java/src/Model.java @@ -3,8 +3,12 @@ package src; import org.json.simple.JSONArray; import org.json.simple.JSONObject; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; import java.util.Iterator; import java.util.List; +import java.util.Scanner; public class Model { @@ -84,7 +88,29 @@ public class Model { } - public void loadAllData() { + public String loadAllData() { + + + File file = new File("src/main/java/src/sudoku.save"); + + if (file.exists()) { + try { + file.createNewFile(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + String line = ""; + try { + Scanner scanner = new Scanner(file); + while (scanner.hasNextLine()) { + line = line + scanner.nextLine(); + + } + } catch (FileNotFoundException e) { + throw new RuntimeException(e); + } + return line; } diff --git a/src/main/java/src/sudoku.save b/src/main/java/src/sudoku.save new file mode 100644 index 0000000..c8324de --- /dev/null +++ b/src/main/java/src/sudoku.save @@ -0,0 +1,3 @@ +A B C +D E F +G H I diff --git a/src/test/java/ModelTest.java b/src/test/java/ModelTest.java index 237aa26..c937661 100644 --- a/src/test/java/ModelTest.java +++ b/src/test/java/ModelTest.java @@ -5,6 +5,9 @@ import src.GameField; import src.MainFrame; import src.Model; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; import java.util.Iterator; import static org.junit.jupiter.api.Assertions.*; @@ -185,6 +188,28 @@ public class ModelTest extends MainFrame { @Test public void test_loadAllData() { + + //write to file + try { + FileWriter write = new FileWriter("src/main/java/src/sudoku.save"); + + write.write("A B C\nD E F\nG H I\n"); + write.close(); + + } catch (IOException e) { + throw new RuntimeException(e); + + } + + GameField gameField = new GameField(360); + Model model = new Model(gameField); + + String s = model.loadAllData(); + + if (s.equals("A B C\nD E F\nG H I\n")) { + assertTrue(true); + } + } @Test