1
1
package fr .zcraft .quartzlib .components .commands ;
2
2
3
+ import fr .zcraft .quartzlib .components .commands .exceptions .CommandException ;
3
4
import org .junit .jupiter .api .Assertions ;
4
5
import org .junit .jupiter .api .BeforeEach ;
5
6
import org .junit .jupiter .api .Test ;
@@ -42,7 +43,7 @@ public void list () {}
42
43
Assertions .assertArrayEquals (new String [] {"add" , "delete" }, commandNames );
43
44
}
44
45
45
- @ Test public void canRunBasicSubcommands () {
46
+ @ Test public void canRunBasicSubcommands () throws CommandException {
46
47
final boolean [] ran = {false , false , false };
47
48
48
49
class FooCommand {
@@ -56,7 +57,7 @@ class FooCommand {
56
57
Assertions .assertArrayEquals (new boolean [] { false , true , false }, ran );
57
58
}
58
59
59
- @ Test public void canReceiveStringArguments () {
60
+ @ Test public void canReceiveStringArguments () throws CommandException {
60
61
final String [] argValue = {"" };
61
62
62
63
class FooCommand {
@@ -68,7 +69,7 @@ class FooCommand {
68
69
Assertions .assertArrayEquals (new String [] { "pomf" }, argValue );
69
70
}
70
71
71
- @ Test public void canReceiveParsedArguments () {
72
+ @ Test public void canReceiveParsedArguments () throws CommandException {
72
73
final int [] argValue = {0 };
73
74
74
75
class FooCommand {
@@ -79,4 +80,19 @@ class FooCommand {
79
80
commands .run ("foo" , "add" , "42" );
80
81
Assertions .assertArrayEquals (new int [] { 42 }, argValue );
81
82
}
83
+
84
+ enum FooEnum { FOO , BAR }
85
+ @ Test public void canReceiveEnumArguments () throws CommandException {
86
+ final FooEnum [] argValue = {null };
87
+
88
+ class FooCommand {
89
+ public void add (FooEnum arg ) { argValue [0 ] = arg ; }
90
+ }
91
+
92
+ commands .registerCommand ("foo" , FooCommand .class , () -> new FooCommand ());
93
+ commands .run ("foo" , "add" , "foo" );
94
+ Assertions .assertArrayEquals (new FooEnum [] { FooEnum .FOO }, argValue );
95
+ commands .run ("foo" , "add" , "bar" );
96
+ Assertions .assertArrayEquals (new FooEnum [] { FooEnum .BAR }, argValue );
97
+ }
82
98
}
0 commit comments