Skip to content

Commit 7e7bc1c

Browse files
committed
Add test documentation for parser tests
1 parent ec90b87 commit 7e7bc1c

20 files changed

+344
-50
lines changed

src/main/java/org/hydev/mcpm/client/arguments/ControllerFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public ListController listController() {
3939

4040
@Override
4141
public SearchPackagesController searchController() {
42-
return new SearchPackagesController(boundary.searchBoundary(), pageBoundary());
42+
return new SearchPackagesController(boundary.searchBoundary());
4343
}
4444

4545
@Override

src/main/java/org/hydev/mcpm/client/arguments/InteractorFactory.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.hydev.mcpm.client.arguments;
22

3-
import org.hydev.mcpm.client.DatabaseManager;
43
import org.hydev.mcpm.client.Downloader;
54
import org.hydev.mcpm.client.database.fetcher.DatabaseFetcher;
65
import org.hydev.mcpm.client.database.fetcher.DatabaseFetcherListener;
@@ -151,10 +150,9 @@ public InstallBoundary installBoundary() {
151150
var tracker = pluginTracker();
152151
var searcher = searchBoundary();
153152
var downloader = pluginDownloader();
154-
var manager = new DatabaseManager(tracker, searcher);
155153
var loader = loadBoundary();
156154

157-
return cache(InstallInteractor.class, () -> new InstallInteractor(downloader, manager, loader));
155+
return cache(InstallInteractor.class, () -> new InstallInteractor(downloader, loader, searcher, tracker));
158156
}
159157

160158
@Override

src/main/java/org/hydev/mcpm/client/arguments/ParserFactory.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
import org.hydev.mcpm.client.arguments.parsers.UninstallParser;
1515
import org.hydev.mcpm.client.arguments.parsers.UnloadParser;
1616
import org.hydev.mcpm.client.arguments.parsers.UpdateParser;
17+
import org.hydev.mcpm.client.display.presenters.InstallPresenter;
18+
import org.hydev.mcpm.client.display.presenters.SearchPresenter;
1719

1820
import java.util.List;
1921
import java.util.stream.Stream;
@@ -31,6 +33,9 @@ private ParserFactory() { }
3133
* @return Returns a list of argument parsers that work in any environment (Server & CLI).
3234
*/
3335
public static List<CommandParser> baseParsers(ControllerFactoryBoundary factory) {
36+
var searchPresenter = new SearchPresenter(factory.pageBoundary());
37+
var installPresenter = new InstallPresenter();
38+
3439
/*
3540
* Add general parsers to this list!
3641
* All versions of MCPM will have access to these parsers.
@@ -39,10 +44,10 @@ public static List<CommandParser> baseParsers(ControllerFactoryBoundary factory)
3944
return List.of(
4045
new ExportPluginsParser(factory.exportController()),
4146
new ListParser(factory.listController()),
42-
new SearchParser(factory.searchController()),
47+
new SearchParser(factory.searchController(), searchPresenter),
4348
new MirrorParser(factory.mirrorController()),
4449
new InfoParser(factory.infoController()),
45-
new InstallParser(factory.installController()),
50+
new InstallParser(factory.installController(), installPresenter),
4651
new RefreshParser(factory.refreshController()),
4752
new PageParser(factory.pageBoundary()),
4853
new UninstallParser(factory.uninstallController()),

src/test/java/org/hydev/mcpm/client/arguments/ArgsParserTest.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import static org.junit.jupiter.api.Assertions.assertThrows;
1515

1616
/**
17-
* Tests for ArgsParser.
17+
* Tests for the ArgsParser class (whether it can handle parsing basic commands, etc).
1818
*/
1919
class ArgsParserTest
2020
{
@@ -46,8 +46,11 @@ public void configure(Subparser parser)
4646
}
4747
}
4848

49+
/**
50+
* Tests whether the argument parser can parse basic strings for a test command.
51+
*/
4952
@Test
50-
void parse() throws ArgumentParserException
53+
void testParse() throws ArgumentParserException
5154
{
5255
Consumer<String> out = System.out::println;
5356
var p = new ArgsParser(List.of(new TestCommand()));
@@ -61,8 +64,11 @@ void parse() throws ArgumentParserException
6164
assertEquals(p.getRawSubparsers().size(), 1);
6265
}
6366

67+
/**
68+
* Tests whether the argument parser will fail on invalid invocations.
69+
*/
6470
@Test
65-
void fail()
71+
void testFail()
6672
{
6773
Consumer<String> out = System.out::println;
6874

src/test/java/org/hydev/mcpm/client/arguments/ExportParserTest.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,20 @@
2323
import static org.junit.jupiter.api.Assertions.assertThrows;
2424
import static org.junit.jupiter.api.Assertions.assertTrue;
2525

26+
/**
27+
* Contains tests for testing the export controller and parser objects.
28+
* E.g. whether strings commands will result in correct inputs, call the right methods in the boundary, etc.
29+
*/
2630
public class ExportParserTest {
2731
private MockExportBoundary exporter;
2832
private ExportPluginsController controller;
2933

3034
private ArgsParser args;
3135

36+
37+
/**
38+
* Initializes the various fields (controllers, etc.) before a test starts.
39+
*/
3240
@BeforeEach
3341
public void setup() {
3442
exporter = new MockExportBoundary();
@@ -37,6 +45,9 @@ public void setup() {
3745
args = new ArgsParser(List.of(parser));
3846
}
3947

48+
/**
49+
* Tests if export parser will correctly fail when no arguments are passed.
50+
*/
4051
@Test
4152
void testNoArguments() {
4253
var exception = assertThrows(
@@ -47,6 +58,9 @@ void testNoArguments() {
4758
assertEquals(exception.getMessage(), "too few arguments");
4859
}
4960

61+
/**
62+
* Tests whether an output stream is created when passed an outfile.
63+
*/
5064
@Test
5165
@Tag("IntegrationTest")
5266
void testWithOutfile() throws ArgumentParserException, IOException {
@@ -64,6 +78,9 @@ void testWithOutfile() throws ArgumentParserException, IOException {
6478
assertTrue(input.cache());
6579
}
6680

81+
/**
82+
* Tests whether no-cache is correctly set when the --cache option is provided.
83+
*/
6784
@Test
6885
@Tag("IntegrationTest")
6986
void testWithNoCache() throws ArgumentParserException, IOException {
@@ -80,6 +97,9 @@ void testWithNoCache() throws ArgumentParserException, IOException {
8097
assertFalse(input.cache());
8198
}
8299

100+
/**
101+
* Tests whether the controller will properly generate an input object when invoked.
102+
*/
83103
@Test
84104
void testControllerWithRegularStream() {
85105
ByteArrayOutputStream stream = new ByteArrayOutputStream();
@@ -93,6 +113,9 @@ void testControllerWithRegularStream() {
93113
assertTrue(input.cache());
94114
}
95115

116+
/**
117+
* Tests whether a controller will still fail gracefully when passed a default result.
118+
*/
96119
@Test
97120
void testControllerWithFailState() {
98121
exporter.setDefaultResult(ExportPluginsResult.State.FAILED_TO_FETCH_PLUGINS);

src/test/java/org/hydev/mcpm/client/arguments/InfoParserTest.java

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,20 @@
1818
import static org.junit.jupiter.api.Assertions.assertEquals;
1919
import static org.junit.jupiter.api.Assertions.assertThrows;
2020

21+
/**
22+
* Contains tests for testing the info controller and parser objects.
23+
* E.g. whether strings commands will result in correct inputs, call the right methods in the boundary, etc.
24+
*/
2125
public class InfoParserTest {
2226
private AtomicReference<String> output;
2327
private Consumer<String> log;
24-
private MockPluginTracker tracker;
2528
private InfoController controller;
2629

2730
private ArgsParser args;
2831

32+
/**
33+
* Initializes the various fields (controllers, etc.) before a test starts.
34+
*/
2935
@BeforeEach
3036
public void setup() {
3137
output = new AtomicReference<>("");
@@ -43,12 +49,16 @@ public void setup() {
4349
PluginMockFactory.meta("Plugin Plus", "v1.2", "def")
4450
);
4551

46-
tracker = new MockPluginTracker(plugins);
52+
var tracker = new MockPluginTracker(plugins);
4753
controller = new InfoController(tracker);
4854
var parser = new InfoParser(controller);
4955
args = new ArgsParser(List.of(parser));
5056
}
5157

58+
59+
/**
60+
* Tests if info parser will correctly fail when no arguments are passed.
61+
*/
5262
@Test
5363
void testNoArguments() {
5464
var exception = assertThrows(
@@ -60,9 +70,12 @@ void testNoArguments() {
6070
}
6171

6272
// Here we'll be interacting with log strings more since info only writes to log.
63-
// Not sure how we can do better than this, we're gonna lock in InfoController into a format.
73+
// Not sure how we can do better than this, we will lock in InfoController into a format.
6474
// This would be moved to presenter when info is moved to presenter.
6575

76+
/**
77+
* Tests whether the info parser will present the correct message when passed a plugin that does not exist.
78+
*/
6679
@Test
6780
void testPluginAbsent() throws ArgumentParserException {
6881
args.parse(new String[] { "info", "what" }, log);
@@ -71,6 +84,9 @@ void testPluginAbsent() throws ArgumentParserException {
7184
assertEquals(ColorLogger.trimNoColor(output.get()), expected);
7285
}
7386

87+
/**
88+
* Tests whether the info parser will print the correct plugin details for a small plugin.
89+
*/
7490
@Test
7591
void testPluginDetails() throws ArgumentParserException {
7692
args.parse(new String[] { "info", "My Plugin" }, log);
@@ -85,6 +101,9 @@ void testPluginDetails() throws ArgumentParserException {
85101
assertEquals(ColorLogger.trimNoColor(output.get()), expected);
86102
}
87103

104+
/**
105+
* Tests whether the info parser will present the correct message when pass a plugin with non-null list/map values.
106+
*/
88107
@Test
89108
void testPluginDetailsExtended() throws ArgumentParserException {
90109
args.parse(new String[] { "info", "My Plugin2" }, log);
@@ -96,6 +115,25 @@ void testPluginDetailsExtended() throws ArgumentParserException {
96115
> Version : v1.1
97116
> Description : bc
98117
> Authors : Hello world
118+
> Commands : comm
119+
""".trim() + "\n";
120+
assertEquals(ColorLogger.trimNoColor(output.get()), expected);
121+
}
122+
123+
/**
124+
* Tests whether the info parser will present the correct message when invoked via controller.
125+
*/
126+
@Test
127+
void testPluginDetailsDirectly() {
128+
controller.info("My Plugin2", log);
129+
130+
var expected = """
131+
Plugin Info:
132+
> Name : My Plugin2
133+
> Main : org.My Plugin2
134+
> Version : v1.1
135+
> Description : bc
136+
> Authors : Hello world
99137
> Commands : comm
100138
""".trim() + "\n";
101139
assertEquals(ColorLogger.trimNoColor(output.get()), expected);

src/test/java/org/hydev/mcpm/client/arguments/InstallParserTest.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ public class InstallParserTest {
2525

2626
private ArgsParser args;
2727

28+
/**
29+
* Initializes the various fields (controllers, etc.) before a test starts.
30+
*/
2831
@BeforeEach
2932
public void setup() {
3033
installer = new MockInstallBoundary();
@@ -41,6 +44,9 @@ void assertAcceptable(InstallInput input, String name, boolean load) {
4144
assertTrue(input.isManuallyInstalled());
4245
}
4346

47+
/**
48+
* Tests if install parser will correctly fail when no arguments are passed.
49+
*/
4450
@Test
4551
void testNoArguments() {
4652
var exception = assertThrows(
@@ -51,6 +57,9 @@ void testNoArguments() {
5157
assertEquals(exception.getMessage(), "too few arguments");
5258
}
5359

60+
/**
61+
* Tests whether the `install` parser will correctly invoke the boundary with one name.
62+
*/
5463
@Test
5564
void testInstallSingleName() throws ArgumentParserException {
5665

@@ -61,6 +70,9 @@ void testInstallSingleName() throws ArgumentParserException {
6170
assertAcceptable(inputs.get(0), "JedCore", true);
6271
}
6372

73+
/**
74+
* Tests whether the `install` parser will correctly set the noLoad parameter when the --no-load option is provided.
75+
*/
6476
@Test
6577
void testInstallNoLoad() throws ArgumentParserException {
6678
args.parse(new String[] { "install", "ABC", "--no-load" }, log -> {});
@@ -70,7 +82,9 @@ void testInstallNoLoad() throws ArgumentParserException {
7082
assertAcceptable(inputs.get(0), "ABC", false);
7183
}
7284

73-
85+
/**
86+
* Tests whether the `install` controller will correctly invoke the boundary (with different package types).
87+
*/
7488
@Test
7589
void testInstallController() {
7690
controller.install("MyPlugin", SearchPackagesType.BY_COMMAND, false);

0 commit comments

Comments
 (0)