11package com .thealgorithms .strings ;
22
33import java .util .stream .Stream ;
4+
45import org .junit .jupiter .api .Assertions ;
56import org .junit .jupiter .params .ParameterizedTest ;
67import org .junit .jupiter .params .provider .MethodSource ;
78
8- public class LongestCommonSubstringTest {
9+ public final class LongestCommonSubstringTest {
910
1011 private record TestData (String a , String b , String expected ) {
1112 }
1213
13- private static Stream <TestData > provideTestCases () {
14+ // JUnit 5 matches this automatically because it has the same name as the test method
15+ private static Stream <TestData > testLongestCommonSubstring () {
1416 return Stream .of (
1517 new TestData (null , "abc" , "" ),
1618 new TestData ("abc" , null , "" ),
@@ -20,14 +22,14 @@ private static Stream<TestData> provideTestCases() {
2022 new TestData ("abc" , "abc" , "abc" ),
2123 new TestData ("abc" , "xyz" , "" ),
2224 new TestData ("abcdef" , "cdefgh" , "cdef" ),
23- new TestData ("a" , "a" , "a" )
25+ new TestData ("a" , "a" , "a" ),
26+ new TestData ("abcXdef" , "abcYdef" , "abc" )
2427 );
2528 }
2629
2730 @ ParameterizedTest
28- @ MethodSource ( "provideTestCases" )
31+ @ MethodSource // No string argument needed here anymore
2932 void testLongestCommonSubstring (TestData testData ) {
30- Assertions .assertEquals (testData .expected (),
31- LongestCommonSubstring .longestCommonSubstring (testData .a (), testData .b ()));
33+ Assertions .assertEquals (testData .expected (), LongestCommonSubstring .longestCommonSubstring (testData .a (), testData .b ()));
3234 }
3335}
0 commit comments