found a bug, this is why we write tests
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
f616b4b4bf
commit
45630b2813
|
@ -61,7 +61,7 @@ public class GenericCSVDAO<T extends CSVSerializable> implements GenericDAO<T> {
|
|||
|
||||
public void removeAll() {
|
||||
|
||||
try (BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(this.file, true))) {
|
||||
try (BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(this.file, false))) {
|
||||
bufferedWriter.write("");
|
||||
}
|
||||
catch (IOException e) {
|
||||
|
|
|
@ -1,39 +1,38 @@
|
|||
package persistence;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.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<CategoryEntity> sut;
|
||||
|
||||
public void beforeEachDirty() throws IOException {
|
||||
File file = new File("test.csv");
|
||||
|
||||
@BeforeEach
|
||||
public void beforeEach() throws IOException {
|
||||
|
||||
if (file.exists()) {
|
||||
file.delete();
|
||||
}
|
||||
file.createNewFile();
|
||||
|
||||
this.sut = new GenericCSVDAO<CategoryEntity>(file,CategoryEntity::new);
|
||||
|
||||
this.sut = new GenericCSVDAO<>(file, CategoryEntity::new);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void afterEach() {
|
||||
file.delete();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addWorks() throws IOException {
|
||||
|
||||
beforeEachDirty();
|
||||
|
||||
|
||||
assertEquals(0, sut.getALl().size());
|
||||
|
||||
var entityToAdd = new CategoryEntity("categoryName", 99);
|
||||
|
@ -41,18 +40,10 @@ class GenericCSVDAOTest {
|
|||
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);
|
||||
|
||||
|
@ -63,10 +54,6 @@ class GenericCSVDAOTest {
|
|||
|
||||
@Test
|
||||
public void removeAllWorks() throws IOException {
|
||||
|
||||
beforeEachDirty();
|
||||
|
||||
|
||||
var entityToAdd1 = new CategoryEntity("categoryName1", 101);
|
||||
sut.add(entityToAdd1);
|
||||
var entityToAdd2 = new CategoryEntity("categoryName2", 102);
|
||||
|
|
Reference in a new issue