Skip to content
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 @@ -15,11 +15,12 @@ public class KrakenException extends RuntimeException {
private final List<String> errors;

/**
* Creates an exception holding the errors returned by Kraken.
* Creates an exception holding the errors returned by Kraken, whose message lists them separated by commas.
*
* @param errors the errors, as returned by Kraken
*/
public KrakenException(List<String> errors) {
super(errors == null ? null : String.join(", ", errors));
this.errors = errors;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package dev.andstuff.kraken.api.endpoint;

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

import java.util.List;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension;

@ExtendWith(MockitoExtension.class)
class KrakenExceptionTest {

@Test
void should_use_error_as_message_when_kraken_returns_one_error() {
KrakenException unit = new KrakenException(List.of("EAPI:Invalid key"));

assertThat(unit).hasMessage("EAPI:Invalid key");
assertThat(unit.getErrors()).containsExactly("EAPI:Invalid key");
}

@Test
void should_join_errors_in_message_when_kraken_returns_several_errors() {
KrakenException unit = new KrakenException(List.of("EGeneral:Invalid arguments", "EGeneral:Permission denied"));

assertThat(unit).hasMessage("EGeneral:Invalid arguments, EGeneral:Permission denied");
}

@Test
void should_have_no_message_when_kraken_returns_no_error_field() {
KrakenException unit = new KrakenException(null);

assertThat(unit.getMessage()).isNull();
assertThat(unit.getErrors()).isNull();
}
}
Loading