From 6c68ccd4593ccd3c57b8602fc1971231bca31f76 Mon Sep 17 00:00:00 2001 From: volodya-lombrozo Date: Thu, 26 Oct 2023 17:31:47 +0300 Subject: [PATCH 1/2] feat(#185): add unit test for XmlClass#constructors --- .../jeo/representation/xmir/XmlClass.java | 3 - .../jeo/representation/xmir/XmlClassTest.java | 79 +++++++++++++++++++ 2 files changed, 79 insertions(+), 3 deletions(-) create mode 100644 src/test/java/org/eolang/jeo/representation/xmir/XmlClassTest.java diff --git a/src/main/java/org/eolang/jeo/representation/xmir/XmlClass.java b/src/main/java/org/eolang/jeo/representation/xmir/XmlClass.java index 865a1f379..f5439f1fe 100644 --- a/src/main/java/org/eolang/jeo/representation/xmir/XmlClass.java +++ b/src/main/java/org/eolang/jeo/representation/xmir/XmlClass.java @@ -53,9 +53,6 @@ public XmlClass(final Node xml) { /** * Retrieve all constructors from XMIR. * @return List of constructors. - * @todo #167:60min Add unit tests for 'constructors' method. - * Currently we don't have unit tests for that method. So, it makes sense to add - * them to keep code safe and clear. */ public List constructors() { return this.objects().filter( diff --git a/src/test/java/org/eolang/jeo/representation/xmir/XmlClassTest.java b/src/test/java/org/eolang/jeo/representation/xmir/XmlClassTest.java new file mode 100644 index 000000000..3b20b7ac6 --- /dev/null +++ b/src/test/java/org/eolang/jeo/representation/xmir/XmlClassTest.java @@ -0,0 +1,79 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2016-2023 Objectionary.com + * + * 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.eolang.jeo.representation.xmir; + +import com.jcabi.xml.XML; +import com.jcabi.xml.XMLDocument; +import org.hamcrest.MatcherAssert; +import org.hamcrest.Matchers; +import org.junit.jupiter.api.Test; + +/** + * Test case for {@link XmlClass}. + * @since 0.1 + */ +class XmlClassTest { + + @Test + void retrievesConstructor() { + final XML doc = new XMLDocument( + String.join( + "", + "", + "", + "" + ) + ); + MatcherAssert.assertThat( + String.format( + "%s should retrieve exactly one constructor from %n%s%n", + XmlClass.class.getSimpleName(), + doc + ), + new XmlClass(doc.node().getFirstChild()).constructors(), + Matchers.hasSize(1) + ); + } + + @Test + void doesNotRetrieveConstructor() { + final XML doc = new XMLDocument( + String.join( + "", + "", + "", + "" + ) + ); + MatcherAssert.assertThat( + String.format( + "%s should not retrieve any constructor from %n%s%n", + XmlClass.class.getSimpleName(), + doc + ), + new XmlClass(doc.node().getFirstChild()).constructors(), + Matchers.empty() + ); + } +} \ No newline at end of file From 863d36906b3155d8da669394e8721ab12971ed3c Mon Sep 17 00:00:00 2001 From: volodya-lombrozo Date: Thu, 26 Oct 2023 17:32:24 +0300 Subject: [PATCH 2/2] feat(#185): fix all qulice suggestions --- .../java/org/eolang/jeo/representation/xmir/XmlClassTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/eolang/jeo/representation/xmir/XmlClassTest.java b/src/test/java/org/eolang/jeo/representation/xmir/XmlClassTest.java index 3b20b7ac6..87affa589 100644 --- a/src/test/java/org/eolang/jeo/representation/xmir/XmlClassTest.java +++ b/src/test/java/org/eolang/jeo/representation/xmir/XmlClassTest.java @@ -76,4 +76,4 @@ void doesNotRetrieveConstructor() { Matchers.empty() ); } -} \ No newline at end of file +}