UtilsTest.java 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. package io.spring.gradle.convention;
  2. import static org.assertj.core.api.Assertions.assertThat;
  3. import static org.mockito.Mockito.when;
  4. import org.gradle.api.Project;
  5. import org.junit.jupiter.api.Test;
  6. import org.junit.jupiter.api.extension.ExtendWith;
  7. import org.mockito.Mock;
  8. import org.mockito.junit.jupiter.MockitoExtension;
  9. @ExtendWith(MockitoExtension.class)
  10. public class UtilsTest {
  11. @Mock
  12. Project project;
  13. @Mock
  14. Project rootProject;
  15. @Test
  16. public void getProjectName() {
  17. when(project.getRootProject()).thenReturn(rootProject);
  18. when(rootProject.getName()).thenReturn("spring-security");
  19. assertThat(Utils.getProjectName(project)).isEqualTo("spring-security");
  20. }
  21. @Test
  22. public void getProjectNameWhenEndsWithBuildThenStrippedOut() {
  23. when(project.getRootProject()).thenReturn(rootProject);
  24. when(rootProject.getName()).thenReturn("spring-security-build");
  25. assertThat(Utils.getProjectName(project)).isEqualTo("spring-security");
  26. }
  27. @Test
  28. public void isSnapshotValidWithDot() {
  29. when(project.getVersion()).thenReturn("1.0.0.BUILD-SNAPSHOT");
  30. assertThat(Utils.isSnapshot(project)).isTrue();
  31. }
  32. @Test
  33. public void isSnapshotValidWithNoBuild() {
  34. when(project.getVersion()).thenReturn("1.0.0-SNAPSHOT");
  35. assertThat(Utils.isSnapshot(project)).isTrue();
  36. }
  37. @Test
  38. public void isSnapshotValidWithDash() {
  39. when(project.getVersion()).thenReturn("Theme-BUILD-SNAPSHOT");
  40. assertThat(Utils.isSnapshot(project)).isTrue();
  41. }
  42. @Test
  43. public void isSnapshotInvalid() {
  44. when(project.getVersion()).thenReturn("1.0.0.SNAPSHOT");
  45. assertThat(Utils.isSnapshot(project)).isFalse();
  46. }
  47. @Test
  48. public void isMilestoneValidWithDot() {
  49. when(project.getVersion()).thenReturn("1.0.0.M1");
  50. assertThat(Utils.isMilestone(project)).isTrue();
  51. }
  52. @Test
  53. public void isMilestoneValidWithDash() {
  54. when(project.getVersion()).thenReturn("Theme-M1");
  55. assertThat(Utils.isMilestone(project)).isTrue();
  56. }
  57. @Test
  58. public void isMilestoneValidWithNumberDash() {
  59. when(project.getVersion()).thenReturn("1.0.0-M1");
  60. assertThat(Utils.isMilestone(project)).isTrue();
  61. }
  62. @Test
  63. public void isMilestoneInvalid() {
  64. when(project.getVersion()).thenReturn("1.0.0.M");
  65. assertThat(Utils.isMilestone(project)).isFalse();
  66. }
  67. @Test
  68. public void isReleaseCandidateValidWithDot() {
  69. when(project.getVersion()).thenReturn("1.0.0.RC1");
  70. assertThat(Utils.isMilestone(project)).isTrue();
  71. }
  72. @Test
  73. public void isReleaseCandidateValidWithNumberDash() {
  74. when(project.getVersion()).thenReturn("1.0.0-RC1");
  75. assertThat(Utils.isMilestone(project)).isTrue();
  76. }
  77. @Test
  78. public void isReleaseCandidateValidWithDash() {
  79. when(project.getVersion()).thenReturn("Theme-RC1");
  80. assertThat(Utils.isMilestone(project)).isTrue();
  81. }
  82. @Test
  83. public void isReleaseCandidateInvalid() {
  84. when(project.getVersion()).thenReturn("1.0.0.RC");
  85. assertThat(Utils.isMilestone(project)).isFalse();
  86. }
  87. @Test
  88. public void isReleaseValidWithDot() {
  89. when(project.getVersion()).thenReturn("1.0.0.RELEASE");
  90. assertThat(Utils.isRelease(project)).isTrue();
  91. }
  92. @Test
  93. public void isReleaseValidWithNoRelease() {
  94. when(project.getVersion()).thenReturn("1.0.0");
  95. assertThat(Utils.isRelease(project)).isTrue();
  96. }
  97. @Test
  98. public void isReleaseValidWithDash() {
  99. when(project.getVersion()).thenReturn("Theme-RELEASE");
  100. assertThat(Utils.isRelease(project)).isTrue();
  101. }
  102. @Test
  103. public void isServiceReleaseValid() {
  104. when(project.getVersion()).thenReturn("Theme-SR1");
  105. assertThat(Utils.isRelease(project)).isTrue();
  106. }
  107. }