diff --git a/0-Plugin/pom.xml b/0-Plugin/pom.xml
index c062f6d..1b87eba 100644
--- a/0-Plugin/pom.xml
+++ b/0-Plugin/pom.xml
@@ -24,7 +24,19 @@
1.0-SNAPSHOT
compile
-
+
+ org.junit.jupiter
+ junit-jupiter
+ RELEASE
+ test
+
+
+ org.junit.jupiter
+ junit-jupiter
+ RELEASE
+ test
+
+
17
diff --git a/0-Plugin/src/test/java/persistence/GenericCSVDAOTest.java b/0-Plugin/src/test/java/persistence/GenericCSVDAOTest.java
new file mode 100644
index 0000000..ad99a63
--- /dev/null
+++ b/0-Plugin/src/test/java/persistence/GenericCSVDAOTest.java
@@ -0,0 +1,79 @@
+package persistence;
+
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import persistence.category.CategoryEntity;
+
+import java.io.File;
+import java.io.IOException;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.*;
+
+class GenericCSVDAOTest {
+
+ GenericCSVDAO sut;
+
+ public void beforeEachDirty() throws IOException {
+ File file = new File("test.csv");
+
+ if (file.exists()){
+ file.delete();
+ }
+ file.createNewFile();
+
+ this.sut = new GenericCSVDAO(file,CategoryEntity::new);
+
+
+ }
+
+ @Test
+ public void addWorks() throws IOException {
+
+ beforeEachDirty();
+
+
+ assertEquals(0, sut.getALl().size());
+
+ var entityToAdd = new CategoryEntity("categoryName",99);
+ sut.add(entityToAdd);
+ var foundEntity = sut.getALl().stream().findFirst().orElseThrow();
+
+ assertEquals(entityToAdd,foundEntity);
+
+
+
+
+ }
+
+ @Test
+ public void removeWorks() throws IOException {
+
+ beforeEachDirty();
+
+
+ var entityToAdd = new CategoryEntity("categoryName",99);
+ sut.add(entityToAdd);
+
+ sut.remove(entityToAdd);
+
+ assertEquals(0, sut.getALl().size());
+ }
+
+ @Test
+ public void removeAllWorks() throws IOException {
+
+ beforeEachDirty();
+
+
+ var entityToAdd1 = new CategoryEntity("categoryName1",101);
+ sut.add(entityToAdd1);
+ var entityToAdd2 = new CategoryEntity("categoryName2",102);
+ sut.add(entityToAdd2);
+ assertEquals(2, sut.getALl().size());
+ sut.removeAll();
+
+ assertEquals(0, sut.getALl().size());
+ }
+}
\ No newline at end of file
diff --git a/1-Adapter/src/main/java/persistence/category/CategoryEntity.java b/1-Adapter/src/main/java/persistence/category/CategoryEntity.java
index ced3733..0abe8f2 100644
--- a/1-Adapter/src/main/java/persistence/category/CategoryEntity.java
+++ b/1-Adapter/src/main/java/persistence/category/CategoryEntity.java
@@ -5,6 +5,8 @@ import category.CategoryId;
import category.CategoryName;
import persistence.csv.CSVSerializable;
+import java.util.Objects;
+
public class CategoryEntity implements CSVSerializable {
private final String name;
@@ -36,4 +38,17 @@ public class CategoryEntity implements CSVSerializable {
public String toCSVString() {
return name + CSVSerializable.seperator + Integer.toString(id);
}
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+ CategoryEntity that = (CategoryEntity) o;
+ return id == that.id && Objects.equals(name, that.name);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(name, id);
+ }
}
diff --git a/3-Domain/pom.xml b/3-Domain/pom.xml
index bcdff14..c5248ff 100644
--- a/3-Domain/pom.xml
+++ b/3-Domain/pom.xml
@@ -19,7 +19,13 @@
1.0-SNAPSHOT
compile
-
+
+ org.junit.jupiter
+ junit-jupiter
+ RELEASE
+ test
+
+
17