You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
1.2 KiB

package edu.homework.crawler.command;
import edu.homework.crawler.exception.CommandException;
import org.junit.jupiter.api.Test;
import java.util.List;
import java.util.Map;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
class CommandRegistryTest {
@Test
void tokenizesQuotedOutputPath() throws Exception {
CommandRegistry registry = new CommandRegistry();
List<String> tokens = registry.tokenize("crawl --site all --out \"data/my news.json\"");
assertEquals(List.of("crawl", "--site", "all", "--out", "data/my news.json"), tokens);
}
@Test
void parsesOptionsAsKeyValuePairs() throws Exception {
CommandRegistry registry = new CommandRegistry();
Map<String, String> options = registry.parseOptions(new String[]{"--site", "hnu", "--limit", "5"});
assertEquals("hnu", options.get("site"));
assertEquals("5", options.get("limit"));
}
@Test
void rejectsMissingOptionValue() {
CommandRegistry registry = new CommandRegistry();
assertThrows(CommandException.class, () -> registry.parseOptions(new String[]{"--site"}));
}
}