This commit is contained in:
parent
259c15b785
commit
fd4a2c0e83
|
@ -18,7 +18,7 @@ abstract public class Subcommand {
|
||||||
public String executeSubcommand(String[] args) {
|
public String executeSubcommand(String[] args) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
commandExits(args[0]);
|
commandExists(args[0]);
|
||||||
return commands.get(args[0]).apply(args);
|
return commands.get(args[0]).apply(args);
|
||||||
}
|
}
|
||||||
catch (IndexOutOfBoundsException e) {
|
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) {
|
if (commands.get(command) == null) {
|
||||||
throw new CliError("Subcommand " + command + " does not exist! " + getUsage());
|
throw new CliError("Subcommand " + command + " does not exist! " + getUsage());
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,20 +1,24 @@
|
||||||
package main;
|
package main;
|
||||||
|
|
||||||
import persistence.GenericCSVDAO;
|
import persistence.PersistenceError;
|
||||||
import persistence.category.CSVCategoryPersistenceAdapter;
|
|
||||||
import persistence.category.CategoryEntity;
|
|
||||||
import tag.TagName;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
|
||||||
CommandHandler commandHandler = new CommandHandler();
|
CommandHandler commandHandler = new CommandHandler();
|
||||||
|
|
||||||
commandHandler.executeCommand(args);
|
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());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,10 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
class GenericCSVDAOTest {
|
class GenericCSVDAOTest {
|
||||||
|
|
||||||
GenericCSVDAO<CategoryEntity> sut;
|
GenericCSVDAO<CategoryEntity> sut;
|
||||||
File file = new File("test.csv");
|
File file = File.createTempFile("test","link-ditch");
|
||||||
|
|
||||||
|
GenericCSVDAOTest() throws IOException {
|
||||||
|
}
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void beforeEach() throws IOException {
|
public void beforeEach() throws IOException {
|
||||||
|
@ -35,8 +38,7 @@ class GenericCSVDAOTest {
|
||||||
public void addWorks() throws IOException {
|
public void addWorks() throws IOException {
|
||||||
assertEquals(0, sut.getALl().size());
|
assertEquals(0, sut.getALl().size());
|
||||||
|
|
||||||
var entityToAdd = new CategoryEntity("categoryName", 99);
|
CategoryEntity entityToAdd = addDummyEntity("categoryName", 99);
|
||||||
sut.add(entityToAdd);
|
|
||||||
var foundEntity = sut.getALl().stream().findFirst().orElseThrow();
|
var foundEntity = sut.getALl().stream().findFirst().orElseThrow();
|
||||||
|
|
||||||
assertEquals(entityToAdd, foundEntity);
|
assertEquals(entityToAdd, foundEntity);
|
||||||
|
@ -44,23 +46,27 @@ class GenericCSVDAOTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void removeWorks() throws IOException {
|
public void removeWorks() throws IOException {
|
||||||
var entityToAdd = new CategoryEntity("categoryName", 99);
|
CategoryEntity entityToAdd = addDummyEntity("categoryName", 99);
|
||||||
sut.add(entityToAdd);
|
|
||||||
|
|
||||||
sut.remove(entityToAdd);
|
sut.remove(entityToAdd);
|
||||||
|
|
||||||
assertEquals(0, sut.getALl().size());
|
assertEquals(0, sut.getALl().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void removeAllWorks() throws IOException {
|
public void removeAllWorks() throws IOException {
|
||||||
var entityToAdd1 = new CategoryEntity("categoryName1", 101);
|
addDummyEntity("categoryName1", 101);
|
||||||
sut.add(entityToAdd1);
|
addDummyEntity("categoryName2", 102);
|
||||||
var entityToAdd2 = new CategoryEntity("categoryName2", 102);
|
|
||||||
sut.add(entityToAdd2);
|
|
||||||
assertEquals(2, sut.getALl().size());
|
assertEquals(2, sut.getALl().size());
|
||||||
sut.removeAll();
|
sut.removeAll();
|
||||||
|
|
||||||
assertEquals(0, sut.getALl().size());
|
assertEquals(0, sut.getALl().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private CategoryEntity addDummyEntity(String categoryName, int id) {
|
||||||
|
var entityToAdd = new CategoryEntity(categoryName, id);
|
||||||
|
sut.add(entityToAdd);
|
||||||
|
return entityToAdd;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,12 +18,12 @@ public class LinkUseCase {
|
||||||
private final LinkRepository linkRepository;
|
private final LinkRepository linkRepository;
|
||||||
private final CategoryRepository categoryRepository;
|
private final CategoryRepository categoryRepository;
|
||||||
private final TaggingUseCase taggingUseCase;
|
private final TaggingUseCase taggingUseCase;
|
||||||
private final LinkIdGenerator linkIdGenerator;
|
private final RandomLinkIdGenerator linkIdGenerator;
|
||||||
|
|
||||||
public LinkUseCase(LinkRepository linkRepository,
|
public LinkUseCase(LinkRepository linkRepository,
|
||||||
CategoryRepository categoryRepository,
|
CategoryRepository categoryRepository,
|
||||||
TaggingUseCase taggingUseCase,
|
TaggingUseCase taggingUseCase,
|
||||||
LinkIdGenerator linkIdGenerator) {
|
RandomLinkIdGenerator linkIdGenerator) {
|
||||||
this.linkRepository = linkRepository;
|
this.linkRepository = linkRepository;
|
||||||
this.categoryRepository = categoryRepository;
|
this.categoryRepository = categoryRepository;
|
||||||
this.taggingUseCase = taggingUseCase;
|
this.taggingUseCase = taggingUseCase;
|
||||||
|
|
|
@ -19,5 +19,4 @@ public class TaggingUseCase {
|
||||||
tagMatcherRepository.getTagMatchers().forEach(tagMatcher -> tagMatcher.ifMatches(url).addTo(result));
|
tagMatcherRepository.getTagMatchers().forEach(tagMatcher -> tagMatcher.ifMatches(url).addTo(result));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue