-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for scope/stage calculators
- Loading branch information
1 parent
8b3138c
commit ec7e26b
Showing
6 changed files
with
95 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
reckon-core/src/test/java/org/ajoberstar/reckon/core/ReckonerIntegTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
reckon-core/src/test/java/org/ajoberstar/reckon/core/ScopeCalculatorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package org.ajoberstar.reckon.core; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.Arrays; | ||
import java.util.Optional; | ||
import java.util.regex.Pattern; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
public class ScopeCalculatorTest { | ||
@Test | ||
@DisplayName("ofUserString filters out empty scope strings") | ||
public void ofUserStringFiltersEmptyStrings() { | ||
var calc = ScopeCalculator.ofUserString(i -> Optional.of("")); | ||
assertEquals(Optional.empty(), calc.calculate(VcsInventory.empty(false))); | ||
} | ||
|
||
@Test | ||
@DisplayName("ofUserString handles mixed case") | ||
public void ofUserStringMixedCase() { | ||
var calc = ScopeCalculator.ofUserString(i -> Optional.of("MiNor")); | ||
assertEquals(Optional.of(Scope.MINOR), calc.calculate(VcsInventory.empty(false))); | ||
} | ||
|
||
@Test | ||
@DisplayName("ofCommitMessage behaves as expected") | ||
public void ofCommitMessageNoMatch() { | ||
var pattern = Pattern.compile("^(major|minor|patch): .+"); | ||
var calc = ScopeCalculator.ofCommitMessage(msg -> { | ||
var matcher = pattern.matcher(msg); | ||
if (matcher.find()) { | ||
return Optional.of(Scope.from(matcher.group(1))); | ||
} else { | ||
return Optional.empty(); | ||
} | ||
}); | ||
assertEquals(Optional.empty(), calc.calculate(VcsInventory.empty(false)), "Should not find a scope in an empty inventory"); | ||
|
||
var inventoryNoMatches = getInventoryWithMessages("some message", "other message\n\nminor: something", "major"); | ||
assertEquals(Optional.empty(), calc.calculate(inventoryNoMatches), "Should not find a scope when no messages match"); | ||
|
||
var inventoryOneMatch = getInventoryWithMessages("some message", "patch: some fix"); | ||
assertEquals(Optional.of(Scope.PATCH), calc.calculate(inventoryOneMatch), "Should find the one matching scope"); | ||
|
||
var inventoryMultiMatch = getInventoryWithMessages("some message", "patch: some fix", "major: breaking change"); | ||
assertEquals(Optional.of(Scope.MAJOR), calc.calculate(inventoryMultiMatch), "Should find the more significant matching scope"); | ||
} | ||
|
||
private VcsInventory getInventoryWithMessages(String... messages) { | ||
return new VcsInventory( | ||
null, | ||
false, | ||
null, | ||
null, | ||
null, | ||
0, | ||
null, | ||
null, | ||
Arrays.asList(messages) | ||
); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
reckon-core/src/test/java/org/ajoberstar/reckon/core/StageCalculatorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package org.ajoberstar.reckon.core; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.Optional; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
public class StageCalculatorTest { | ||
@Test | ||
@DisplayName("ofUserString filters out empty scope strings") | ||
public void ofUserStringFiltersEmptyStrings() { | ||
var calc = StageCalculator.ofUserString((i, v) -> Optional.of("")); | ||
assertEquals(Optional.empty(), calc.calculate(VcsInventory.empty(false), Version.IDENTITY)); | ||
} | ||
|
||
@Test | ||
@DisplayName("ofUserString handles mixed case") | ||
public void ofUserStringMixedCase() { | ||
var calc = StageCalculator.ofUserString((i, v) -> Optional.of("BeTa")); | ||
assertEquals(Optional.of("beta"), calc.calculate(VcsInventory.empty(false), Version.IDENTITY)); | ||
} | ||
} |