1+ package fr .traqueur .commands .annotations ;
2+
3+ import fr .traqueur .commands .annotations .commands .PrimitiveTypesTestCommands ;
4+ import fr .traqueur .commands .api .arguments .Arguments ;
5+ import fr .traqueur .commands .api .models .Command ;
6+ import fr .traqueur .commands .test .mocks .MockCommandManager ;
7+ import fr .traqueur .commands .test .mocks .MockPlatform ;
8+ import fr .traqueur .commands .test .mocks .MockSender ;
9+ import org .junit .jupiter .api .BeforeEach ;
10+ import org .junit .jupiter .api .DisplayName ;
11+ import org .junit .jupiter .api .Test ;
12+
13+ import static org .junit .jupiter .api .Assertions .*;
14+
15+ /**
16+ * Integration tests for primitive types support.
17+ * These tests verify that commands with primitive type arguments can be:
18+ * 1. Parsed correctly
19+ * 2. Stored in Arguments
20+ * 3. Retrieved from Arguments
21+ * 4. Passed to method invocation via reflection
22+ */
23+ @ DisplayName ("Primitive Types Integration" )
24+ class PrimitiveTypesIntegrationTest {
25+
26+ private MockPlatform platform ;
27+ private MockCommandManager manager ;
28+ private PrimitiveTypesTestCommands commands ;
29+
30+ // Mock sender implementation for testing
31+ private static class TestSender implements MockSender {
32+ @ Override
33+ public void sendMessage (String message ) {
34+ // Do nothing
35+ }
36+
37+ @ Override
38+ public boolean hasPermission (String permission ) {
39+ return true ;
40+ }
41+ }
42+
43+ @ BeforeEach
44+ void setUp () {
45+ platform = new MockPlatform ();
46+ manager = new MockCommandManager (platform );
47+ AnnotationCommandProcessor <Object , MockSender > processor = new AnnotationCommandProcessor <>(manager );
48+ commands = new PrimitiveTypesTestCommands ();
49+ processor .register (commands );
50+ }
51+
52+ @ Test
53+ @ DisplayName ("should execute command with primitive int" )
54+ void shouldExecuteCommandWithPrimitiveInt () throws Exception {
55+ Command <Object , MockSender > cmd = platform .getCommand ("primitiveint" );
56+ assertNotNull (cmd );
57+
58+ // Parse arguments
59+ Arguments args = manager .parse (cmd , new String []{"42" });
60+ assertNotNull (args );
61+ assertEquals (1 , args .size ());
62+
63+ // Verify the argument was parsed and stored correctly
64+ Integer value = args .get ("value" );
65+ assertEquals (42 , value );
66+
67+ // Execute the command
68+ TestSender sender = new TestSender ();
69+ cmd .execute (sender , args );
70+
71+ // Verify the method was called
72+ assertEquals (1 , commands .executedCommands .size ());
73+ assertEquals ("primitiveint" , commands .executedCommands .getFirst ());
74+
75+ // Verify arguments were passed correctly
76+ Object [] invokeArgs = commands .executedArgs .getFirst ();
77+ assertEquals (2 , invokeArgs .length );
78+ assertEquals (sender , invokeArgs [0 ]);
79+ assertEquals (42 , invokeArgs [1 ]);
80+ assertInstanceOf (Integer .class , invokeArgs [1 ]);
81+ }
82+
83+ @ Test
84+ @ DisplayName ("should execute command with primitive boolean" )
85+ void shouldExecuteCommandWithPrimitiveBoolean () throws Exception {
86+ Command <Object , MockSender > cmd = platform .getCommand ("primitivebool" );
87+ assertNotNull (cmd );
88+
89+ // Parse arguments
90+ Arguments args = manager .parse (cmd , new String []{"true" });
91+ assertNotNull (args );
92+
93+ // Verify the argument was parsed and stored correctly
94+ Boolean enabled = args .get ("enabled" );
95+ assertTrue (enabled );
96+
97+ // Execute the command
98+ TestSender sender = new TestSender ();
99+ cmd .execute (sender , args );
100+
101+ // Verify the method was called correctly
102+ assertEquals (1 , commands .executedCommands .size ());
103+ Object [] invokeArgs = commands .executedArgs .getFirst ();
104+ assertEquals (true , invokeArgs [1 ]);
105+ assertInstanceOf (Boolean .class , invokeArgs [1 ]);
106+ }
107+
108+ @ Test
109+ @ DisplayName ("should execute command with primitive double" )
110+ void shouldExecuteCommandWithPrimitiveDouble () throws Exception {
111+ Command <Object , MockSender > cmd = platform .getCommand ("primitivedouble" );
112+ assertNotNull (cmd );
113+
114+ // Parse arguments
115+ Arguments args = manager .parse (cmd , new String []{"3.14" });
116+ assertNotNull (args );
117+
118+ // Verify the argument was parsed and stored correctly
119+ Double value = args .get ("value" );
120+ assertEquals (3.14 , value , 0.001 );
121+
122+ // Execute the command
123+ TestSender sender = new TestSender ();
124+ cmd .execute (sender , args );
125+
126+ // Verify the method was called correctly
127+ assertEquals (1 , commands .executedCommands .size ());
128+ Object [] invokeArgs = commands .executedArgs .getFirst ();
129+ assertInstanceOf (Double .class , invokeArgs [1 ]);
130+ assertEquals (3.14 , (Double ) invokeArgs [1 ], 0.001 );
131+ }
132+
133+ @ Test
134+ @ DisplayName ("should execute command with primitive long" )
135+ void shouldExecuteCommandWithPrimitiveLong () throws Exception {
136+ Command <Object , MockSender > cmd = platform .getCommand ("primitivelong" );
137+ assertNotNull (cmd );
138+
139+ // Parse arguments
140+ Arguments args = manager .parse (cmd , new String []{"9223372036854775807" });
141+ assertNotNull (args );
142+
143+ // Verify the argument was parsed and stored correctly
144+ Long value = args .get ("value" );
145+ assertEquals (9223372036854775807L , value );
146+
147+ // Execute the command
148+ TestSender sender = new TestSender ();
149+ cmd .execute (sender , args );
150+
151+ // Verify the method was called correctly
152+ assertEquals (1 , commands .executedCommands .size ());
153+ Object [] invokeArgs = commands .executedArgs .getFirst ();
154+ assertEquals (9223372036854775807L , invokeArgs [1 ]);
155+ assertInstanceOf (Long .class , invokeArgs [1 ]);
156+ }
157+
158+ @ Test
159+ @ DisplayName ("should execute command with mixed primitive types" )
160+ void shouldExecuteCommandWithMixedPrimitives () throws Exception {
161+ Command <Object , MockSender > cmd = platform .getCommand ("mixedprimitives" );
162+ assertNotNull (cmd );
163+
164+ // Parse arguments
165+ Arguments args = manager .parse (cmd , new String []{"10" , "true" , "2.5" });
166+ assertNotNull (args );
167+ assertEquals (3 , args .size ());
168+
169+ // Verify all arguments were parsed and stored correctly
170+ Integer count = args .get ("count" );
171+ Boolean enabled = args .get ("enabled" );
172+ Double ratio = args .get ("ratio" );
173+
174+ assertEquals (10 , count );
175+ assertTrue (enabled );
176+ assertEquals (2.5 , ratio , 0.001 );
177+
178+ // Execute the command
179+ TestSender sender = new TestSender ();
180+ cmd .execute (sender , args );
181+
182+ // Verify the method was called correctly with all arguments
183+ assertEquals (1 , commands .executedCommands .size ());
184+ assertEquals ("mixedprimitives" , commands .executedCommands .getFirst ());
185+
186+ Object [] invokeArgs = commands .executedArgs .getFirst ();
187+ assertEquals (4 , invokeArgs .length );
188+ assertEquals (sender , invokeArgs [0 ]);
189+ assertEquals (10 , invokeArgs [1 ]);
190+ assertEquals (true , invokeArgs [2 ]);
191+ assertEquals (2.5 , (Double ) invokeArgs [3 ], 0.001 );
192+ }
193+
194+ @ Test
195+ @ DisplayName ("should handle negative primitive int" )
196+ void shouldHandleNegativePrimitiveInt () throws Exception {
197+ Command <Object , MockSender > cmd = platform .getCommand ("primitiveint" );
198+ Arguments args = manager .parse (cmd , new String []{"-42" });
199+
200+ Integer value = args .get ("value" );
201+ assertEquals (-42 , value );
202+
203+ TestSender sender = new TestSender ();
204+ cmd .execute (sender , args );
205+
206+ Object [] invokeArgs = commands .executedArgs .getFirst ();
207+ assertEquals (-42 , invokeArgs [1 ]);
208+ }
209+
210+ @ Test
211+ @ DisplayName ("should handle false boolean primitive" )
212+ void shouldHandleFalseBooleanPrimitive () throws Exception {
213+ Command <Object , MockSender > cmd = platform .getCommand ("primitivebool" );
214+ Arguments args = manager .parse (cmd , new String []{"false" });
215+
216+ Boolean enabled = args .get ("enabled" );
217+ assertFalse (enabled );
218+
219+ TestSender sender = new TestSender ();
220+ cmd .execute (sender , args );
221+
222+ Object [] invokeArgs = commands .executedArgs .getFirst ();
223+ assertEquals (false , invokeArgs [1 ]);
224+ }
225+ }
0 commit comments