### Question:
LinkageMonitor { @VisibleForTesting static Model buildModelWithSnapshotBom( RepositorySystem repositorySystem, RepositorySystemSession session, String bomCoordinates, Map<String, String> localArtifacts) throws ModelBuildingException, ArtifactResolutionException { String[] elements = bomCoordinates.split(":"); DefaultArtifact bom; if (elements.length >= 4) { bom = new DefaultArtifact(bomCoordinates); } else if (elements.length == 3) { bom = new DefaultArtifact(elements[0], elements[1], "pom", elements[2]); } else { throw new IllegalArgumentException( "BOM coordinates do not have valid format: " + bomCoordinates); } ArtifactResult bomResult = repositorySystem.resolveArtifact( session, new ArtifactRequest(bom, ImmutableList.of(CENTRAL), null)); ModelBuildingRequest modelRequest = new DefaultModelBuildingRequest(); modelRequest.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL); modelRequest.setProcessPlugins(false); modelRequest.setTwoPhaseBuilding(true); modelRequest.setPomFile(bomResult.getArtifact().getFile()); modelRequest.setModelResolver( new VersionSubstitutingModelResolver( session, null, repositorySystem, new DefaultRemoteRepositoryManager(), ImmutableList.of(CENTRAL), localArtifacts)); modelRequest.setSystemProperties(System.getProperties()); ModelBuildingResult resultPhase1 = modelBuilder.build(modelRequest); DependencyManagement dependencyManagement = resultPhase1.getEffectiveModel().getDependencyManagement(); for (org.apache.maven.model.Dependency dependency : dependencyManagement.getDependencies()) { if ("import".equals(dependency.getScope())) { String version = localArtifacts.getOrDefault( dependency.getGroupId() + ":" + dependency.getArtifactId(), dependency.getVersion()); dependency.setVersion(version); } } ModelBuildingResult resultPhase2 = modelBuilder.build(modelRequest, resultPhase1); return resultPhase2.getEffectiveModel(); }  static void main(String[] arguments);  }### Answer:
@Test public void testBuildModelWithSnapshotBom_noSnapshotUpdate() throws ModelBuildingException, ArtifactResolutionException { Model model = LinkageMonitor.buildModelWithSnapshotBom( system, session, "com.google.cloud:libraries-bom:2.2.1", ImmutableMap.of()); List<Dependency> dependencies = model.getDependencyManagement().getDependencies(); assertEquals( "There should not be a duplicate", dependencies.stream().distinct().count(), dependencies.size()); assertEquals(214, dependencies.size()); }
@Test public void testBuildModelWithSnapshotBom_invalidCoordinates() throws ModelBuildingException, ArtifactResolutionException { for (String invalidCoordinates : ImmutableList.of("a.b.c:d", "a:b:c:d:e:1", "a::c:0.1")) { try { LinkageMonitor.buildModelWithSnapshotBom( system, session, invalidCoordinates, ImmutableMap.of()); fail("The method should invalidate coordinates: " + invalidCoordinates); } catch (IllegalArgumentException ex) { } } }
@Test public void testBuildModelWithSnapshotBom_BomSnapshotUpdate() throws ModelBuildingException, ArtifactResolutionException { Model model = LinkageMonitor.buildModelWithSnapshotBom( system, session, "com.google.cloud:libraries-bom:2.2.1", ImmutableMap.of("com.google.cloud:google-cloud-bom", "0.106.0-alpha")); List<Dependency> dependencies = model.getDependencyManagement().getDependencies(); assertEquals(224, dependencies.size()); assertTrue( dependencies.stream() .anyMatch( dependency -> "gax".equals(dependency.getArtifactId()) && "1.48.0".equals(dependency.getVersion()))); }
@Test public void testBuildModelWithSnapshotBom_JdkVersionActivation() throws ModelBuildingException, ArtifactResolutionException { Model model = LinkageMonitor.buildModelWithSnapshotBom( system, session, "com.google.cloud:google-cloud-core-parent:1.91.0", ImmutableMap.of()); assertNotNull(model); }