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 code of {@link ReplyException}
   *
   * @throws Exception
   */
  @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 code of {@link IllegalArgumentException}
   *
   * @throws Exception
   */
  @Test
  public void testThrowableToCode_IllegalArgument() throws Exception {
    int expectedCode = 400;

    Throwable throwable = new IllegalArgumentException();

    int statusCode = ThrowableHelper.throwableToCode(throwable);

    assertEquals(expectedCode, statusCode);
  }

  /**
   * Test code of {@link FileNotFoundException}
   *
   * @throws Exception
   */
  @Test
  public void testThrowableToCode_FileNotFound() throws Exception {
    int expectedCode = 404;

    Throwable throwable = new FileNotFoundException();

    int statusCode = ThrowableHelper.throwableToCode(throwable);

    assertEquals(expectedCode, statusCode);
  }

  /**
   * Test code of unknown throwables.
   *
   * @throws Exception
   */
  @Test
  public void testThrowableToCode_Throwable() throws Exception {
    int expectedCode = 500;

    Throwable throwable = new Throwable();

    int statusCode = ThrowableHelper.throwableToCode(throwable);

    assertEquals(expectedCode, statusCode);
  }

  /**
   * Test throwable message
   *
   * @throws Exception
   */
  @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 default message
   *
   * @throws Exception
   */
  @Test
  public void testThrowableToMessage_Default() throws Exception {
    String defaultMessage = "Oops!";

    Throwable throwable = new Throwable();

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

    assertEquals(defaultMessage, message);
  }

}
@@ -32,90 +32,85 @@
 ort 
-io.vertx.core.eventbus.ReplyException;%0Aimport io.vertx.core.eventbus.ReplyFailure;
+static org.junit.Assert.assertEquals;%0A%0Aimport java.io.FileNotFoundException;%0A
 %0Aimp
@@ -137,36 +137,44 @@
 %0Aimport 
-java.io.FileNotFound
+io.vertx.core.eventbus.Reply
 Exceptio
@@ -180,41 +180,50 @@
 on;%0A
-%0A
 import 
-static org.junit.Assert.*
+io.vertx.core.eventbus.ReplyFailure
 ;%0A%0A/
@@ -322,17 +322,16 @@
 rTest %7B%0A
-%0A
   /**%0A  
@@ -373,36 +373,8 @@
 on%7D%0A
-   *%0A   * @throws Exception%0A
    *
@@ -416,17 +416,16 @@
 leToCode
-_
 ReplyExc
@@ -432,33 +432,16 @@
 eption()
- throws Exception
  %7B%0A    i
@@ -463,16 +463,20 @@
  = 505;%0A
+    
 %0A    Thr
@@ -565,16 +565,20 @@
 sage%22);%0A
+    
 %0A    int
@@ -627,33 +627,32 @@
 ode(throwable);%0A
-%0A
     assertEquals
@@ -745,36 +745,8 @@
 on%7D%0A
-   *%0A   * @throws Exception%0A
    *
@@ -788,17 +788,16 @@
 leToCode
-_
 IllegalA
@@ -805,33 +805,16 @@
 gument()
- throws Exception
  %7B%0A    i
@@ -832,24 +832,28 @@
 Code = 400;%0A
+    
 %0A    Throwab
@@ -891,32 +891,36 @@
 entException();%0A
+    
 %0A    int statusC
@@ -961,33 +961,32 @@
 ode(throwable);%0A
-%0A
     assertEquals
@@ -1076,36 +1076,8 @@
 on%7D%0A
-   *%0A   * @throws Exception%0A
    *
@@ -1119,17 +1119,16 @@
 leToCode
-_
 FileNotF
@@ -1133,33 +1133,16 @@
 tFound()
- throws Exception
  %7B%0A    i
@@ -1164,16 +1164,20 @@
  = 404;%0A
+    
 %0A    Thr
@@ -1220,24 +1220,28 @@
 xception();%0A
+    
 %0A    int sta
@@ -1286,33 +1286,32 @@
 ode(throwable);%0A
-%0A
     assertEquals
@@ -1391,36 +1391,8 @@
 es.%0A
-   *%0A   * @throws Exception%0A
    *
@@ -1434,17 +1434,16 @@
 leToCode
-_
 Throwabl
@@ -1445,33 +1445,16 @@
 owable()
- throws Exception
  %7B%0A    i
@@ -1476,16 +1476,20 @@
  = 500;%0A
+    
 %0A    Thr
@@ -1520,24 +1520,28 @@
 hrowable();%0A
+    
 %0A    int sta
@@ -1590,25 +1590,24 @@
 throwable);%0A
-%0A
     assertEq
@@ -1681,36 +1681,8 @@
 age%0A
-   *%0A   * @throws Exception%0A
    *
@@ -1737,33 +1737,16 @@
 essage()
- throws Exception
  %7B%0A    S
@@ -1817,32 +1817,36 @@
 sage = %22Oops!%22;%0A
+    
 %0A    Throwable t
@@ -1884,24 +1884,28 @@
 edMessage);%0A
+    
 %0A    String 
@@ -1969,33 +1969,32 @@
 efaultMessage);%0A
-%0A
     assertEquals
@@ -2062,36 +2062,8 @@
 age%0A
-   *%0A   * @throws Exception%0A
    *
@@ -2108,17 +2108,16 @@
 oMessage
-_
 Default(
@@ -2121,25 +2121,8 @@
 lt()
- throws Exception
  %7B%0A 
@@ -2157,16 +2157,20 @@
 Oops!%22;%0A
+    
 %0A    Thr
@@ -2205,16 +2205,20 @@
 able();%0A
+    
 %0A    Str
@@ -2294,17 +2294,16 @@
 ssage);%0A
-%0A
     asse
@@ -2345,6 +2345,6 @@
   %7D%0A
-%0A
 %7D
+%0A

Clean up ThrowableHelperTest