Skip to content

Instantly share code, notes, and snippets.

@stevez
Created April 30, 2015 03:09
Show Gist options
  • Save stevez/b72ad3b294a80626b925 to your computer and use it in GitHub Desktop.
Save stevez/b72ad3b294a80626b925 to your computer and use it in GitHub Desktop.
import static org.junit.Assert.*;
import org.junit.Before
import org.junit.Test;
class TestScriptScrub {
private ScriptScrub scrub
@Before
public void setup() {
scrub = new ScriptScrub()
}
@Test
public void given_text_will_remove_script_tag() {
def text = """The historic <script>
adfadfasdfasdf;a sdf
a adfasdfasdfaf
</script>moment is cool"""
def expected_result = "The historic moment is cool"
def result = scrub.scrub(text)
assert result == expected_result
}
@Test
public void given_text_non_Line_break_will_remove_script_tag() {
def text = """The historic <script>adfadfasdfasdf;a sdf a adfasdfasdfaf</script>moment is cool"""
def expected_result = "The historic moment is cool"
ScriptScrub scrub = new ScriptScrub()
def result = scrub.scrub(text)
assert result == expected_result
}
@Test
public void given_text_with_javascript_tag_will_remove_script_tag() {
def text = """The historic <script type="text/javascript">
adfadfasdfasdf;a sdf
a adfasdfasdfaf
</script>moment is cool"""
def expected_result = "The historic moment is cool"
def result = scrub.scrub(text)
assert result == expected_result
}
@Test
public void given_text_with_javascript_tag_and_src_tag_will_remove_script_tag() {
def text = """The historic <script type="text/javascript" src="javascript.js">
adfadfasdfasdf;a sdf
a adfasdfasdfaf
</script>moment is cool"""
def expected_result = "The historic moment is cool"
def result = scrub.scrub(text)
assert result == expected_result
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment