Skip to content

Commit

Permalink
fix NPE when convert invalid results (non-exist names)
Browse files Browse the repository at this point in the history
  • Loading branch information
baev committed Feb 16, 2015
1 parent 2237161 commit 641e429
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ import static ru.yandex.qatools.allure.data.utils.TextUtils.generateUid
*/
class DefaultTestCaseConverter implements TestCaseConverter {

public static final String UNKNOWN_STEP_NAME = "UnknownStepName"
public static final String UNKNOWN_TEST_SUITE = "UnknownTestSuite"
public static final String UNKNOWN_TEST_CASE = "UnknownTestCase"

def suiteUids = [:].withDefault {
generateUid();
}
Expand All @@ -48,9 +52,9 @@ class DefaultTestCaseConverter implements TestCaseConverter {
use([PluginUtils, SummaryCategory]) {
result.uid = generateUid();

if (!result.title) {
result.title = TextUtils.humanize(result.name);
}
result.name = source.name ?: UNKNOWN_TEST_CASE;
result.title = result.title ?: TextUtils.humanize(result.name);

result.description = source.convertedDescription;
result.time = source.time;

Expand All @@ -61,10 +65,14 @@ class DefaultTestCaseConverter implements TestCaseConverter {
result.severity = source.severity;
result.testId = source.testId
result.issues = source.issues;

def suiteName = source.suiteName ?: UNKNOWN_TEST_SUITE;
def suiteTitle = source.suiteTitle ?: TextUtils.humanize(suiteName);

result.suite = new AllureTestSuiteInfo(
uid: suiteUids[source.suiteName],
name: source.suiteName,
title: source.suiteTitle ?: source.suiteName ? TextUtils.humanize(source.suiteName) : "Unknown"
name: suiteName,
title: suiteTitle
);
}

Expand All @@ -79,9 +87,8 @@ class DefaultTestCaseConverter implements TestCaseConverter {
def source = context.source;

use([PluginUtils, SummaryCategory]) {
if (!result.title && result.name) {
result.title = TextUtils.humanize(result.name);
}
result.name = result.name ?: UNKNOWN_STEP_NAME;
result.title = result.title ?: TextUtils.humanize(result.name);

result.time = source.time;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ru.yandex.qatools.allure.data.converters

import org.junit.Test
import ru.yandex.qatools.allure.data.io.TestCaseReader
import ru.yandex.qatools.allure.data.utils.TextUtils
import ru.yandex.qatools.allure.model.Attachment
import ru.yandex.qatools.allure.model.Description
import ru.yandex.qatools.allure.model.DescriptionType
Expand All @@ -11,6 +12,8 @@ import ru.yandex.qatools.allure.model.Step
import ru.yandex.qatools.allure.model.TestCaseResult

import static ru.yandex.qatools.allure.config.AllureModelUtils.createSeverityLabel
import static ru.yandex.qatools.allure.data.converters.DefaultTestCaseConverter.UNKNOWN_STEP_NAME
import static ru.yandex.qatools.allure.data.converters.DefaultTestCaseConverter.UNKNOWN_TEST_CASE
import static ru.yandex.qatools.allure.model.SeverityLevel.CRITICAL
import static ru.yandex.qatools.allure.model.SeverityLevel.NORMAL
import static ru.yandex.qatools.allure.model.Status.PASSED
Expand Down Expand Up @@ -296,6 +299,90 @@ class DefaultTestCaseConverterTest {
assert modify.attachments[0].uid
}

@Test
void shouldConvertTestCaseWithoutNameAndTitle() {
def origin = new TestCaseResult()
def modify = converter.convert(origin)

assert modify.name
assert modify.name == UNKNOWN_TEST_CASE

assert modify.title
assert modify.title == TextUtils.humanize(UNKNOWN_TEST_CASE)
}

@Test
void shouldConvertTestCaseWithoutName() {
def origin = new TestCaseResult(title: "some title")
def modify = converter.convert(origin)

assert modify.name
assert modify.name == UNKNOWN_TEST_CASE

assert modify.title
assert modify.title == "some title"
}

@Test
void shouldConvertTestCaseWithoutTitle() {
def origin = new TestCaseResult(name: "someName")
def modify = converter.convert(origin)

assert modify.name
assert modify.name == "someName"

assert modify.title
assert modify.title == "Some name"
}

@Test
void shouldConvertStepWithoutNameAndTitle() {
def origin = new TestCaseResult(
name: "name",
steps: [new Step()]
)
def modify = converter.convert(origin)

assert modify.steps
assert modify.steps.size() == 1
assert modify.steps[0].name
assert modify.steps[0].name == UNKNOWN_STEP_NAME
assert modify.steps[0].title
assert modify.steps[0].title == TextUtils.humanize(UNKNOWN_STEP_NAME)
}

@Test
void shouldConvertStepWithoutName() {
def origin = new TestCaseResult(
name: "name",
steps: [new Step(title: "some title")]
)
def modify = converter.convert(origin)

assert modify.steps
assert modify.steps.size() == 1
assert modify.steps[0].name
assert modify.steps[0].name == UNKNOWN_STEP_NAME
assert modify.steps[0].title
assert modify.steps[0].title == "some title"
}

@Test
void shouldConvertStepWithoutTitle() {
def origin = new TestCaseResult(
name: "name",
steps: [new Step(name: "someName")]
)
def modify = converter.convert(origin)

assert modify.steps
assert modify.steps.size() == 1
assert modify.steps[0].name
assert modify.steps[0].name == "someName"
assert modify.steps[0].title
assert modify.steps[0].title == "Some name"
}

static def checkLabel(List<Label> labels, LabelName name, String expectedValue) {
def found = labels.find { it.name == name.value() }
assert found
Expand Down

0 comments on commit 641e429

Please sign in to comment.