Skip to content

Commit

Permalink
java:S5838: Chained AssertJ assertions should be simplified to the co…
Browse files Browse the repository at this point in the history
…rresponding dedicated assertion
  • Loading branch information
616slayer616 committed Jan 18, 2023
1 parent 4e9c105 commit 3fc4327
Show file tree
Hide file tree
Showing 18 changed files with 80 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void testFunctionArguments() {
assertThat(function.getSourceCodeLocation()).isNull();
assertThat(function.getArguments()).isNotNull();
assertThat(function.getArguments().getChildren()).asList().isNotEmpty();
assertThat(function.toString()).isEqualTo("rgb(test)");
assertThat(function).hasToString("rgb(test)");
assertThat(function.getValue()).isEqualTo("rgb(test)");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void testPropertyNodeCreation1() {
assertThat(property.getParent()).isNull();
assertThat(property.getSourceCodeLocation()).isNull();
assertThat(property.isCustom()).isFalse();
assertThat(property.toString()).isEqualTo("color");
assertThat(property).hasToString("color");
assertThat(property.getProperty().hasPositionalParameters()).isFalse();
}

Expand All @@ -47,7 +47,7 @@ void testPropertyNodeCreation2() {
assertThat(property.getParent()).isNull();
assertThat(property.getSourceCodeLocation()).isNull();
assertThat(property.isCustom()).isFalse();
assertThat(property.toString()).isEqualTo("color");
assertThat(property).hasToString("color");
assertThat(property.getProperty().hasPositionalParameters()).isFalse();
}

Expand All @@ -60,7 +60,7 @@ void testPropertyNodeCreation3() {
assertThat(property.getParent()).isNull();
assertThat(property.getSourceCodeLocation()).isEqualTo(codeLoc);
assertThat(property.isCustom()).isFalse();
assertThat(property.toString()).isEqualTo("color");
assertThat(property).hasToString("color");
assertThat(property.getProperty().hasPositionalParameters()).isFalse();
}

Expand All @@ -70,7 +70,7 @@ void testCustomPropertyNodeCreation() {
assertThat(property.getParent()).isNull();
assertThat(property.getSourceCodeLocation()).isNull();
assertThat(property.isCustom()).isTrue();
assertThat(property.toString()).isEqualTo("--cOloR");
assertThat(property).hasToString("--cOloR");
assertThat(property.getProperty().hasPositionalParameters()).isFalse();
}

Expand All @@ -82,19 +82,19 @@ void testPropertyNodePositionDependentValues() {
CssPropertyNode margin = new CssPropertyNode("margin", null);
CssPropertyNode padding = new CssPropertyNode("padding", null);

assertThat(borderColor.toString()).isEqualTo("border-color");
assertThat(borderColor).hasToString("border-color");
assertThat(borderColor.getProperty().hasPositionalParameters()).isTrue();

assertThat(borderStyle.toString()).isEqualTo("border-style");
assertThat(borderStyle).hasToString("border-style");
assertThat(borderStyle.getProperty().hasPositionalParameters()).isTrue();

assertThat(borderWidth.toString()).isEqualTo("border-width");
assertThat(borderWidth).hasToString("border-width");
assertThat(borderWidth.getProperty().hasPositionalParameters()).isTrue();

assertThat(margin.toString()).isEqualTo("margin");
assertThat(margin).hasToString("margin");
assertThat(margin.getProperty().hasPositionalParameters()).isTrue();

assertThat(padding.toString()).isEqualTo("padding");
assertThat(padding).hasToString("padding");
assertThat(padding.getProperty().hasPositionalParameters()).isTrue();
}

Expand Down Expand Up @@ -163,12 +163,12 @@ void testPropertyNodeCopy() {
assertThat(property2.getSourceCodeLocation()).isNull();
assertThat(property2Copy.getSourceCodeLocation()).isNull();

assertThat(property.toString()).isEqualTo("color");
assertThat(propertyCopy.toString()).isEqualTo("color");
assertThat(property1.toString()).isEqualTo("border-color");
assertThat(property1Copy.toString()).isEqualTo("border-color");
assertThat(property2.toString()).isEqualTo("--theme-color");
assertThat(property2Copy.toString()).isEqualTo("--theme-color");
assertThat(property).hasToString("color");
assertThat(propertyCopy).hasToString("color");
assertThat(property1).hasToString("border-color");
assertThat(property1Copy).hasToString("border-color");
assertThat(property2).hasToString("--theme-color");
assertThat(property2Copy).hasToString("--theme-color");

assertThat(property.getProperty().isRecognizedProperty()).isTrue();
assertThat(propertyCopy.getProperty().isRecognizedProperty()).isTrue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,6 @@ private void testSpecificity(String selector, String expected) {
assertThat(node).isInstanceOf(CssRulesetNode.class);
CssRulesetNode rulesetNode = (CssRulesetNode) node;
CssSelectorNode selectorNode = rulesetNode.getSelectors().getChildAt(0);
assertThat(selectorNode.getSpecificity().toString()).isEqualTo(expected);
assertThat(selectorNode.getSpecificity()).hasToString(expected);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ void testVisitBlockChildrenState1() {
state.transitionToNextState();
assertThat(visitController.getStateStack().size()).isEqualTo(2);
assertThat(visitController.getStateStack().getTop()).isInstanceOf(VisitDefinitionState.class);
assertThat(state.currentIndex).isEqualTo(0);
assertThat(state.currentIndex).isZero();

visitController.getStateStack().getTop().transitionToNextState();
assertThat(visitController.getStateStack().size()).isEqualTo(3);
Expand Down Expand Up @@ -372,13 +372,13 @@ void testVisitBlockChildrenState2() {
state.transitionToNextState();
assertThat(visitController.getStateStack().size()).isEqualTo(2);
assertThat(visitController.getStateStack().getTop()).isInstanceOf(VisitDefinitionState.class);
assertThat(state.currentIndex).isEqualTo(0);
assertThat(state.currentIndex).isZero();

state.removeCurrentChild();
assertThat(state.currentIndex).isEqualTo(0);
assertThat(state.currentIndex).isZero();

state.removeCurrentChild();
assertThat(state.currentIndex).isEqualTo(0);
assertThat(state.currentIndex).isZero();

visitController.getStateStack().getTop().transitionToNextState();
assertThat(visitController.getStateStack().size()).isEqualTo(3);
Expand All @@ -387,7 +387,7 @@ void testVisitBlockChildrenState2() {
state.transitionToNextState();
state.transitionToNextState();
assertThat(visitController.getStateStack().isEmpty()).isTrue();
assertThat(state.currentIndex).isEqualTo(0);
assertThat(state.currentIndex).isZero();
}

@Test
Expand All @@ -413,17 +413,17 @@ void testVisitBlockChildrenState3() {
state.transitionToNextState();
assertThat(visitController.getStateStack().size()).isEqualTo(2);
assertThat(visitController.getStateStack().getTop()).isInstanceOf(VisitDefinitionState.class);
assertThat(state.currentIndex).isEqualTo(0);
assertThat(state.currentIndex).isZero();

state.replaceCurrentBlockChildWith(
Lists.newArrayList(
new CssDefinitionNode(new CssLiteralNode("")),
new CssDefinitionNode(new CssLiteralNode(""))),
true);
assertThat(state.currentIndex).isEqualTo(0);
assertThat(state.currentIndex).isZero();

state.removeCurrentChild();
assertThat(state.currentIndex).isEqualTo(0);
assertThat(state.currentIndex).isZero();

visitController.getStateStack().getTop().transitionToNextState();
assertThat(visitController.getStateStack().size()).isEqualTo(3);
Expand Down Expand Up @@ -583,7 +583,7 @@ void testVisitFunctionNode() {
inOrder.verify(testVisitor).leaveDefinition(def);
inOrder.verifyNoMoreInteractions();

assertThat(argCaptor.getValue().toString()).isEqualTo(argument.toString());
assertThat(argCaptor.getValue()).hasToString(argument.toString());
}

@Test
Expand Down Expand Up @@ -826,7 +826,7 @@ public boolean enterValueNode(CssValueNode value) {
}
});

assertThat(composite.toString()).isEqualTo("foo,baz,quux");
assertThat(composite).hasToString("foo,baz,quux");

CssValueNode fooValue = composite.getValues().get(0);
assertThat(fooValue.getParent()).isSameAs(composite);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ void testCreateFunctionComments() throws Exception {
assertThat(getFirstActualNode()).isInstanceOf(CssUnknownAtRuleNode.class);
CssUnknownAtRuleNode def = (CssUnknownAtRuleNode) getFirstActualNode();
int defComments = def.getComments().size();
assertThat(defComments).isEqualTo(0);
assertThat(defComments).isZero();
CssValueNode valueNode = def.getParameters().get(0);
assertThat(valueNode).isInstanceOf(CssFunctionNode.class);
CssFunctionNode functionNode = (CssFunctionNode) valueNode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ void testEnterDeclaration2() {
BiDiFlipper pass = new BiDiFlipper(tree.getMutatingVisitController(),
true, true);
pass.runPass();
assertThat(tree.getRoot().getBody().toString())
.isEqualTo(
assertThat(tree.getRoot().getBody())
.hasToString(
"[[foo]{["
+ "padding:[5px, 3px, 2px, 1px], "
+ "font:[90%], "
Expand Down Expand Up @@ -205,8 +205,8 @@ void testSubPercentValues() {
BiDiFlipper pass = new BiDiFlipper(tree.getMutatingVisitController(),
true, true);
pass.runPass();
assertThat(tree.getRoot().getBody().toString())
.isEqualTo(
assertThat(tree.getRoot().getBody())
.hasToString(
"[[foo]{["
+ "background-position-x:[98.87654322%], "
+ "-ms-background-position-x:[97.5%]"
Expand Down Expand Up @@ -262,8 +262,8 @@ void testBidiImportant() {
BiDiFlipper pass = new BiDiFlipper(tree.getMutatingVisitController(),
true, true);
pass.runPass();
assertThat(tree.getRoot().getBody().toString())
.isEqualTo(
assertThat(tree.getRoot().getBody())
.hasToString(
"[[foo]{["
+ "margin:[1px, 4px, 3px, 2px, !important], "
+ "border-radius:[2px, 1px, !important], "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ void testEnterValueNode1() {
ColorValueOptimizer pass = new ColorValueOptimizer(
tree.getMutatingVisitController());
pass.runPass();
assertThat(tree.getRoot().getBody().toString()).isEqualTo("[[foo]{[color:[#123]]}]");
assertThat(tree.getRoot().getBody()).hasToString("[[foo]{[color:[#123]]}]");
}

@Test
Expand All @@ -91,7 +91,7 @@ void testEnterValueNode2() {
ColorValueOptimizer pass = new ColorValueOptimizer(
tree.getMutatingVisitController());
pass.runPass();
assertThat(tree.getRoot().getBody().toString()).isEqualTo("[[foo]{[color:[#123344]]}]");
assertThat(tree.getRoot().getBody()).hasToString("[[foo]{[color:[#123344]]}]");
}

private CssNumericNode createNumericNode(String value) {
Expand Down Expand Up @@ -137,7 +137,7 @@ void testEnterFunctionNode1() {
ColorValueOptimizer pass = new ColorValueOptimizer(
tree.getMutatingVisitController());
pass.runPass();
assertThat(tree.getRoot().getBody().toString()).isEqualTo("[[foo]{[color:[#0f0]]}]");
assertThat(tree.getRoot().getBody()).hasToString("[[foo]{[color:[#0f0]]}]");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void testCreateComponentNode1() throws Exception {
assertThat(comp.getName().getValue()).isEqualTo("CSS_X");
assertThat(comp.getParentName()).isNull();
assertThat(comp.isAbstract()).isFalse();
assertThat(comp.getBlock().toString()).isEqualTo("[@def[X, Y]]");
assertThat(comp.getBlock()).hasToString("[@def[X, Y]]");
}

@Test
Expand All @@ -54,7 +54,7 @@ void testCreateComponentNode2() throws Exception {
assertThat(comp.getName().getValue()).isEqualTo("CSS_X");
assertThat(comp.getParentName()).isNull();
assertThat(comp.isAbstract()).isTrue();
assertThat(comp.getBlock().toString()).isEqualTo("[@def[X, Y]]");
assertThat(comp.getBlock()).hasToString("[@def[X, Y]]");
}

@Test
Expand All @@ -70,7 +70,7 @@ void testCreateComponentNode3() throws Exception {
assertThat(comp.getParentName()).isNotNull();
assertThat(comp.getParentName().getValue()).isEqualTo("CSS_X");
assertThat(comp.isAbstract()).isFalse();
assertThat(comp.getBlock().toString()).isEqualTo("[@def[X, Y]]");
assertThat(comp.getBlock()).hasToString("[@def[X, Y]]");
}

@Test
Expand All @@ -81,7 +81,7 @@ void testImplicitlyNamedComponent() throws Exception {
assertThat(comp.getName().getValue()).isSameAs(CssComponentNode.IMPLICIT_NODE_NAME);
assertThat(comp.getParentName()).isNull();
assertThat(comp.isAbstract()).isFalse();
assertThat(comp.getBlock().toString()).isEqualTo("[@def[X, Y]]");
assertThat(comp.getBlock()).hasToString("[@def[X, Y]]");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ void testCreatePageNode() throws Exception {
assertThat(getFirstActualNode()).isInstanceOf(CssPageRuleNode.class);
CssPageRuleNode pageRule = (CssPageRuleNode) getFirstActualNode();
assertThat(pageRule.getName().getValue()).isEqualTo("page");
assertThat(pageRule.getParametersCount()).isEqualTo(0);
assertThat(pageRule.getParametersCount()).isZero();
}

@Test
Expand Down Expand Up @@ -241,7 +241,7 @@ void testCreatePageInMedia() throws Exception {
CssPageRuleNode pageRule =
(CssPageRuleNode) mediaRule.getBlock().getChildAt(0);
assertThat(pageRule.getName().getValue()).isEqualTo("page");
assertThat(pageRule.getParametersCount()).isEqualTo(0);
assertThat(pageRule.getParametersCount()).isZero();
}

@Test
Expand Down Expand Up @@ -345,7 +345,7 @@ void testCreateFontNode() throws GssParserException {
assertThat(getFirstActualNode()).isInstanceOf(CssFontFaceNode.class);
CssFontFaceNode fontFace = (CssFontFaceNode) getFirstActualNode();
assertThat(fontFace.getName().getValue()).isEqualTo("font-face");
assertThat(fontFace.getParametersCount()).isEqualTo(0);
assertThat(fontFace.getParametersCount()).isZero();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ void testLoopParametersReplacement() throws Exception {
parseAndRun("@for $i from FOO to BAR step BAZ {}");
assertThat(getFirstActualNode()).isInstanceOf(CssForLoopRuleNode.class);
CssForLoopRuleNode loop = (CssForLoopRuleNode) getFirstActualNode();
assertThat(loop.getFrom().toString()).isEqualTo("2");
assertThat(loop.getTo().toString()).isEqualTo("7");
assertThat(loop.getStep().toString()).isEqualTo("3");
assertThat(loop.getFrom()).hasToString("2");
assertThat(loop.getTo()).hasToString("7");
assertThat(loop.getStep()).hasToString("3");
}

@Test
Expand All @@ -56,7 +56,7 @@ void testValueInDefinitionReplacement() throws Exception {
assertThat(getFirstActualNode()).isInstanceOf(CssDefinitionNode.class);
CssDefinitionNode definition = (CssDefinitionNode) getFirstActualNode();
assertThat(definition.getChildren()).asList().hasSize(1);
assertThat(definition.getChildAt(0).toString()).isEqualTo("2");
assertThat(definition.getChildAt(0)).hasToString("2");
}

@Test
Expand All @@ -65,6 +65,6 @@ void testValueInArgumentReplacement() throws Exception {
assertThat(getFirstActualNode()).isInstanceOf(CssDefinitionNode.class);
CssDefinitionNode definition = (CssDefinitionNode) getFirstActualNode();
assertThat(definition.getChildren()).asList().hasSize(1);
assertThat(definition.getChildAt(0).toString()).isEqualTo("f(7)");
assertThat(definition.getChildAt(0)).hasToString("f(7)");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ void testMixedSubtree() throws Exception {
.isFalse();
CssDeclarationBlockNode block =
findFirstNodeOf(CssDeclarationBlockNode.class);
assertThat(block.getSourceCodeLocation() == null || block.getSourceCodeLocation().isUnknown())
assertThat(block.getSourceCodeLocation()==null || block.getSourceCodeLocation().isUnknown())
.as("There should be a node with an known location")
.isFalse();

Expand Down Expand Up @@ -149,7 +149,7 @@ void testMixedSubtree() throws Exception {
}
// For good measure: some specific, empirical, and reasonable-looking
// assertions.
assertThat(actual.getBeginCharacterIndex()).isEqualTo(0);
assertThat(actual.getBeginCharacterIndex()).isZero();
assertThat(actual.getEndCharacterIndex()).isEqualTo(19);
}
}
Loading

0 comments on commit 3fc4327

Please sign in to comment.