-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
51 additions
and
2 deletions.
There are no files selected for viewing
53 changes: 51 additions & 2 deletions
53
...romoter/src/test/java/com/bottega/promoter/concert/domain/Title_fromString_microTest.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 |
---|---|---|
@@ -1,20 +1,69 @@ | ||
package com.bottega.promoter.concert.domain; | ||
|
||
import com.bottega.promoter.concert.fixtures.*; | ||
import org.assertj.vavr.api.VavrAssertions; | ||
import org.junit.jupiter.api.Test; | ||
import static com.bottega.promoter.concert.api.app.ConcertErrorCode.invalid_title; | ||
import static com.bottega.promoter.concert.domain.Title.from; | ||
import static com.bottega.promoter.concert.fixtures.TitleAssert.assertThatTitle; | ||
import static com.bottega.sharedlib.vo.error.ErrorResult.badRequest; | ||
import static org.apache.commons.lang3.StringUtils.repeat; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
class Title_fromString_microTest extends ConcertLogicTestBase { | ||
|
||
//TODO tests | ||
|
||
@Test | ||
public void fromString_OK_onValidString(){ | ||
//expect | ||
assertThat(from("This is a valid title for a concert").get().getValue()).isEqualTo("This is a valid title for a concert"); | ||
} | ||
|
||
@Test | ||
public void fromString_trimsTrailingAndLeadingWhitespaces(){ | ||
//given | ||
String expectedValue = repeat("a", 10); | ||
|
||
//expect | ||
assertThat(from(" " + expectedValue + " ").get().getValue()).isEqualTo(expectedValue); | ||
} | ||
|
||
@Test | ||
public void fromString_honorsLengthLimits(){ | ||
//expect | ||
VavrAssertions.assertThat(from(repeat("a", 10))).isValid(); | ||
VavrAssertions.assertThat(from(repeat("a", 160))).isValid(); | ||
|
||
assertInvalidLengthError(repeat("a", 9)); | ||
assertInvalidLengthError(repeat("a", 161)); | ||
|
||
assertInvalidLengthError(repeat("a", 9) + " "); | ||
VavrAssertions.assertThat(from(repeat("a", 160) + " ")).isValid(); | ||
|
||
assertInvalidLengthError(null); | ||
} | ||
|
||
|
||
private void assertInvalidLengthError(String input) { | ||
VavrAssertions.assertThat(from(input)) | ||
.isInvalid() | ||
.containsInvalid(badRequest(invalid_title, "Title length must be between 10 and 160 chars")); | ||
} | ||
|
||
@Test | ||
public void fromString_reportsFirstBannedWord_onBannedWordInTitle(){ | ||
//expect | ||
assertBannedWordsError("rage against the machine", "rage"); | ||
assertBannedWordsError("VIOLENCE", "violence"); | ||
assertBannedWordsError(" Snickers ", "snickers"); | ||
|
||
assertBannedWordsError("rage against the machine", "rage"); | ||
assertBannedWordsError("machine against the rage", "rage"); | ||
assertBannedWordsError("machine rage machine", "rage"); | ||
} | ||
|
||
private void assertBannedWordsError(String input, String bannedWord) { | ||
VavrAssertions.assertThat(from(input)) | ||
.isInvalid() | ||
.containsInvalid(badRequest(invalid_title, "Title must not contain banned word: " + bannedWord)); | ||
} | ||
} |