From 3447c9359fd3acc55e0b7add9473cf167722ee31 Mon Sep 17 00:00:00 2001
From: steyer <steyer10@gmail.com>
Date: Fri, 29 Nov 2019 12:19:50 +0100
Subject: [PATCH] ?

---
 manualtest/game/JTableTest.java |  2 +-
 test/game/GameLogicTest.java    | 18 +++++-----
 test/game/JsonTest.java         | 58 +++++++++++++++++++++++++++++++++
 3 files changed, 68 insertions(+), 10 deletions(-)
 create mode 100644 test/game/JsonTest.java

diff --git a/manualtest/game/JTableTest.java b/manualtest/game/JTableTest.java
index cae8839..40b30b9 100644
--- a/manualtest/game/JTableTest.java
+++ b/manualtest/game/JTableTest.java
@@ -26,7 +26,7 @@ public class JTableTest {
 		JButton stopButton = new JButton("Stop");
 		startButton.addActionListener(new StartButtonListener(testModel));
 		stepButton.addActionListener(new StepButtonListener(testModel));
-		stopButton.addActionListener(new StopButtonListener(testModel));
+  		stopButton.addActionListener(new StopButtonListener(testModel));
 		JPanel bottomPanel = new JPanel();
 		bottomPanel.add(stepButton);
 		bottomPanel.add(startButton);
diff --git a/test/game/GameLogicTest.java b/test/game/GameLogicTest.java
index 3204d88..97e91e5 100644
--- a/test/game/GameLogicTest.java
+++ b/test/game/GameLogicTest.java
@@ -18,23 +18,23 @@ class GameLogicTest {
 
 	@Test
 	void testStep1() {
-		testModel.setValueAt(true, 0, 1);	//-+	->	+-
-		testModel.setValueAt(true, 1, 0);	//++	->	--
+		testModel.setValueAt(true, 0, 1);	//-+	->	++
+		testModel.setValueAt(true, 1, 0);	//++	->	++
 		testModel.setValueAt(true, 1, 1);
 		
 		testModel.step();
 		
 		assertTrue((boolean) testModel.getValueAt(0, 0)); 
-		assertFalse((boolean) testModel.getValueAt(0, 1)); 
-		assertFalse((boolean) testModel.getValueAt(1, 0)); 
-		assertFalse((boolean) testModel.getValueAt(1, 1)); 
+		assertTrue((boolean) testModel.getValueAt(0, 1));
+		assertTrue((boolean) testModel.getValueAt(1, 0));
+		assertTrue((boolean) testModel.getValueAt(1, 1));
 		
 		testModel.step();
 		
-		assertFalse((boolean) testModel.getValueAt(0, 0)); 
-		assertFalse((boolean) testModel.getValueAt(0, 1)); 
-		assertFalse((boolean) testModel.getValueAt(1, 0)); 
-		assertFalse((boolean) testModel.getValueAt(1, 1));
+		assertTrue((boolean) testModel.getValueAt(0, 0));
+		assertTrue((boolean) testModel.getValueAt(0, 1));
+		assertTrue((boolean) testModel.getValueAt(1, 0));
+		assertTrue((boolean) testModel.getValueAt(1, 1));
 	}
 
 }
diff --git a/test/game/JsonTest.java b/test/game/JsonTest.java
new file mode 100644
index 0000000..4e5e8f7
--- /dev/null
+++ b/test/game/JsonTest.java
@@ -0,0 +1,58 @@
+package game;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+import junit.framework.Assert.*;
+
+import javax.swing.*;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+
+public class JsonTest {
+    private GameBoard board;
+    private JFileChooser chooser;
+
+    @BeforeEach
+    public void setUp() {
+        board = new GameBoard(10, 10);
+        chooser = new JFileChooser();
+        board.get(5, 5).setAlive(true);
+        board.get(5, 6).setAlive(true);
+        board.get(5, 7).setAlive(true);
+        board.get(5, 8).setAlive(true);
+        board.get(5, 9).setAlive(true);
+    }
+
+    @Test
+    public void saveLoadTest() throws FileNotFoundException {
+        int returnVal = chooser.showSaveDialog(new JFrame());
+        File destination;
+        if (returnVal == JFileChooser.APPROVE_OPTION) {
+            destination = chooser.getSelectedFile();
+            try {
+                GameBoardJson.saveToFile(board, destination);
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+
+            int returnVal2 = chooser.showOpenDialog(new JFrame());
+            File savedFile;
+            if (returnVal2 == JFileChooser.APPROVE_OPTION) {
+                savedFile = chooser.getSelectedFile();
+                GameBoard loadedBoard;
+
+                loadedBoard = GameBoardJson.loadFromFile(savedFile);
+
+
+                for (int i = 0; i < 10; i++)
+                    for (int j = 1; j < 10; j++) {
+                        assertEquals(board.get(i, j).isAlive(), loadedBoard.get(i, j).isAlive());
+                    }
+            }
+        }
+    }
+}
-- 
GitLab