@@ -122,28 +122,12 @@ void nullComparisonTest() {
122122
123123 private GetSparkVersionsResponse testGetSparkVersionsWithSparkVersion () {
124124 Collection <SparkVersion > versions = new ArrayList <>();
125- // Mock realistic Databricks Runtime versions based on actual API response format
126- versions .add (
127- new SparkVersion ()
128- .setName ("12.2 LTS (includes Apache Spark 3.3.2, Scala 2.12)" )
129- .setKey ("12.2.x-scala2.12" ));
125+ // Mock realistic Databricks Runtime version based on actual API response format
126+ // The key point: version name contains more than just "Apache Spark X.Y.Z"
130127 versions .add (
131128 new SparkVersion ()
132129 .setName ("13.3 LTS (includes Apache Spark 3.4.1, Scala 2.12)" )
133130 .setKey ("13.3.x-scala2.12" ));
134- versions .add (
135- new SparkVersion ()
136- .setName ("14.3 LTS (includes Apache Spark 3.5.0, Scala 2.12)" )
137- .setKey ("14.3.x-scala2.12" ));
138- versions .add (
139- new SparkVersion ()
140- .setName ("14.2 ML (includes Apache Spark 3.5.0, Scala 2.12)" )
141- .setKey ("14.2.x-cpu-ml-scala2.12" ));
142- // Add another version with same Spark version to create multiple matches
143- versions .add (
144- new SparkVersion ()
145- .setName ("14.1 (includes Apache Spark 3.5.0, Scala 2.12)" )
146- .setKey ("14.1.x-scala2.12" ));
147131 return new GetSparkVersionsResponse ().setVersions (versions );
148132 }
149133
@@ -152,65 +136,12 @@ void sparkVersionWithSparkVersionParameter() {
152136 ClustersExt clustersExt = new ClustersExt (clustersMock );
153137 Mockito .doReturn (testGetSparkVersionsWithSparkVersion ()).when (clustersMock ).sparkVersions ();
154138
155- // Test exact spark version match
139+ // Test that sparkVersion parameter works with realistic API response format
140+ // This tests the contains() fix - the version name is "13.3 LTS (includes Apache Spark 3.4.1, Scala 2.12)"
141+ // not just "Apache Spark 3.4.1", so equals() would fail but contains() works
156142 String sparkVersion =
157143 clustersExt .selectSparkVersion (new SparkVersionSelector ().withSparkVersion ("3.4.1" ));
158144 assertEquals ("13.3.x-scala2.12" , sparkVersion );
159145 }
160146
161- @ Test
162- void sparkVersionWithSparkVersionParameterMultipleMatches () {
163- ClustersExt clustersExt = new ClustersExt (clustersMock );
164- Mockito .doReturn (testGetSparkVersionsWithSparkVersion ()).when (clustersMock ).sparkVersions ();
165-
166- // Test spark version with multiple matches - should return latest when latest=true is
167- // explicitly set
168- String sparkVersion =
169- clustersExt .selectSparkVersion (
170- new SparkVersionSelector ().withSparkVersion ("3.5.0" ).withLatest ());
171- // Should return the highest version (14.3.x) when latest=true and multiple 3.5.0 versions match
172- assertEquals ("14.3.x-scala2.12" , sparkVersion );
173- }
174-
175- @ Test
176- void sparkVersionWithSparkVersionParameterAndML () {
177- ClustersExt clustersExt = new ClustersExt (clustersMock );
178- Mockito .doReturn (testGetSparkVersionsWithSparkVersion ()).when (clustersMock ).sparkVersions ();
179-
180- // Test spark version combined with ML requirement
181- String sparkVersion =
182- clustersExt .selectSparkVersion (
183- new SparkVersionSelector ().withSparkVersion ("3.5.0" ).withML ());
184- assertEquals ("14.2.x-cpu-ml-scala2.12" , sparkVersion );
185- }
186-
187- @ Test
188- void sparkVersionWithSparkVersionParameterNoMatch () {
189- ClustersExt clustersExt = new ClustersExt (clustersMock );
190- Mockito .doReturn (testGetSparkVersionsWithSparkVersion ()).when (clustersMock ).sparkVersions ();
191-
192- // Test spark version that doesn't exist
193- assertThrows (
194- IllegalArgumentException .class ,
195- () -> {
196- clustersExt .selectSparkVersion (new SparkVersionSelector ().withSparkVersion ("2.4.5" ));
197- });
198- }
199-
200- @ Test
201- void sparkVersionWithSparkVersionParameterMultipleMatchesLatestFalse () {
202- ClustersExt clustersExt = new ClustersExt (clustersMock );
203- Mockito .doReturn (testGetSparkVersionsWithSparkVersion ()).when (clustersMock ).sparkVersions ();
204-
205- // Test spark version with multiple matches and latest=false (default) - should throw exception
206- SparkVersionSelector selector = new SparkVersionSelector ().withSparkVersion ("3.5.0" );
207- // latest defaults to false, so multiple matches should throw an exception
208-
209- assertThrows (
210- IllegalArgumentException .class ,
211- () -> {
212- clustersExt .selectSparkVersion (selector );
213- },
214- "Expected exception when multiple versions match with latest=false (default)" );
215- }
216147}
0 commit comments