@@ -299,6 +299,86 @@ void addingANewDependencyMakesTypesAvailable() {
299
299
assertThat (fullyQualifiedName ).isEqualTo ("javax.validation.constraints.Email" );
300
300
}
301
301
302
+ @ Test
303
+ @ DisplayName ("after adding an dependency the type should resolved" )
304
+ void test1 () {
305
+ ProjectContext projectContext = TestProjectContext .buildProjectContext ()
306
+ .withBuildFileHavingDependencies ("javax.validation:validation-api:2.0.1.Final" )
307
+ .withJavaSource ("src/main/java" , "public class Fred { private int age;}" )
308
+ .build ();
309
+
310
+ JavaSource javaSource = projectContext .getProjectJavaSources ().list ().get (0 );
311
+ javaSource .getTypes ().get (0 ).getMembers ().get (0 ).addAnnotation ("@Max(8)" , "javax.validation.constraints.Max" );
312
+ System .out .println (javaSource .print ());
313
+ Statement statement = ((OpenRewriteJavaSource ) javaSource ).getSourceFile ().getClasses ().get (0 ).getBody ().getStatements ().get (0 );
314
+ J .VariableDeclarations vd = (J .VariableDeclarations ) statement ;
315
+ assertThat (((JavaType .Class )vd .getLeadingAnnotations ().get (0 ).getType ()).getFullyQualifiedName ()).isEqualTo ("javax.validation.constraints.Max" );
316
+ }
317
+
318
+ @ Test
319
+ @ DisplayName ("after adding an dependency the type should resolved" )
320
+ void test2 () {
321
+ ProjectContext projectContext = TestProjectContext .buildProjectContext ()
322
+ // .withBuildFileHavingDependencies("javax.validation:validation-api:2.0.1.Final")
323
+ .withJavaSource ("src/main/java" , "public class Fred { private int age;}" )
324
+ .build ();
325
+
326
+ projectContext .getApplicationModules ().getRootModule ().getBuildFile ().addDependency (Dependency .fromCoordinates ("javax.validation:validation-api:2.0.1.Final" ));
327
+
328
+ JavaSource javaSource = projectContext .getProjectJavaSources ().list ().get (0 );
329
+ javaSource .getTypes ().get (0 ).getMembers ().get (0 ).addAnnotation ("@Max(8)" , "javax.validation.constraints.Max" );
330
+ System .out .println (javaSource .print ());
331
+ Statement statement = ((OpenRewriteJavaSource ) javaSource ).getSourceFile ().getClasses ().get (0 ).getBody ().getStatements ().get (0 );
332
+ J .VariableDeclarations vd = (J .VariableDeclarations ) statement ;
333
+ JavaType type = vd .getLeadingAnnotations ().get (0 ).getType ();
334
+ assertThat (type ).isInstanceOf (JavaType .Class .class );
335
+ assertThat (((JavaType .Class ) type ).getFullyQualifiedName ()).isEqualTo ("javax.validation.constraints.Max" );
336
+ }
337
+
338
+ @ Test
339
+ @ DisplayName ("compare differences" )
340
+ void classpathFromJavaSourceSetShouldBeEqual () {
341
+ ProjectContext projectContextWithDep = TestProjectContext .buildProjectContext ()
342
+ .withBuildFileHavingDependencies ("javax.validation:validation-api:2.0.1.Final" )
343
+ .withJavaSource ("src/main/java" , "public class Fred { private int age;}" )
344
+ .build ();
345
+
346
+ ProjectContext projectContextNoDep = TestProjectContext .buildProjectContext ()
347
+ // .withBuildFileHavingDependencies("javax.validation:validation-api:2.0.1.Final")
348
+ .withJavaSource ("src/main/java" , "public class Fred { private int age;}" )
349
+ .build ();
350
+
351
+ projectContextNoDep .getApplicationModules ().getRootModule ().getBuildFile ().addDependency (Dependency .fromCoordinates ("javax.validation:validation-api:2.0.1.Final" ));
352
+
353
+ List <String > noDepClasspath = ((OpenRewriteJavaSource ) projectContextNoDep .getProjectJavaSources ().list ().get (0 )).getSourceFile ().getMarkers ().findFirst (JavaSourceSet .class ).get ().getClasspath ().stream ().map (JavaType .FullyQualified ::getFullyQualifiedName ).toList ();
354
+ List <String > withDepClasspath = ((OpenRewriteJavaSource ) projectContextWithDep .getProjectJavaSources ().list ().get (0 )).getSourceFile ().getMarkers ().findFirst (JavaSourceSet .class ).get ().getClasspath ().stream ().map (JavaType .FullyQualified ::getFullyQualifiedName ).toList ();
355
+
356
+ assertThat (noDepClasspath ).isEqualTo (withDepClasspath );
357
+ }
358
+
359
+ @ Test
360
+ @ DisplayName ("compare differences" )
361
+ void classpathFromJClasspathMarkerShouldBeEqual () {
362
+ ProjectContext projectContextWithDep = TestProjectContext .buildProjectContext ()
363
+ .withBuildFileHavingDependencies ("javax.validation:validation-api:2.0.1.Final" )
364
+ .withJavaSource ("src/main/java" , "public class Fred { private int age;}" )
365
+ .build ();
366
+
367
+ ProjectContext projectContextNoDep = TestProjectContext .buildProjectContext ()
368
+ // .withBuildFileHavingDependencies("javax.validation:validation-api:2.0.1.Final")
369
+ .withJavaSource ("src/main/java" , "public class Fred { private int age;}" )
370
+ .build ();
371
+
372
+ projectContextNoDep .getApplicationModules ().getRootModule ().getBuildFile ().addDependency (Dependency .fromCoordinates ("javax.validation:validation-api:2.0.1.Final" ));
373
+
374
+ List <String > noDepClasspath = ((OpenRewriteJavaSource ) projectContextNoDep .getProjectJavaSources ().list ().get (0 )).getSourceFile ().getMarkers ().findFirst (ClasspathDependencies .class ).get ().getDependencies ().stream ().map (Path ::toString ).toList ();
375
+ List <String > withDepClasspath = ((OpenRewriteJavaSource ) projectContextWithDep .getProjectJavaSources ().list ().get (0 )).getSourceFile ().getMarkers ().findFirst (ClasspathDependencies .class ).get ().getDependencies ().stream ().map (Path ::toString ).toList ();
376
+
377
+ assertThat (noDepClasspath ).isEqualTo (withDepClasspath );
378
+ }
379
+
380
+
381
+
302
382
private ProjectContext createProjectContext () {
303
383
return TestProjectContext
304
384
.buildProjectContext (beanFactory )
0 commit comments