From f9c7f028702cb82a0df3516f8cad938514a3549e Mon Sep 17 00:00:00 2001 From: Kevin Ramharak Date: Tue, 23 Apr 2019 21:56:31 +0200 Subject: [PATCH] fix tests and configuration --- Server/pom.xml | 1 + .../simon987/server/assembly/MemoryTest.java | 26 ++++++++++++++----- .../instruction/AddInstructionTest.java | 22 +++++++++++++--- .../instruction/AndInstructionTest.java | 26 ++++++++++++++----- 4 files changed, 59 insertions(+), 16 deletions(-) diff --git a/Server/pom.xml b/Server/pom.xml index 67f82ba..d3b61cd 100644 --- a/Server/pom.xml +++ b/Server/pom.xml @@ -77,6 +77,7 @@ maven-surefire-plugin 2.7.2 + never ./src/main/resources diff --git a/Server/src/test/java/net/simon987/server/assembly/MemoryTest.java b/Server/src/test/java/net/simon987/server/assembly/MemoryTest.java index e0faa80..effb12a 100644 --- a/Server/src/test/java/net/simon987/server/assembly/MemoryTest.java +++ b/Server/src/test/java/net/simon987/server/assembly/MemoryTest.java @@ -5,12 +5,29 @@ import org.junit.Test; import static org.junit.Assert.*; +import java.io.File; public class MemoryTest { + + ServerConfiguration getConfig() { + String filePath = "config.properties"; + + if (!new File(filePath).exists()) { + File fallback = new File("Server/src/main/resources/", filePath); + if (fallback.exists()) { + filePath = fallback.getAbsolutePath(); + } else { + throw new AssertionError("'config.properties' and 'Server/src/main/resources/config.properties' cannot be found with working directory: " + new File("").getAbsolutePath()); + } + } + + ServerConfiguration config = new ServerConfiguration(filePath); + return config; + } + @Test public void getSet() { - ServerConfiguration config = new ServerConfiguration("config.properties"); - int memorySize = config.getInt("memory_size"); + int memorySize = getConfig().getInt("memory_size"); Memory memory = new Memory(memorySize); memory.set(1, 1); @@ -28,12 +45,9 @@ public class MemoryTest { @Test public void write() { - - ServerConfiguration config = new ServerConfiguration("config.properties"); - int memorySize = config.getInt("memory_size"); + int memorySize = getConfig().getInt("memory_size"); Memory memory = new Memory(memorySize); - assertTrue(memory.write(0, new char[memorySize], 0, memorySize)); assertFalse(memory.write(0, new char[memorySize], 0, memorySize + 1)); assertFalse(memory.write(0, new char[memorySize], 0, -1)); diff --git a/Server/src/test/java/net/simon987/server/assembly/instruction/AddInstructionTest.java b/Server/src/test/java/net/simon987/server/assembly/instruction/AddInstructionTest.java index ba381c3..e696d35 100644 --- a/Server/src/test/java/net/simon987/server/assembly/instruction/AddInstructionTest.java +++ b/Server/src/test/java/net/simon987/server/assembly/instruction/AddInstructionTest.java @@ -9,17 +9,32 @@ import org.junit.Test; import static org.junit.Assert.*; +import java.io.File; public class AddInstructionTest { + ServerConfiguration getConfig() { + String filePath = "config.properties"; + + if (!new File(filePath).exists()) { + File fallback = new File("Server/src/main/resources/", filePath); + if (fallback.exists()) { + filePath = fallback.getAbsolutePath(); + } else { + throw new AssertionError("'config.properties' and 'Server/src/main/resources/config.properties' cannot be found with working directory: " + new File("").getAbsolutePath()); + } + } + + ServerConfiguration config = new ServerConfiguration(filePath); + return config; + } /** * ADD mem/reg, mem/reg */ @Test public void addTargetTarget() { - ServerConfiguration config = new ServerConfiguration("config.properties"); - int memorySize = config.getInt("memory_size"); + int memorySize = getConfig().getInt("memory_size"); //Memory Memory memory = new Memory(memorySize); @@ -129,8 +144,7 @@ public class AddInstructionTest { */ @Test public void addTargetImm() { - ServerConfiguration config = new ServerConfiguration("config.properties"); - int memorySize = config.getInt("memory_size"); + int memorySize = getConfig().getInt("memory_size"); //Memory Memory memory = new Memory(memorySize); diff --git a/Server/src/test/java/net/simon987/server/assembly/instruction/AndInstructionTest.java b/Server/src/test/java/net/simon987/server/assembly/instruction/AndInstructionTest.java index 5c7c404..a4ac78c 100644 --- a/Server/src/test/java/net/simon987/server/assembly/instruction/AndInstructionTest.java +++ b/Server/src/test/java/net/simon987/server/assembly/instruction/AndInstructionTest.java @@ -7,13 +7,29 @@ import org.junit.Test; import static org.junit.Assert.assertEquals; +import java.io.File; public class AndInstructionTest { + + ServerConfiguration getConfig() { + String filePath = "config.properties"; + + if (!new File(filePath).exists()) { + File fallback = new File("Server/src/main/resources/", filePath); + if (fallback.exists()) { + filePath = fallback.getAbsolutePath(); + } else { + throw new AssertionError("'config.properties' and 'Server/src/main/resources/config.properties' cannot be found with working directory: " + new File("").getAbsolutePath()); + } + } + + ServerConfiguration config = new ServerConfiguration(filePath); + return config; + } + @Test public void executeTargetTarget() { - - ServerConfiguration config = new ServerConfiguration("config.properties"); - int memorySize = config.getInt("memory_size"); + int memorySize = getConfig().getInt("memory_size"); //Memory Memory memory = new Memory(memorySize); @@ -53,9 +69,7 @@ public class AndInstructionTest { @Test public void executeTargetImm() { - - ServerConfiguration config = new ServerConfiguration("config.properties"); - int memorySize = config.getInt("memory_size"); + int memorySize = getConfig().getInt("memory_size"); //Memory Memory memory = new Memory(memorySize);