/*
 * The MIT License
 *
 * Copyright (c) 2017 Marcelo "Ataxexe" Guimarães <ataxexe@devnull.tools>
 *
 * Permission  is hereby granted, free of charge, to any person obtaining
 * a  copy  of  this  software  and  associated  documentation files (the
 * "Software"),  to  deal  in the Software without restriction, including
 * without  limitation  the  rights to use, copy, modify, merge, publish,
 * distribute,  sublicense,  and/or  sell  copies of the Software, and to
 * permit  persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 * The  above  copyright  notice  and  this  permission  notice  shall be
 * included  in  all  copies  or  substantial  portions  of the Software.
 *
 * THE  SOFTWARE  IS  PROVIDED  "AS  IS",  WITHOUT  WARRANTY OF ANY KIND,
 * EXPRESS  OR  IMPLIED,  INCLUDING  BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * IN  NO  EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 * CLAIM,  DAMAGES  OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 * TORT  OR  OTHERWISE,  ARISING  FROM,  OUT OF OR IN CONNECTION WITH THE
 * SOFTWARE   OR   THE   USE   OR   OTHER   DEALINGS  IN  THE  SOFTWARE.
 */

package tools.devnull.boteco.util;

import org.junit.Test;
import tools.devnull.kodo.Spec;

import java.time.LocalDate;
import java.util.Date;
import java.util.function.Function;

import static tools.devnull.kodo.Expectation.performing;
import static tools.devnull.kodo.Expectation.to;

public class ParameterBinderTest {

  @Test
  public void testStringBind() {
    Spec.given(new ParameterBinder<>(String.class))
        .expect(binding("some string"), to().be("some string"))
        .expect(performing(binding("")), to().raise(IllegalArgumentException.class));
  }

  @Test
  public void testDateBind() {
    Spec.given(new ParameterBinder<>(Date.class))
        .expect(binding("2017-02-04"), to().equal(new Date(2017 - 1900, 1, 4)))
        .expect(performing(binding("")), to().raise(IllegalArgumentException.class))
        .expect(performing(binding("string")), to().raise(IllegalArgumentException.class));
  }

  @Test
  public void testLocalDateBind() {
    Spec.given(new ParameterBinder<>(LocalDate.class))
        .expect(binding("2017-02-04"), to().equal(LocalDate.of(2017, 2, 4)))
        .expect(performing(binding("")), to().raise(IllegalArgumentException.class))
        .expect(performing(binding("string")), to().raise(IllegalArgumentException.class));
  }

  @Test
  public void testIntegerBind() {
    Spec.given(new ParameterBinder<>(Integer.class))
        .expect(binding("10"), to().be(10))
        .expect(performing(binding("")), to().raise(IllegalArgumentException.class))
        .expect(performing(binding("string")), to().raise(IllegalArgumentException.class));

    Spec.given(new ParameterBinder<>(int.class))
        .expect(binding("10"), to().be(10))
        .expect(performing(binding("")), to().raise(IllegalArgumentException.class))
        .expect(performing(binding("string")), to().raise(IllegalArgumentException.class));
  }

  @Test
  public void testLongBind() {
    Spec.given(new ParameterBinder<>(Long.class))
        .expect(binding("10000000000"), to().be(10000000000L))
        .expect(performing(binding("")), to().raise(IllegalArgumentException.class))
        .expect(performing(binding("string")), to().raise(IllegalArgumentException.class));

    Spec.given(new ParameterBinder<>(long.class))
        .expect(binding("10000000000"), to().be(10000000000L))
        .expect(performing(binding("")), to().raise(IllegalArgumentException.class))
        .expect(performing(binding("string")), to().raise(IllegalArgumentException.class));
  }

  private <E> Function<ParameterBinder<E>, E> binding(String content) {
    return binder -> binder.apply(content);
  }

}

@@ -1466,26 +1466,19 @@
 ctation.
-performing
+the
 ;%0Aimport
@@ -1726,34 +1726,27 @@
     .expect(
-performing
+the
 (binding(%22%22)
@@ -1979,34 +1979,27 @@
     .expect(
-performing
+the
 (binding(%22%22)
@@ -2057,34 +2057,27 @@
     .expect(
-performing
+the
 (binding(%22st
@@ -2323,34 +2323,27 @@
     .expect(
-performing
+the
 (binding(%22%22)
@@ -2401,34 +2401,27 @@
     .expect(
-performing
+the
 (binding(%22st
@@ -2630,34 +2630,27 @@
     .expect(
-performing
+the
 (binding(%22%22)
@@ -2708,34 +2708,27 @@
     .expect(
-performing
+the
 (binding(%22st
@@ -2887,34 +2887,27 @@
     .expect(
-performing
+the
 (binding(%22%22)
@@ -2965,34 +2965,27 @@
     .expect(
-performing
+the
 (binding(%22st
@@ -3207,34 +3207,27 @@
     .expect(
-performing
+the
 (binding(%22%22)
@@ -3285,34 +3285,27 @@
     .expect(
-performing
+the
 (binding(%22st
@@ -3484,34 +3484,27 @@
     .expect(
-performing
+the
 (binding(%22%22)
@@ -3570,18 +3570,11 @@
 ect(
-performing
+the
 (bin

update test code