Skip to content

Commit

Permalink
fix npe (fixes #522, via #525)
Browse files Browse the repository at this point in the history
  • Loading branch information
baev authored Aug 4, 2017
1 parent d264c30 commit 6249bdb
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
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");
}
}

0 comments on commit 6249bdb

Please sign in to comment.