small fixes
continuous-integration/drone/push Build is failing Details

This commit is contained in:
qvalentin 2022-05-22 18:05:21 +02:00
parent 259c15b785
commit fd4a2c0e83
Signed by: qvalentin
GPG Key ID: C979FA1EAFCABF1C
5 changed files with 31 additions and 22 deletions

View File

@ -18,7 +18,7 @@ abstract public class Subcommand {
public String executeSubcommand(String[] args) {
try {
commandExits(args[0]);
commandExists(args[0]);
return commands.get(args[0]).apply(args);
}
catch (IndexOutOfBoundsException e) {
@ -26,7 +26,7 @@ abstract public class Subcommand {
}
}
private void commandExits(String command) {
private void commandExists(String command) {
if (commands.get(command) == null) {
throw new CliError("Subcommand " + command + " does not exist! " + getUsage());
}

View File

@ -1,20 +1,24 @@
package main;
import persistence.GenericCSVDAO;
import persistence.category.CSVCategoryPersistenceAdapter;
import persistence.category.CategoryEntity;
import tag.TagName;
import java.io.File;
import persistence.PersistenceError;
public class Main {
public static void main(String[] args) {
CommandHandler commandHandler = new CommandHandler();
try {
commandHandler.executeCommand(args);
}
catch (PersistenceError persistenceError) {
System.out.println("There was a Error with loading or saving the persistence data.");
System.out.println(persistenceError.getMessage());
}
catch (RuntimeException runtimeException) {
System.out.println(runtimeException.getMessage());
}
}
}

View File

@ -13,7 +13,10 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
class GenericCSVDAOTest {
GenericCSVDAO<CategoryEntity> sut;
File file = new File("test.csv");
File file = File.createTempFile("test","link-ditch");
GenericCSVDAOTest() throws IOException {
}
@BeforeEach
public void beforeEach() throws IOException {
@ -35,8 +38,7 @@ class GenericCSVDAOTest {
public void addWorks() throws IOException {
assertEquals(0, sut.getALl().size());
var entityToAdd = new CategoryEntity("categoryName", 99);
sut.add(entityToAdd);
CategoryEntity entityToAdd = addDummyEntity("categoryName", 99);
var foundEntity = sut.getALl().stream().findFirst().orElseThrow();
assertEquals(entityToAdd, foundEntity);
@ -44,23 +46,27 @@ class GenericCSVDAOTest {
@Test
public void removeWorks() throws IOException {
var entityToAdd = new CategoryEntity("categoryName", 99);
sut.add(entityToAdd);
CategoryEntity entityToAdd = addDummyEntity("categoryName", 99);
sut.remove(entityToAdd);
assertEquals(0, sut.getALl().size());
}
@Test
public void removeAllWorks() throws IOException {
var entityToAdd1 = new CategoryEntity("categoryName1", 101);
sut.add(entityToAdd1);
var entityToAdd2 = new CategoryEntity("categoryName2", 102);
sut.add(entityToAdd2);
addDummyEntity("categoryName1", 101);
addDummyEntity("categoryName2", 102);
assertEquals(2, sut.getALl().size());
sut.removeAll();
assertEquals(0, sut.getALl().size());
}
private CategoryEntity addDummyEntity(String categoryName, int id) {
var entityToAdd = new CategoryEntity(categoryName, id);
sut.add(entityToAdd);
return entityToAdd;
}
}

View File

@ -18,12 +18,12 @@ public class LinkUseCase {
private final LinkRepository linkRepository;
private final CategoryRepository categoryRepository;
private final TaggingUseCase taggingUseCase;
private final LinkIdGenerator linkIdGenerator;
private final RandomLinkIdGenerator linkIdGenerator;
public LinkUseCase(LinkRepository linkRepository,
CategoryRepository categoryRepository,
TaggingUseCase taggingUseCase,
LinkIdGenerator linkIdGenerator) {
RandomLinkIdGenerator linkIdGenerator) {
this.linkRepository = linkRepository;
this.categoryRepository = categoryRepository;
this.taggingUseCase = taggingUseCase;

View File

@ -19,5 +19,4 @@ public class TaggingUseCase {
tagMatcherRepository.getTagMatchers().forEach(tagMatcher -> tagMatcher.ifMatches(url).addTo(result));
return result;
}
}