junit
junit
diff --git a/testing-modules/selenium-junit-testng/pom.xml b/testing-modules/selenium-junit-testng/pom.xml
index 860397f229..0bf6f0726d 100644
--- a/testing-modules/selenium-junit-testng/pom.xml
+++ b/testing-modules/selenium-junit-testng/pom.xml
@@ -1,7 +1,7 @@
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
selenium-junit-testng
0.0.1-SNAPSHOT
diff --git a/testing-modules/testing-assertions/src/test/java/com/baeldung/optional/OptionalUnitTest.java b/testing-modules/testing-assertions/src/test/java/com/baeldung/optional/OptionalUnitTest.java
new file mode 100644
index 0000000000..351b3dd3e0
--- /dev/null
+++ b/testing-modules/testing-assertions/src/test/java/com/baeldung/optional/OptionalUnitTest.java
@@ -0,0 +1,58 @@
+package com.baeldung.optional;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.Optional;
+
+import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+class OptionalUnitTest {
+
+ private static final String OPTIONAL_RETURN_VALUE = "optionalReturnValue";
+
+ @Test
+ public void givenOptionalWithValue_whenAssertThatIsNotEmpty_thenOk() {
+ assertThat(Optional.of(OPTIONAL_RETURN_VALUE)).isNotEmpty();
+ }
+
+ @Test
+ public void givenOptionalWithValue_whenAssertThatHasValue_thenOk() {
+ assertThat(Optional.of(OPTIONAL_RETURN_VALUE)).hasValue(OPTIONAL_RETURN_VALUE);
+ }
+
+ @Test
+ public void givenOptionalWithValue_whenAssertEqualsOptionalObject_thenOk() {
+ Optional expected = Optional.of(OPTIONAL_RETURN_VALUE);
+ Optional actual = Optional.of(OPTIONAL_RETURN_VALUE);
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void givenOptionalWithValue_whenAssertEqualsGet_thenOk() {
+ Optional optional = Optional.of(OPTIONAL_RETURN_VALUE);
+ assertEquals(OPTIONAL_RETURN_VALUE, optional.get());
+ }
+
+ @Test
+ public void givenOptionalWithValue_whenIsPresentAndGetSplit_thenOk() {
+ Optional optional = Optional.of(OPTIONAL_RETURN_VALUE);
+
+ assertTrue(optional.isPresent());
+ assertEquals(OPTIONAL_RETURN_VALUE, optional.get());
+ }
+
+ @Test
+ public void givenEmptyOptional_whenAssertThatIsEmpty_thenOk() {
+ Optional emptyOptional = Optional.empty();
+ assertThat(emptyOptional).isEmpty();
+ }
+
+ @Test
+ public void givenEmptyOptional_whenAssertIsNotPresent_thenOk() {
+ Optional emptyOptional = Optional.empty();
+ assertFalse(emptyOptional.isPresent());
+ }
+}
diff --git a/xml/pom.xml b/xml/pom.xml
index f88f0f89b0..d05f2401e3 100644
--- a/xml/pom.xml
+++ b/xml/pom.xml
@@ -14,6 +14,22 @@
+
+ org.jsoup
+ jsoup
+ ${jsoup.version}
+
+
+ net.sourceforge.htmlcleaner
+ htmlcleaner
+ ${htmlcleaner.version}
+
+
+ net.htmlparser.jericho
+ jericho-html
+ ${jericho.version}
+
+
org.dom4j
@@ -178,8 +194,8 @@
${maven-compiler-plugin.version}
+ org.apache.maven.plugins
maven-surefire-plugin
- ${maven-surefire-plugin.version}
@@ -242,7 +258,6 @@
org.apache.maven.plugins
maven-surefire-plugin
- ${maven-surefire-plugin.version}
CustomerTest.java
@@ -362,6 +377,9 @@
1.3.1
3.8.0
+ 1.14.3
+ 2.25
+ 3.4
\ No newline at end of file
diff --git a/xml/src/test/java/com/baeldung/xmlhtml/delhtmltags/RemoveHtmlTagsLiveTest.java b/xml/src/test/java/com/baeldung/xmlhtml/delhtmltags/RemoveHtmlTagsLiveTest.java
new file mode 100644
index 0000000000..b05123cbdc
--- /dev/null
+++ b/xml/src/test/java/com/baeldung/xmlhtml/delhtmltags/RemoveHtmlTagsLiveTest.java
@@ -0,0 +1,61 @@
+package com.baeldung.xmlhtml.delhtmltags;
+
+import net.htmlparser.jericho.Renderer;
+import net.htmlparser.jericho.Segment;
+import net.htmlparser.jericho.Source;
+import org.htmlcleaner.CleanerProperties;
+import org.htmlcleaner.HtmlCleaner;
+import org.jsoup.Jsoup;
+import org.junit.jupiter.api.Test;
+
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+
+class RemoveHtmlTagsLiveTest {
+
+ @Test
+ void givenHtml1_whenRemoveTagsByRegex_thenPrintText() throws IOException, URISyntaxException {
+ String html = new String(Files.readAllBytes(
+ (Paths.get(getClass().getResource("/xmlhtml/delhtmltags/example1.html").toURI()))));
+ String result = html.replaceAll("<[^>]*>", "")
+ .replaceAll("(?m)^\\s*$", ""); // remove empty and blank lines
+ System.out.println(result);
+ }
+
+ @Test
+ void givenHtml2_whenRemoveTagsByRegex_thenPrintText() throws IOException, URISyntaxException {
+ String html = new String(Files.readAllBytes(
+ (Paths.get(getClass().getResource("/xmlhtml/delhtmltags/example2.html").toURI()))));
+ String result = html.replaceAll("<[^>]*>", "");
+ System.out.println(result);
+ }
+
+ @Test
+ void givenHtml2_whenRemoveTagsByJsoup_thenPrintText() throws IOException, URISyntaxException {
+ String html = new String(Files.readAllBytes(
+ (Paths.get(getClass().getResource("/xmlhtml/delhtmltags/example2.html").toURI()))));
+ System.out.println(Jsoup.parse(html).text());
+ }
+
+ @Test
+ void givenHtml2_whenRemoveTagsByHtmlCleaner_thenPrintText() throws IOException, URISyntaxException {
+ String html = new String(Files.readAllBytes(
+ (Paths.get(getClass().getResource("/xmlhtml/delhtmltags/example2.html").toURI()))));
+ CleanerProperties props = new CleanerProperties();
+ props.setPruneTags("script");
+ String result = new HtmlCleaner(props).clean(html).getText().toString();
+ System.out.println(result);
+ }
+
+ @Test
+ void givenHtml2_whenRemoveTagsByJericho_thenPrintText() throws IOException, URISyntaxException {
+ String html = new String(Files.readAllBytes(
+ (Paths.get(getClass().getResource("/xmlhtml/delhtmltags/example2.html").toURI()))));
+ Source htmlSource = new Source(html);
+ Segment segment = new Segment(htmlSource, 0, htmlSource.length());
+ Renderer htmlRender = new Renderer(segment).setIncludeHyperlinkURLs(true);
+ System.out.println(htmlRender);
+ }
+}
diff --git a/xml/src/test/resources/xmlhtml/delhtmltags/example1.html b/xml/src/test/resources/xmlhtml/delhtmltags/example1.html
new file mode 100644
index 0000000000..43f3a22ef4
--- /dev/null
+++ b/xml/src/test/resources/xmlhtml/delhtmltags/example1.html
@@ -0,0 +1,15 @@
+
+
+
+ This is the page title
+
+
+
+ If the application X doesn't start, the possible causes could be:
+ 1. Maven is not installed.
+ 2. Not enough disk space.
+ 3. Not enough memory.
+
+
+
\ No newline at end of file
diff --git a/xml/src/test/resources/xmlhtml/delhtmltags/example2.html b/xml/src/test/resources/xmlhtml/delhtmltags/example2.html
new file mode 100644
index 0000000000..532eadc101
--- /dev/null
+++ b/xml/src/test/resources/xmlhtml/delhtmltags/example2.html
@@ -0,0 +1,22 @@
+
+
+
+ This is the page title
+
+
+
+
+ If the application X doesn't start, the possible causes could be:
+ 1.
+ Maven
+ is not installed.
+ 2. Not enough (<1G) disk space.
+ 3. Not enough (<64MB) memory.
+
+
+
\ No newline at end of file