|
| 1 | +// Copyright 2021 The Terasology Foundation |
| 2 | +// SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +package org.terasology.gestalt.module.dependencyresolution; |
| 5 | + |
| 6 | +import org.junit.jupiter.api.Test; |
| 7 | +import org.terasology.gestalt.naming.Version; |
| 8 | + |
| 9 | +import java.util.function.Predicate; |
| 10 | + |
| 11 | +import static org.junit.jupiter.api.Assertions.assertFalse; |
| 12 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
| 13 | + |
| 14 | +class DependencyInfoTest { |
| 15 | + |
| 16 | + @Test |
| 17 | + void testMinimumVersionUnderOnePointZero() { |
| 18 | + Version minVersion = new Version("0.2.4"); |
| 19 | + |
| 20 | + DependencyInfo dependency = new DependencyInfo(); |
| 21 | + dependency.setMinVersion(minVersion); |
| 22 | + Predicate<Version> predicate = dependency.versionPredicate(); |
| 23 | + |
| 24 | + assertTrue(predicate.test(minVersion), "failed to match its own version"); |
| 25 | + |
| 26 | + Version nextVersion = minVersion.getNextPatchVersion(); |
| 27 | + assertTrue(predicate.test(nextVersion), "failed to match the next patch version"); |
| 28 | + assertTrue(predicate.test(new Version(nextVersion + "-SNAPSHOT")), "failed to match the next snapshot"); |
| 29 | + |
| 30 | + assertFalse(predicate.test(new Version("0.2.3")), "inappropriately matched an earlier patch version"); |
| 31 | + |
| 32 | + assertFalse(predicate.test(nextVersion.getNextMinorVersion()), "inappropriately matched next 0.x minor version"); |
| 33 | + } |
| 34 | + |
| 35 | + @Test |
| 36 | + void testMinimumVersionOverOnePointZero() { |
| 37 | + Version minVersion = new Version("1.4.7"); |
| 38 | + |
| 39 | + DependencyInfo dependency = new DependencyInfo(); |
| 40 | + dependency.setMinVersion(minVersion); |
| 41 | + Predicate<Version> predicate = dependency.versionPredicate(); |
| 42 | + |
| 43 | + assertTrue(predicate.test(minVersion), "failed to match its own version"); |
| 44 | + |
| 45 | + Version nextVersion = minVersion.getNextPatchVersion(); |
| 46 | + assertTrue(predicate.test(nextVersion), "failed to match the next patch version"); |
| 47 | + assertTrue(predicate.test(new Version(nextVersion + "-SNAPSHOT")), "failed to match the next snapshot"); |
| 48 | + |
| 49 | + Version nextMinorVersion = minVersion.getNextMinorVersion(); |
| 50 | + assertTrue(predicate.test(nextMinorVersion), "failed to match the next minor version"); |
| 51 | + assertTrue(predicate.test(new Version(nextMinorVersion + "-SNAPSHOT")), "failed to match the next minor snapshot"); |
| 52 | + |
| 53 | + assertFalse(predicate.test(new Version("1.4.6")), "inappropriately matched an earlier patch version"); |
| 54 | + assertFalse(predicate.test(nextVersion.getNextMajorVersion()), "inappropriately matched next major version"); |
| 55 | + } |
| 56 | + |
| 57 | + @Test |
| 58 | + void testMinimumVersionIsSnapshot() { |
| 59 | + Version snapshot = new Version("2.0.0-SNAPSHOT"); |
| 60 | + Version release = new Version("2.0.0"); |
| 61 | + |
| 62 | + DependencyInfo dependency = new DependencyInfo(); |
| 63 | + dependency.setMinVersion(snapshot); |
| 64 | + Predicate<Version> predicate = dependency.versionPredicate(); |
| 65 | + |
| 66 | + assertTrue(predicate.test(snapshot), "failed to match its own version"); |
| 67 | + assertTrue(predicate.test(release), "failed to match release version"); |
| 68 | + |
| 69 | + Version nextVersion = release.getNextPatchVersion(); |
| 70 | + assertTrue(predicate.test(nextVersion), "failed to match the next patch version"); |
| 71 | + assertTrue(predicate.test(new Version(nextVersion + "-SNAPSHOT")), "failed to match the next snapshot"); |
| 72 | + assertFalse(predicate.test(release.getNextMajorVersion()), "inappropriately matched next major version"); |
| 73 | + } |
| 74 | +} |
0 commit comments