pibizza commented on code in PR #6254:
URL:
https://github.com/apache/incubator-kie-drools/pull/6254#discussion_r1957835129
##########
drools-scenario-simulation/drools-scenario-simulation-backend/src/test/java/org/drools/scenariosimulation/backend/util/ScenarioSimulationXMLPersistenceTest.java:
##########
@@ -349,24 +353,58 @@ public void migrateIfNecessary() throws Exception {
}
@Test
- public void extractVersion() {
- String version = instance.extractVersion("<ScenarioSimulationModel
version=\"1.0\" version=\"1.1\">");
- assertThat(version).isEqualTo("1.0");
+ public void extractVersionNullDocument() {
+ assertThatThrownBy(() -> instance.extractVersion(null))
+ .isInstanceOf(IllegalArgumentException.class);
}
@Test
- public void extractVersionWhenXmlPrologIsPresent() {
- String version = instance.extractVersion("<?xml version=\"1.0\"
encoding=\"UTF-8\"?>\n" +
-
"<ScenarioSimulationModel version=\"1.1\">");
+ public void extractVersionMissingAttribute() {
+ assertThatThrownBy(() ->
instance.extractVersion(DOMParserUtil.getDocument("<ScenarioSimulationModel
/>")))
+ .isInstanceOf(IllegalArgumentException.class);
+ }
+
+ @Test
+ public void extractVersionWhenXmlPrologIsPresent() throws
ParserConfigurationException, IOException, SAXException {
+ String version =
instance.extractVersion(DOMParserUtil.getDocument("<?xml version=\"1.0\"
encoding=\"UTF-8\"?>\n" +
+ "<ScenarioSimulationModel version=\"1.1\" />"));
assertThat(version).isEqualTo("1.1");
}
@Test
- public void extractVersionWhenMoreVersionAttributesArePresent() {
- String version = instance.extractVersion("<?xml version=\"1.0\"
encoding=\"UTF-8\"?>\n" +
-
"<ScenarioSimulationModel version=\"1.2\">\n" +
- "<someUnknownTag
version=\"1.1\"/>\n" +
-
"</ScenarioSimulationModel>");
+ public void
extractVersionWhenXmlPrologIsPresentAndWithMultipleAttributes1() throws
ParserConfigurationException, IOException, SAXException {
+ String version =
instance.extractVersion(DOMParserUtil.getDocument("<?xml version=\"1.0\"
encoding=\"UTF-8\"?>\n" +
+ "<ScenarioSimulationModel version=\"1.1\"
attribute1=\"whatever\" />"));
+ assertThat(version).isEqualTo("1.1");
+ }
+
+ @Test
+ public void
extractVersionWhenXmlPrologIsPresentAndWithMultipleAttributes2() throws
ParserConfigurationException, IOException, SAXException {
+ String version =
instance.extractVersion(DOMParserUtil.getDocument("<?xml version=\"1.0\"
encoding=\"UTF-8\"?>\n" +
+ "<ScenarioSimulationModel attribute1=\"whatever\"
version=\"1.2\" />"));
+ assertThat(version).isEqualTo("1.2");
+ }
+
+ @Test
+ public void
extractVersionWhenXmlPrologIsPresentAndWithMultipleAttributes3() throws
ParserConfigurationException, IOException, SAXException {
+ String version =
instance.extractVersion(DOMParserUtil.getDocument("<?xml version=\"1.0\"
encoding=\"UTF-8\"?>\n" +
+ "<ScenarioSimulationModel attribute2=\"whatever\"
version=\"1.3\" attribute1=\"whatever\" />"));
+ assertThat(version).isEqualTo("1.3");
+ }
+
+ @Test
+ public void
extractVersionWhenXmlPrologIsPresentAndWithMultipleAttributes4() throws
ParserConfigurationException, IOException, SAXException {
+ String version =
instance.extractVersion(DOMParserUtil.getDocument("<?xml version=\"1.0\"
encoding=\"UTF-8\"?>\n" +
+ "<ScenarioSimulationModel attribute2=\"whatever\"
attribute1=\"whatever\" version=\"1.4\" />"));
+ assertThat(version).isEqualTo("1.4");
+ }
+
Review Comment:
@yesamer I would suggest something that describe your use case. In Junit 5
you can add a string for a specific test name. In this case add some infos in
the name and restructure grouping for cases. So you can have a test where you
have one entry (version or attribute), one case where you have two entries
(version and attribute, times the various possible cases good or bad) and
finally one case where you have three entries (version and two attributes,
times the two possible values.) I expect order is not relevant, so it should
not be present in the tests. at this point the name of the test could be
extractXXX_version, extract XXX_version_attribute,
extractXXX_version_twoattributes. You can go for different groupings, if you
prefer, but that is the general idea.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]