Skip to content

Commit

Permalink
CR carried out
Browse files Browse the repository at this point in the history
  • Loading branch information
zub4t committed Jun 26, 2024
1 parent 8426120 commit a0982ae
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
*
* Contributors:
* Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation
* zub4t - Improving failure detail message
*
*/

Expand All @@ -33,11 +32,7 @@ public StreamFailure(List<String> messages, Reason reason) {
@Override
public String getFailureDetail() {
var str = super.getFailureDetail();
if (str != null && !str.isEmpty()) {
str = reason + ": " + str;
return str;
}
return String.valueOf(reason);
return (str != null && !str.isEmpty()) ? (reason + ": " + str) : (reason + "");
}

public Reason getReason() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0
*
* SPDX-License-Identifier: Apache-2.0
*
* Contributors:
* Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - Initial implementation
*
*/

package org.eclipse.edc.connector.dataplane.spi.pipeline;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.util.Collections;
import java.util.List;
import java.util.stream.Stream;

import static org.assertj.core.api.Assertions.assertThat;
import static org.eclipse.edc.connector.dataplane.spi.pipeline.StreamFailure.Reason.GENERAL_ERROR;
import static org.eclipse.edc.connector.dataplane.spi.pipeline.StreamFailure.Reason.NOT_AUTHORIZED;
import static org.eclipse.edc.connector.dataplane.spi.pipeline.StreamFailure.Reason.NOT_FOUND;

public class StreamFailureTest {
private StreamFailure streamFailure;
private String failureMessage;

@BeforeEach
void setup() {
failureMessage = "FAILURE MESSAGE";
}

@Test
void verify_with_failureDetail_message_startWith_notFound() {

streamFailure = new StreamFailure(List.of(failureMessage), NOT_FOUND);
assertThat(streamFailure.getFailureDetail()).startsWith(NOT_FOUND.toString());
}

@Test
void verify_with_failureDetail_message_startWith_notAuthorized() {

streamFailure = new StreamFailure(List.of(failureMessage), NOT_AUTHORIZED);
assertThat(streamFailure.getFailureDetail()).startsWith(NOT_AUTHORIZED.toString());
}

@Test
void verify_with_failureDetail_message_startWith_generalError() {

streamFailure = new StreamFailure(List.of(failureMessage), GENERAL_ERROR);
assertThat(streamFailure.getFailureDetail()).startsWith(GENERAL_ERROR.toString());
}

@Test
void verify_with_failureDetail_message_only_contains_reason_when_message_is_empty() {

assertThat(Stream.of(StreamFailure.Reason.values())
.allMatch(enumVal -> {
return new StreamFailure(Collections.emptyList(), enumVal)
.getFailureDetail()
.equals(enumVal.toString());
})).isTrue();
}
}

0 comments on commit a0982ae

Please sign in to comment.