-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Had to add separator field, so that can keep track of how long the separator is and fix bug that occurs with long separator Strings.
- Loading branch information
1 parent
873ce0e
commit b0cd47e
Showing
2 changed files
with
81 additions
and
3 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
74 changes: 74 additions & 0 deletions
74
src/test/java/com/eddarmitage/slugger/SlugBuilderTest.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,74 @@ | ||
package com.eddarmitage.slugger; | ||
|
||
import org.assertj.core.api.SoftAssertions; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import java.util.Arrays; | ||
import java.util.OptionalInt; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class SlugBuilderTest { | ||
|
||
@Before | ||
public void setup() { | ||
|
||
} | ||
|
||
@Test | ||
public void testSlugBuilder_withDefaultConfiguration() { | ||
SlugBuilder slugBuilder = new SlugBuilder("-"); | ||
Arrays.asList("one", "two", "three").forEach(slugBuilder::addWord); | ||
|
||
assertThat(slugBuilder.build()).isEqualTo("one-two-three"); | ||
} | ||
|
||
@Test | ||
public void testSlugBuilder_withLengthRestriction() { | ||
SlugBuilder slugBuilder = new SlugBuilder(OptionalInt.of(10), false, "-"); | ||
Arrays.asList("one", "two", "three").forEach(slugBuilder::addWord); | ||
|
||
assertThat(slugBuilder.build()).isEqualTo("one-two"); | ||
} | ||
|
||
@Test | ||
public void testSlugBuilder_withLengthRestrictionAndLongSeparator() { | ||
SlugBuilder slugBuilder = new SlugBuilder(OptionalInt.of(10), false, "-----"); | ||
Arrays.asList("one", "two", "three").forEach(slugBuilder::addWord); | ||
|
||
assertThat(slugBuilder.build()).isEqualTo("one"); | ||
} | ||
|
||
@Test | ||
public void testSlugBuilder_withLongFirstWord() { | ||
SlugBuilder slugBuilder = new SlugBuilder(OptionalInt.of(10), false, "-"); | ||
slugBuilder.addWord("refrigerator"); | ||
|
||
assertThat(slugBuilder.build()).isEqualTo("refrigerator"); | ||
} | ||
|
||
@Test | ||
public void testSlugBuilder_withLongFirstWordAndHardLimitsEnforced() { | ||
SlugBuilder slugBuilder = new SlugBuilder(OptionalInt.of(10), true, "-"); | ||
slugBuilder.addWord("refrigerator"); | ||
|
||
assertThat(slugBuilder.build()).isEqualTo("refrigerat"); | ||
} | ||
|
||
@Test | ||
public void testSlugBuilder_isMergedWithOtherSlugBuilder() { | ||
SlugBuilder firstBuilder = new SlugBuilder("-"); | ||
Arrays.asList("one", "two").forEach(firstBuilder::addWord); | ||
|
||
SlugBuilder secondBuilder = new SlugBuilder("-"); | ||
Arrays.asList("three", "four").forEach(secondBuilder::addWord); | ||
|
||
String mergedResult = firstBuilder.merge(secondBuilder).build(); | ||
|
||
SoftAssertions softly = new SoftAssertions(); | ||
softly.assertThat(mergedResult).hasSize(18); | ||
softly.assertThat(mergedResult).isEqualTo("one-two-three-four"); | ||
softly.assertAll(); | ||
} | ||
} |