Browse Source

aus der Sudoku File gelesen und den Test dazu geschreiben

remotes/origin/develop
fdai7460 2 years ago
parent
commit
3efea61d57
  1. 5
      pom.xml
  2. 28
      src/main/java/src/Model.java
  3. 3
      src/main/java/src/sudoku.save
  4. 25
      src/test/java/ModelTest.java

5
pom.xml

@ -15,6 +15,11 @@
</properties>
<build>
<resources>
<resource>
<directory>src/sudoku.save</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>

28
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;
}

3
src/main/java/src/sudoku.save

@ -0,0 +1,3 @@
A B C
D E F
G H I

25
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

Loading…
Cancel
Save