package io.georocket.util;

import io.vertx.core.eventbus.ReplyException;
import io.vertx.core.eventbus.ReplyFailure;
import org.junit.Test;

import java.io.FileNotFoundException;

import static org.junit.Assert.*;

/**
 * Test {@link ThrowableHelper}
 * @author Andrej Sajenko
 */
public class ThrowableHelperTest {

  @Test
  public void testThrowableToCode_ReplyException() throws Exception {
    int expectedCode = 505;

    Throwable throwable = new ReplyException(ReplyFailure.NO_HANDLERS, expectedCode, "Message");

    int statusCode = ThrowableHelper.throwableToCode(throwable);

    assertEquals(expectedCode, statusCode);
  }

  @Test
  public void testThrowableToCode_IllegalArgument() throws Exception {
    int expectedCode = 400;

    Throwable throwable = new IllegalArgumentException();

    int statusCode = ThrowableHelper.throwableToCode(throwable);

    assertEquals(expectedCode, statusCode);
  }

  @Test
  public void testThrowableToCode_FileNotFound() throws Exception {
    int expectedCode = 404;

    Throwable throwable = new FileNotFoundException();

    int statusCode = ThrowableHelper.throwableToCode(throwable);

    assertEquals(expectedCode, statusCode);
  }

  @Test
  public void testThrowableToCode_Throwable() throws Exception {
    int expectedCode = 500;

    Throwable throwable = new Throwable();

    int statusCode = ThrowableHelper.throwableToCode(throwable);

    assertEquals(expectedCode, statusCode);
  }

  @Test
  public void testThrowableToMessage_Message() throws Exception {
    String expectedMessage = "A Error happen!";
    String defaultMessage = "Oops!";

    Throwable throwable = new Throwable(expectedMessage);

    String message = ThrowableHelper.throwableToMessage(throwable, defaultMessage);

    assertEquals(expectedMessage, message);
  }

  @Test
  public void testThrowableToMessage_Default() throws Exception {
    String defaultMessage = "Oops!";

    Throwable throwable = new Throwable();

    String message = ThrowableHelper.throwableToMessage(throwable, defaultMessage);

    assertEquals(defaultMessage, message);
  }

}
@@ -311,24 +311,105 @@
 Test %7B%0A%0A
+  /**%0A   * Test code of %7B@link ReplyException%7D%0A   *%0A   * @throws Exception%0A   */%0A
   @Test%0A
   public
@@ -392,32 +392,32 @@
 n%0A   */%0A  @Test%0A
-
   public void te
@@ -704,32 +704,123 @@
 atusCode);%0A  %7D%0A%0A
+  /**%0A   * Test code of %7B@link IllegalArgumentException%7D%0A   *%0A   * @throws Exception%0A   */%0A
   @Test%0A  public
@@ -1077,32 +1077,120 @@
 atusCode);%0A  %7D%0A%0A
+  /**%0A   * Test code of %7B@link FileNotFoundException%7D%0A   *%0A   * @throws Exception%0A   */%0A
   @Test%0A  public
@@ -1441,32 +1441,110 @@
 atusCode);%0A  %7D%0A%0A
+  /**%0A   * Test code of unknown throwables.%0A   *%0A   * @throws Exception%0A   */%0A
   @Test%0A  public
@@ -1780,32 +1780,100 @@
 atusCode);%0A  %7D%0A%0A
+  /**%0A   * Test throwable message%0A   *%0A   * @throws Exception%0A   */%0A
   @Test%0A  public
@@ -2209,16 +2209,82 @@
 );%0A  %7D%0A%0A
+  /**%0A   * Test default message%0A   *%0A   * @throws Exception%0A   */%0A
   @Test%0A

add javadoc to ThrowableHelperTest