|
| 1 | +/* |
| 2 | + * Copyright 2019-2020 the original author or authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package org.springframework.security.convention.versions; |
| 18 | + |
| 19 | +import com.github.benmanes.gradle.versions.updates.resolutionstrategy.ComponentSelectionWithCurrent; |
| 20 | +import org.gradle.api.Action; |
| 21 | +import org.gradle.api.artifacts.ComponentSelection; |
| 22 | +import org.gradle.api.artifacts.component.ModuleComponentIdentifier; |
| 23 | +import org.junit.Test; |
| 24 | + |
| 25 | +import java.util.Collections; |
| 26 | +import java.util.List; |
| 27 | + |
| 28 | +import static org.mockito.ArgumentMatchers.any; |
| 29 | +import static org.mockito.BDDMockito.given; |
| 30 | +import static org.mockito.Mockito.*; |
| 31 | + |
| 32 | +public class DependencyExcludesTests { |
| 33 | + |
| 34 | + @Test |
| 35 | + public void createExcludeMinorVersionBumpWhenMajorVersionBumpThenReject() { |
| 36 | + ComponentSelection componentSelection = executeCreateExcludeMinorVersionBump("1.0.0", "2.0.0"); |
| 37 | + verify(componentSelection).reject(any()); |
| 38 | + } |
| 39 | + |
| 40 | + @Test |
| 41 | + public void createExcludeMinorVersionBumpWhenMajorCalVersionBumpThenReject() { |
| 42 | + ComponentSelection componentSelection = executeCreateExcludeMinorVersionBump("2000.0.0", "2001.0.0"); |
| 43 | + verify(componentSelection).reject(any()); |
| 44 | + } |
| 45 | + |
| 46 | + @Test |
| 47 | + public void createExcludeMinorVersionBumpWhenMinorVersionBumpThenReject() { |
| 48 | + ComponentSelection componentSelection = executeCreateExcludeMinorVersionBump("1.0.0", "1.1.0"); |
| 49 | + verify(componentSelection).reject(any()); |
| 50 | + } |
| 51 | + |
| 52 | + @Test |
| 53 | + public void createExcludeMinorVersionBumpWhenMinorCalVersionBumpThenReject() { |
| 54 | + ComponentSelection componentSelection = executeCreateExcludeMinorVersionBump("2000.0.0", "2000.1.0"); |
| 55 | + verify(componentSelection).reject(any()); |
| 56 | + } |
| 57 | + |
| 58 | + @Test |
| 59 | + public void createExcludeMinorVersionBumpWhenMinorAndPatchVersionBumpThenReject() { |
| 60 | + ComponentSelection componentSelection = executeCreateExcludeMinorVersionBump("1.0.0", "1.1.1"); |
| 61 | + verify(componentSelection).reject(any()); |
| 62 | + } |
| 63 | + |
| 64 | + @Test |
| 65 | + public void createExcludeMinorVersionBumpWhenPatchVersionBumpThenDoesNotReject() { |
| 66 | + ComponentSelection componentSelection = executeCreateExcludeMinorVersionBump("1.0.0", "1.0.1"); |
| 67 | + verify(componentSelection, times(0)).reject(any()); |
| 68 | + } |
| 69 | + |
| 70 | + private ComponentSelection executeCreateExcludeMinorVersionBump(String currentVersion, String candidateVersion) { |
| 71 | + ComponentSelection componentSelection = mock(ComponentSelection.class); |
| 72 | + UpdateDependenciesExtension.DependencyExcludes excludes = new UpdateDependenciesExtension(() -> Collections.emptyList()).new DependencyExcludes(); |
| 73 | + Action<ComponentSelectionWithCurrent> excludeMinorVersionBump = excludes.createExcludeMinorVersionBump(); |
| 74 | + ComponentSelectionWithCurrent selection = currentVersionAndCandidateVersion(componentSelection, currentVersion, candidateVersion); |
| 75 | + excludeMinorVersionBump.execute(selection); |
| 76 | + return componentSelection; |
| 77 | + } |
| 78 | + |
| 79 | + private ComponentSelectionWithCurrent currentVersionAndCandidateVersion(ComponentSelection componentSelection, String currentVersion, String candidateVersion) { |
| 80 | + ModuleComponentIdentifier candidate = mock(ModuleComponentIdentifier.class); |
| 81 | + given(componentSelection.getCandidate()).willReturn(candidate); |
| 82 | + ComponentSelectionWithCurrent selection = new ComponentSelectionWithCurrent(currentVersion, componentSelection); |
| 83 | + given(candidate.getVersion()).willReturn(candidateVersion); |
| 84 | + given(componentSelection.getCandidate()).willReturn(candidate); |
| 85 | + return selection; |
| 86 | + } |
| 87 | +} |
0 commit comments