-
-
Notifications
You must be signed in to change notification settings - Fork 48
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
1 parent
326d351
commit bb5735e
Showing
2 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
src/main/java/org/zwobble/mammoth/internal/styles/HighlightMatcher.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,16 @@ | ||
package org.zwobble.mammoth.internal.styles; | ||
|
||
import java.util.Optional; | ||
|
||
public class HighlightMatcher implements DocumentElementMatcher<String> { | ||
private final Optional<String> color; | ||
|
||
public HighlightMatcher(Optional<String> color) { | ||
this.color = color; | ||
} | ||
|
||
@Override | ||
public boolean matches(String color) { | ||
return !this.color.isPresent() || this.color.get().equals(color); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
src/test/java/org/zwobble/mammoth/tests/styles/HighlightMatcherTests.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,38 @@ | ||
package org.zwobble.mammoth.tests.styles; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.zwobble.mammoth.internal.styles.HighlightMatcher; | ||
|
||
import java.util.Optional; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.equalTo; | ||
|
||
public class HighlightMatcherTests { | ||
@Test | ||
public void highlightMatcherWithoutColorMatchesAllHighlightElements() { | ||
HighlightMatcher matcher = new HighlightMatcher(Optional.empty()); | ||
|
||
boolean result = matcher.matches("yellow"); | ||
|
||
assertThat(result, equalTo(true)); | ||
} | ||
|
||
@Test | ||
public void highlightMatcherWithColorMatchesHighlightWithThatColor() { | ||
HighlightMatcher matcher = new HighlightMatcher(Optional.of("yellow")); | ||
|
||
boolean result = matcher.matches("yellow"); | ||
|
||
assertThat(result, equalTo(true)); | ||
} | ||
|
||
@Test | ||
public void highlightMatcherWithColorDoesNotMatchHighlightsWithOtherColors() { | ||
HighlightMatcher matcher = new HighlightMatcher(Optional.of("yellow")); | ||
|
||
boolean result = matcher.matches("red"); | ||
|
||
assertThat(result, equalTo(false)); | ||
} | ||
} |