99import org .junit .jupiter .api .DisplayName ;
1010import org .junit .jupiter .api .Test ;
1111import org .junit .jupiter .api .extension .ExtendWith ;
12+ import org .junit .jupiter .params .ParameterizedTest ;
13+ import org .junit .jupiter .params .provider .ValueSource ;
1214import org .mockito .InjectMocks ;
1315import org .mockito .Mock ;
1416import org .mockito .junit .jupiter .MockitoExtension ;
1517import org .springframework .web .client .RestTemplate ;
1618
1719import java .util .Optional ;
1820
19- import static org .junit .jupiter .api .Assertions .assertThrows ;
21+ import static org .junit .jupiter .api .Assertions .* ;
2022import static org .mockito .ArgumentMatchers .eq ;
2123import static org .mockito .Mockito .verify ;
2224import static org .mockito .Mockito .when ;
@@ -94,4 +96,52 @@ void handlePaymentCallback_Expired() {
9496
9597 verify (paymentService ).handlePaymentStatusUpdate (eq (1L ), eq (PaymentStatus .EXPIRED ));
9698 }
99+
100+ @ ParameterizedTest
101+ @ DisplayName ("Validate Mobile Pay Reference Format" )
102+ @ ValueSource (strings = {
103+ "HotelHunger-order-1234-10050" , // Typical case
104+ "Commercify-order-9999-12345" , // Different system name
105+ "A1-order-1-100" , // Minimum acceptable length
106+ "VeryLongSystemName-order-999999-1000000" // Longer reference
107+ })
108+ void testValidMobilePayReferences (String reference ) {
109+ assertTrue (reference .matches ("^[a-zA-Z0-9-]{8,50}$" ),
110+ "Reference should be valid: " + reference );
111+ }
112+
113+ @ ParameterizedTest
114+ @ DisplayName ("Invalidate Incorrect Mobile Pay Reference Format" )
115+ @ ValueSource (strings = {
116+ "HotelHunger_order-1234-10050" , // Contains underscore
117+ "System!order-1234-10050" , // Contains special character
118+ "ab" , // Too short
119+ "ThisIsAVeryLongReferenceStringThatExceedsTheMaximumAllowedLengthOfFiftyCharacters" // Too long
120+ })
121+ void testInvalidMobilePayReferences (String reference ) {
122+ assertFalse (reference .matches ("^[a-zA-Z0-9-]{8,50}$" ),
123+ "Reference should be invalid: " + reference );
124+ }
125+
126+ @ Test
127+ @ DisplayName ("Validate Reference Generation Components" )
128+ void testMobilePayReferenceGeneration () {
129+ // Assuming you have a method to generate the reference
130+ // This is a placeholder - adjust based on your actual reference generation method
131+ PaymentEntity testPayment = PaymentEntity .builder ()
132+ .id (1234L )
133+ .build ();
134+
135+ String generatedReference = "Commercify-order-" + testPayment .getId () + "-10050" ;
136+
137+ // Validate reference format
138+ assertTrue (generatedReference .matches ("^[a-zA-Z0-9-]{8,50}$" ),
139+ "Generated reference should match the required format" );
140+
141+ // Additional checks
142+ assertTrue (generatedReference .startsWith ("Commercify-order-" ),
143+ "Reference should start with system name and 'order-'" );
144+ assertTrue (generatedReference .contains ("-10050" ),
145+ "Reference should contain the total amount" );
146+ }
97147}
0 commit comments