@ -1,5 +1,5 @@
/ *
/ *
* Copyright 20 20- 2020 the original author or authors .
* Copyright 20 12- 2021 the original author or authors .
*
*
* Licensed under the Apache License , Version 2.0 ( the "License" ) ;
* Licensed under the Apache License , Version 2.0 ( the "License" ) ;
* you may not use this file except in compliance with the License .
* you may not use this file except in compliance with the License .
@ -32,6 +32,7 @@ import org.springframework.boot.build.bom.bomr.version.DependencyVersion;
import org.springframework.util.FileCopyUtils ;
import org.springframework.util.FileCopyUtils ;
import static org.assertj.core.api.Assertions.assertThat ;
import static org.assertj.core.api.Assertions.assertThat ;
import static org.assertj.core.api.Assertions.entry ;
/ * *
/ * *
* Tests for { @link UpgradeApplicator } .
* Tests for { @link UpgradeApplicator } .
@ -47,13 +48,14 @@ class UpgradeApplicatorTests {
void whenUpgradeIsAppliedToLibraryWithVersionThenBomIsUpdated ( ) throws IOException {
void whenUpgradeIsAppliedToLibraryWithVersionThenBomIsUpdated ( ) throws IOException {
File bom = new File ( this . temp , "bom.gradle" ) ;
File bom = new File ( this . temp , "bom.gradle" ) ;
FileCopyUtils . copy ( new File ( "src/test/resources/bom.gradle" ) , bom ) ;
FileCopyUtils . copy ( new File ( "src/test/resources/bom.gradle" ) , bom ) ;
String originalContents = new String ( Files . readAllBytes ( bom . toPath ( ) ) , StandardCharsets . UTF_8 ) ;
File gradleProperties = new File ( this . temp , "gradle.properties" ) ;
File gradleProperties = new File ( this . temp , "gradle.properties" ) ;
FileCopyUtils . copy ( new File ( "src/test/resources/gradle.properties" ) , gradleProperties ) ;
FileCopyUtils . copy ( new File ( "src/test/resources/gradle.properties" ) , gradleProperties ) ;
new UpgradeApplicator ( bom . toPath ( ) , gradleProperties . toPath ( ) )
new UpgradeApplicator ( bom . toPath ( ) , gradleProperties . toPath ( ) )
. apply ( new Upgrade ( new Library ( "ActiveMQ" , DependencyVersion . parse ( "5.15.11" ) , null , null ) ,
. apply ( new Upgrade ( new Library ( "ActiveMQ" , DependencyVersion . parse ( "5.15.11" ) , null , null ) ,
DependencyVersion . parse ( "5.16" ) ) ) ;
DependencyVersion . parse ( "5.16" ) ) ) ;
String bomContents = new String ( Files . readAllBytes ( bom . toPath ( ) ) , StandardCharsets . UTF_8 ) ;
String bomContents = new String ( Files . readAllBytes ( bom . toPath ( ) ) , StandardCharsets . UTF_8 ) ;
assertThat ( bomContents ). contains ( "library(\"ActiveMQ\", \"5.16\")" ) ;
assertThat ( bomContents .length ( ) ) . isEqualTo ( originalContents . length ( ) - 3 ) ;
}
}
@Test
@Test
@ -62,14 +64,14 @@ class UpgradeApplicatorTests {
FileCopyUtils . copy ( new File ( "src/test/resources/bom.gradle" ) , bom ) ;
FileCopyUtils . copy ( new File ( "src/test/resources/bom.gradle" ) , bom ) ;
File gradleProperties = new File ( this . temp , "gradle.properties" ) ;
File gradleProperties = new File ( this . temp , "gradle.properties" ) ;
FileCopyUtils . copy ( new File ( "src/test/resources/gradle.properties" ) , gradleProperties ) ;
FileCopyUtils . copy ( new File ( "src/test/resources/gradle.properties" ) , gradleProperties ) ;
new UpgradeApplicator ( bom . toPath ( ) , gradleProperties . toPath ( ) )
new UpgradeApplicator ( bom . toPath ( ) , gradleProperties . toPath ( ) ) . apply ( new Upgrade (
. apply ( new Upgrade ( new Library ( "Kotlin" , DependencyVersion . parse ( "1.3.70" ) , null , null ) ,
new Library ( "Kotlin" , DependencyVersion . parse ( "1.3.70" ) , null , null ) , DependencyVersion . parse ( "1.4" ) ) ) ;
DependencyVersion . parse ( "1.3.71" ) ) ) ;
Properties properties = new Properties ( ) ;
Properties properties = new Properties ( ) ;
try ( InputStream in = new FileInputStream ( gradleProperties ) ) {
try ( InputStream in = new FileInputStream ( gradleProperties ) ) {
properties . load ( in ) ;
properties . load ( in ) ;
}
}
assertThat ( properties ) . containsEntry ( "kotlinVersion" , "1.3.71" ) ;
assertThat ( properties ) . containsOnly ( entry ( "a" , "alpha" ) , entry ( "b" , "bravo" ) , entry ( "kotlinVersion" , "1.4" ) ,
entry ( "t" , "tango" ) ) ;
}
}
}
}