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

Fix npe (fixes #522) #525

Merged
merged 1 commit into from
Aug 4, 2017
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
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ public Optional<String> findOneLabel(final LabelName name) {
public Optional<String> findOneLabel(final String name) {
return getLabels().stream()
.filter(label -> name.equals(label.getName()))
.map(Label::getValue)
.findAny();
.findAny()
.map(Label::getValue);
}

public void addLabelIfNotExists(final LabelName name, final String value) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package io.qameta.allure.entity;

import org.junit.Test;

import java.util.List;
import java.util.Optional;

import static org.assertj.core.api.Assertions.assertThat;

/**
* @author charlie (Dmitry Baev).
*/
public class LabelsTest {

@Test
public void shouldFindLabelsInEmptyArray() throws Exception {
final Optional<String> found = new TestResult().findOneLabel("hey");
assertThat(found)
.isEmpty();
}

@Test
public void shouldFindOneWithNullValue() throws Exception {
final TestResult result = new TestResult();
result.getLabels().add(new Label().setName("hey").setValue(null));
final Optional<String> found = result.findOneLabel("hey");
assertThat(found)
.isEmpty();
}

@Test
public void shouldFindAllWithNullValue() throws Exception {
final TestResult result = new TestResult();
result.getLabels().add(new Label().setName("hey").setValue(null));
result.getLabels().add(new Label().setName("hey").setValue("a"));
result.getLabels().add(new Label().setName("hey").setValue("b"));
final List<String> found = result.findAllLabels("hey");
assertThat(found)
.containsExactlyInAnyOrder(null, "a", "b");
}
}