Skip to content

Commit

Permalink
Eliminate SonarQube warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanseifert committed Jan 19, 2024
1 parent f0126f4 commit c07b8b9
Show file tree
Hide file tree
Showing 18 changed files with 69 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
* @param <T> Class derived from HtmlElement
*/
@ConsumerType
@SuppressWarnings("java:S110") // # parent inheritance
public abstract class AbstractNonSelfClosingHtmlElement<T extends HtmlElement> extends HtmlElement<T> {
private static final long serialVersionUID = 1L;

Expand Down
1 change: 1 addition & 0 deletions src/main/java/io/wcm/handler/commons/dom/Anchor.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
* Html anchor (a) element.
*/
@ProviderType
@SuppressWarnings("java:S110") // # parent inheritance
public final class Anchor extends AbstractNonSelfClosingHtmlElement<Anchor> {
private static final long serialVersionUID = 1L;

Expand Down
1 change: 1 addition & 0 deletions src/main/java/io/wcm/handler/commons/dom/Area.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
* Html area element.
*/
@ProviderType
@SuppressWarnings("java:S110") // # parent inheritance
public final class Area extends HtmlElement<Area> {
private static final long serialVersionUID = 1L;

Expand Down
1 change: 1 addition & 0 deletions src/main/java/io/wcm/handler/commons/dom/Audio.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
* Html audio (audio) element.
*/
@ProviderType
@SuppressWarnings("java:S110") // # parent inheritance
public final class Audio extends AbstractNonSelfClosingHtmlElement<Audio> {
private static final long serialVersionUID = 1L;

Expand Down
1 change: 1 addition & 0 deletions src/main/java/io/wcm/handler/commons/dom/Div.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
* Html div element.
*/
@ProviderType
@SuppressWarnings("java:S110") // # parent inheritance
public final class Div extends AbstractNonSelfClosingHtmlElement<Div> {
private static final long serialVersionUID = 1L;

Expand Down
1 change: 1 addition & 0 deletions src/main/java/io/wcm/handler/commons/dom/FigCaption.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
* Html figure caption (figcaption) element.
*/
@ProviderType
@SuppressWarnings("java:S110") // # parent inheritance
public final class FigCaption extends AbstractNonSelfClosingHtmlElement<FigCaption> {
private static final long serialVersionUID = 1L;

Expand Down
1 change: 1 addition & 0 deletions src/main/java/io/wcm/handler/commons/dom/Figure.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
* Html figure (figure) element.
*/
@ProviderType
@SuppressWarnings("java:S110") // # parent inheritance
public final class Figure extends AbstractNonSelfClosingHtmlElement<Figure> {
private static final long serialVersionUID = 1L;

Expand Down
10 changes: 9 additions & 1 deletion src/main/java/io/wcm/handler/commons/dom/HtmlElement.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
* This element class is an extension of JDOM Element.
* @param <T> Class derived from HtmlElement
*/
@SuppressWarnings("unchecked")
@ConsumerType
@SuppressWarnings("java:S110") // # parent inheritance
public class HtmlElement<T extends HtmlElement> extends AbstractHtmlElementFactory<T> {
private static final long serialVersionUID = 1L;

Expand Down Expand Up @@ -76,6 +76,7 @@ protected final boolean getEmptyAttributeValueAsBoolean(String attributeName) {
* @param value Attribute value as boolean
* @return Self reference
*/
@SuppressWarnings("unchecked")
protected final T setEmptyAttributeValueAsBoolean(String attributeName, boolean value) {
if (value) {
setAttribute(attributeName, attributeName.toLowerCase());
Expand All @@ -99,6 +100,7 @@ public final String getId() {
* @param value Value of attribute
* @return Self reference
*/
@SuppressWarnings("unchecked")
public final T setId(String value) {
setAttribute(ATTRIBUTE_ID, value);
return (T)this;
Expand All @@ -118,6 +120,7 @@ public final String getCssClass() {
* @param value Value of attribute
* @return Self reference
*/
@SuppressWarnings("unchecked")
public final T setCssClass(String value) {
setAttribute(ATTRIBUTE_CLASS, value);
return (T)this;
Expand All @@ -128,6 +131,7 @@ public final T setCssClass(String value) {
* @param value Value of attribute
* @return Self reference
*/
@SuppressWarnings("unchecked")
public final T addCssClass(String value) {
if (StringUtils.isNotEmpty(value)) {
return setCssClass(StringUtils.isNotEmpty(getCssClass()) ? getCssClass() + " " + value : value);
Expand Down Expand Up @@ -181,6 +185,7 @@ public final String getStyle(String styleAttribute) {
* @param value Value of attribute with style key/value pairs
* @return Self reference
*/
@SuppressWarnings("unchecked")
public final T setStyleString(String value) {
setAttribute(ATTRIBUTE_STYLE, value);
return (T)this;
Expand All @@ -192,6 +197,7 @@ public final T setStyleString(String value) {
* @param styleValue Style attribute value
* @return Self reference
*/
@SuppressWarnings("unchecked")
public final T setStyle(String styleAttribute, String styleValue) {

// Add style to style map
Expand Down Expand Up @@ -223,6 +229,7 @@ public final String getTitle() {
* @param value Value of attribute
* @return Self reference
*/
@SuppressWarnings("unchecked")
public final T setTitle(String value) {
setAttribute(ATTRIBUTE_TITLE, value);
return (T)this;
Expand All @@ -243,6 +250,7 @@ public final String getData(String attributeName) {
* @param value Value of attribute
* @return Self reference
*/
@SuppressWarnings("unchecked")
public final T setData(String attributeName, String value) {
setAttribute(ATTRIBUTE_DATA_PREFIX + attributeName, value);
return (T)this;
Expand Down
1 change: 1 addition & 0 deletions src/main/java/io/wcm/handler/commons/dom/Image.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
* Html image (img) element.
*/
@ProviderType
@SuppressWarnings("java:S110") // # parent inheritance
public final class Image extends HtmlElement<Image> {
private static final long serialVersionUID = 1L;

Expand Down
1 change: 1 addition & 0 deletions src/main/java/io/wcm/handler/commons/dom/Map.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
* Html map element.
*/
@ProviderType
@SuppressWarnings("java:S110") // # parent inheritance
public final class Map extends AbstractNonSelfClosingHtmlElement<Map> {
private static final long serialVersionUID = 1L;

Expand Down
1 change: 1 addition & 0 deletions src/main/java/io/wcm/handler/commons/dom/NoScript.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
* Html noscript element.
*/
@ProviderType
@SuppressWarnings("java:S110") // # parent inheritance
public final class NoScript extends AbstractNonSelfClosingHtmlElement<NoScript> {

private static final long serialVersionUID = 1L;
Expand Down
1 change: 1 addition & 0 deletions src/main/java/io/wcm/handler/commons/dom/Picture.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
* Html picture element.
*/
@ProviderType
@SuppressWarnings("java:S110") // # parent inheritance
public final class Picture extends AbstractNonSelfClosingHtmlElement<Picture> {
private static final long serialVersionUID = 1L;

Expand Down
1 change: 1 addition & 0 deletions src/main/java/io/wcm/handler/commons/dom/Script.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
* </pre>
*/
@ProviderType
@SuppressWarnings("java:S110") // # parent inheritance
public final class Script extends AbstractNonSelfClosingHtmlElement<Script> {
private static final long serialVersionUID = 1L;

Expand Down
1 change: 1 addition & 0 deletions src/main/java/io/wcm/handler/commons/dom/Source.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
* Html source (source) element.
*/
@ProviderType
@SuppressWarnings("java:S110") // # parent inheritance
public class Source extends HtmlElement<Source> {
private static final long serialVersionUID = 1L;

Expand Down
1 change: 1 addition & 0 deletions src/main/java/io/wcm/handler/commons/dom/Span.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
* Html span element.
*/
@ProviderType
@SuppressWarnings("java:S110") // # parent inheritance
public final class Span extends AbstractNonSelfClosingHtmlElement<Span> {
private static final long serialVersionUID = 1L;

Expand Down
1 change: 1 addition & 0 deletions src/main/java/io/wcm/handler/commons/dom/Video.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
* Html video (video) element.
*/
@ProviderType
@SuppressWarnings("java:S110") // # parent inheritance
public final class Video extends AbstractNonSelfClosingHtmlElement<Video> {
private static final long serialVersionUID = 1L;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ protected void doGet(@NotNull SlingHttpServletRequest request, @NotNull SlingHtt
requestDispatcher.include(request, response);
}
else {
log.error("Unable to dispatch proxy request for {} referrer={}", request.getRequestURI(), request.getHeader("Referrer"));
String referrer = request.getHeader("Referrer");
log.error("Unable to dispatch proxy request for {} referrer={}", request.getRequestURI(), referrer);
throw new ServletException("No Content");
}

Expand Down
79 changes: 43 additions & 36 deletions src/test/java/io/wcm/handler/commons/dom/HtmlElementTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/
package io.wcm.handler.commons.dom;

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
Expand Down Expand Up @@ -58,22 +59,24 @@ void testAttributeValueAsInteger() {

@Test
void testAddContent() {
underTest.addContent(Set.of(new Image(), new Div()));
underTest.addContent((Collection)null);
assertDoesNotThrow(() -> {
underTest.addContent(Set.of(new Image(), new Div()));
underTest.addContent((Collection)null);

underTest.addContent(new Image());
underTest.addContent((Content)null);
underTest.addContent(new Image());
underTest.addContent((Content)null);

underTest.addContent("text");
underTest.addContent((String)null);
underTest.addContent("text");
underTest.addContent((String)null);

underTest.addContent(0, Set.of(new Image(), new Div()));
underTest.addContent(0, (Collection)null);
underTest.addContent(0, Set.of(new Image(), new Div()));
underTest.addContent(0, (Collection)null);

underTest.addContent(0, new Image());
underTest.addContent(0, (Content)null);
underTest.addContent(0, new Image());
underTest.addContent(0, (Content)null);

underTest.add(new Image());
underTest.add(new Image());
});
}

@Test
Expand All @@ -87,11 +90,13 @@ void testText() {

@Test
void testSetAttribute() {
underTest.setAttribute("attr1", "value1");
underTest.setAttribute("attr1", null);
assertDoesNotThrow(() -> {
underTest.setAttribute("attr1", "value1");
underTest.setAttribute("attr1", null);

underTest.setAttribute("attr1", "value1", NS_TEST);
underTest.setAttribute("attr1", null, NS_TEST);
underTest.setAttribute("attr1", "value1", NS_TEST);
underTest.setAttribute("attr1", null, NS_TEST);
});
}

@Test
Expand Down Expand Up @@ -152,27 +157,29 @@ void testToString() {

@Test
void testFactory() {
underTest.create("sub1");
underTest.createComment("text");
underTest.createDiv();
underTest.createSpan();
underTest.createSpan("text");
underTest.createAnchor();
underTest.createAnchor("href");
underTest.createAnchor("href", "target");
underTest.createImage();
underTest.createImage("src");
underTest.createImage("src", "alt");
underTest.createImage("src", 20, 30);
underTest.createImage("src", "alt", 20, 30);
underTest.createScript();
underTest.createScript("text");
underTest.createNoScript();
underTest.createFigure();
underTest.createFigCaption();
underTest.createVideo();
underTest.createAudio();
underTest.createSource();
assertDoesNotThrow(() -> {
underTest.create("sub1");
underTest.createComment("text");
underTest.createDiv();
underTest.createSpan();
underTest.createSpan("text");
underTest.createAnchor();
underTest.createAnchor("href");
underTest.createAnchor("href", "target");
underTest.createImage();
underTest.createImage("src");
underTest.createImage("src", "alt");
underTest.createImage("src", 20, 30);
underTest.createImage("src", "alt", 20, 30);
underTest.createScript();
underTest.createScript("text");
underTest.createNoScript();
underTest.createFigure();
underTest.createFigCaption();
underTest.createVideo();
underTest.createAudio();
underTest.createSource();
});
}

}

0 comments on commit c07b8b9

Please sign in to comment.