Skip to content

Commit

Permalink
Fixed Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
avidraccoon committed Dec 2, 2024
1 parent 708974d commit eb0506c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 31 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package coppercore.parameter_tools;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

import com.google.gson.ExclusionStrategy;
import com.google.gson.FieldAttributes;
import com.google.gson.FieldNamingPolicy;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.LongSerializationPolicy;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class JSONSync<T> {

Expand Down Expand Up @@ -82,11 +81,10 @@ public boolean shouldSkipClass(Class<?> clazz) {
if (this.config.prettyPrinting) builder.setPrettyPrinting();
if (this.config.excludeFieldsWithoutExposeAnnotation)
builder.excludeFieldsWithoutExposeAnnotation();
builder
.setFieldNamingPolicy(this.config.namingPolicy)
.setLongSerializationPolicy(this.config.longSerializationPolicy)
.addDeserializationExclusionStrategy(strategy)
.addSerializationExclusionStrategy(strategy);
builder.setFieldNamingPolicy(this.config.namingPolicy)
.setLongSerializationPolicy(this.config.longSerializationPolicy)
.addDeserializationExclusionStrategy(strategy)
.addSerializationExclusionStrategy(strategy);
return builder.create();
}

Expand Down
34 changes: 13 additions & 21 deletions parameter_tools/src/test/java/JSONSyncTests.java
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
package coppercore.parameter_tools.test;

import coppercore.parameter_tools.JSONSync;
import java.io.File;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;

import coppercore.parameter_tools.JSONSync;
import org.junit.jupiter.api.Test;

public class JSONSyncTests {

public static final String DIRECTORY = new File("").getAbsolutePath();
public static final String BUILD_DIRECTORY = DIRECTORY + "\\build";
public static final String RESOURCE_DIRECTORY = BUILD_DIRECTORY + "\\resources\\test";

@BeforeEach
public void TestPrep() {
ExampleJsonSyncClass.synced =
new JSONSync<ExampleJsonSyncClass>(
new ExampleJsonSyncClass(),
"filePath",
RESOURCE_DIRECTORY + "\\ExampleJsonSyncClass.json",
new JSONSync.JSONSyncConfigBuilder().setPrettyPrinting(true).build());
}

//@Test
@Test
public void JsonSyncLoadDataTest() {
System.out.println("LoadTest");
ExampleJsonSyncClass.synced.loadData();
ExampleJsonSyncClass instance = ExampleJsonSyncClass.synced.getObject();

Assertions.assertEquals(10.0, instance.testDouble);
Assertions.assertEquals(2, instance.testInt);
Assertions.assertNull(instance.motorData);
System.out.println(instance);
System.out.println("");
}

//@Test
@Test
public void JsonSyncSetFileTest() {
System.out.println("SetTest");
ExampleJsonSyncClass.synced.setFile(
"filePath");
ExampleJsonSyncClass.synced.setFile(RESOURCE_DIRECTORY + "\\SetFileTest.json");
ExampleJsonSyncClass.synced.loadData();
ExampleJsonSyncClass instance = ExampleJsonSyncClass.synced.getObject();

Expand All @@ -43,22 +43,14 @@ public void JsonSyncSetFileTest() {
Assertions.assertEquals(-12.3, instance.motorData.minVoltage);
Assertions.assertEquals(16.4, instance.motorData.maxVoltage);
Assertions.assertEquals(0.0, instance.motorData.currentVoltage);
System.out.println(instance);
System.out.println("");
}

//@Test
@Test
public void JsonSyncSaveFileTest() {
System.out.println("SaveTest");
ExampleJsonSyncClass.synced.loadData();
ExampleJsonSyncClass instance = ExampleJsonSyncClass.synced.getObject();
System.out.println(instance);
System.out.println("\nSaving File\n");
instance.testInt = 10;
ExampleJsonSyncClass.synced.setFile(
"filePath");
ExampleJsonSyncClass.synced.setFile(RESOURCE_DIRECTORY + "\\SaveFileTest.json");
ExampleJsonSyncClass.synced.saveData();
System.out.println(instance);
System.out.println("");
}
}

0 comments on commit eb0506c

Please sign in to comment.