Skip to content

Commit

Permalink
Review fixes
Browse files Browse the repository at this point in the history
- use InstanceCreator#newInstance()
- use TestNG exception with detail exception message
- create and link github issue
  • Loading branch information
sankouski-dzmitry committed Dec 7, 2021
1 parent a1f2e3f commit 3c964b8
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Current
New: Yaml parser: implement loadClasses flag (Dzmitry Sankouski)
Fixed: GITHUB-2689: Yaml parser: implement loadClasses flag (Dzmitry Sankouski)
Fixed: GITHUB-2676: NPE is triggered when working with ITestObjectFactory (Krishnan Mahadevan)
Fixed: GITHUB-2674: Run onTestSkipped for each value from data provider (Krishnan Mahadevan)
Fixed: GITHUB-2672: Log real stacktrace when test times out. (cdalexndr)
Expand Down
5 changes: 3 additions & 2 deletions testng-core/src/main/java/org/testng/internal/Yaml.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.Map;
import java.util.function.Consumer;
import org.testng.TestNGException;
import org.testng.internal.objects.InstanceCreator;
import org.testng.util.Strings;
import org.testng.xml.XmlClass;
import org.testng.xml.XmlInclude;
Expand Down Expand Up @@ -378,13 +379,13 @@ public Object newInstance(Node node) {
nodeTuple ->
((ScalarNode) nodeTuple.getKeyNode()).getValue().equals("name"))
.findFirst()
.orElseThrow(RuntimeException::new)
.orElseThrow(() -> new TestNGException("Node 'name' not found"))
.getValueNode();
className = ((ScalarNode) valueNode).getValue();
} else {
className = ((ScalarNode) node).getValue();
}
return c.newInstance(className, loadClasses);
return InstanceCreator.newInstance(c, className, loadClasses);
} catch (Exception e) {
throw new TestNGException("Failed to instantiate class", e);
}
Expand Down
2 changes: 1 addition & 1 deletion testng-core/src/test/java/test/yaml/YamlTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void testXmlDependencyGroups() throws IOException {
assertThat(Yaml.toYaml(actualXmlSuite).toString()).isEqualToNormalizingNewlines(expectedYaml);
}

@Test
@Test(description = "GITHUB-2689")
public void testLoadClassesFlag() throws IOException {
YamlParser yamlParser = new YamlParser();
String yamlSuiteFile = "src/test/resources/yaml/suiteWithNonExistentTest.yaml";
Expand Down

0 comments on commit 3c964b8

Please sign in to comment.