Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made XmlMethodCall public and added a test. #451

Merged
merged 1 commit into from
Apr 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/main/java/org/jpeek/graph/XmlMethodArgs.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ final class XmlMethodArgs implements Text {

@Override
public String asString() throws IOException {
return new Joined(":", this.method.xpath("args/arg/@type")).asString();
return new Joined(
":",
this.method.xpath("op/args/arg/@type")
).asString();
}
}
7 changes: 2 additions & 5 deletions src/main/java/org/jpeek/graph/XmlMethodCall.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,8 @@
* Serialize method call to a string.
*
* @since 1.0
* @todo #440:30min This class XmlMethodCall should be made public
* and a test class named XmlMethodCallTest should be added to
* verify its behaviour.
*/
final class XmlMethodCall implements Text {
public final class XmlMethodCall implements Text {

/**
* XML Call operation.
Expand All @@ -55,7 +52,7 @@ final class XmlMethodCall implements Text {
@Override
public String asString() throws IOException {
return new Joined(
"", this.call.xpath("name/text()").get(0),
"", this.call.xpath("op/name/text()").get(0),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vzurauskas Could you please replace get(0) with
org.cactoos.scalar.ItemAt ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fanifieiev Can you explain why? If the goal is to get more object oriented by replacing method calls with object composition, this will not help, because ItemAt is a Scalar, and we would still need to call value() on it. This would only introduce an indirection without reducing the number of method calls.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vzurauskas Agree

".", new XmlMethodArgs(this.call).asString()
).asString();
}
Expand Down
62 changes: 62 additions & 0 deletions src/test/java/org/jpeek/graph/XmlMethodCallTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2017-2019 Yegor Bugayenko
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.jpeek.graph;

import com.jcabi.xml.XMLDocument;
import java.io.IOException;
import org.cactoos.text.Joined;
import org.hamcrest.core.IsEqual;
import org.junit.jupiter.api.Test;
import org.llorllale.cactoos.matchers.Assertion;

/**
* Test case for {@link XmlMethodCall}.
* @since 0.44
*/
final class XmlMethodCallTest {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vzurauskas Why missing public keyword?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fanifieiev JUnit 5 test classes don't have to be public.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vzurauskas Good to know, thanks


@Test
void hasClassMethodAndArgs() throws IOException {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vzurauskas Why missing public keyword?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fanifieiev JUnit 5 test classes don't have to be public.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vzurauskas Good to know, thanks

new Assertion<>(
"Must have class name, method name and args.",
new XmlMethodCall(
new XMLDocument(
new Joined(
"",
"<op code=\"call\">",
" <name>OverloadMethods.methodOne</name>",
" <args>",
" <arg type=\"Ljava/lang/String\">?</arg>",
" <arg type=\"Z\">?</arg>",
" </args>",
"</op>"
).asString()
)
).asString(),
new IsEqual<>(
"OverloadMethods.methodOne.Ljava/lang/String:Z"
)
).affirm();
}
}