package com.dhemery.expressions;

import com.dhemery.expressions.diagnosing.Diagnosis;
import com.dhemery.expressions.diagnosing.Named;
import com.dhemery.expressions.helpers.Throwables;
import org.junit.Test;

import java.util.function.Function;

import static java.util.function.Function.identity;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;

public class SubjectFunctionMatcherExpressionTests {

    public static class AssertThat {
        Function<String, String> function = Named.function("function", String::toUpperCase);

        @Test
        public void returnsWithoutThrowing_ifMatcherAcceptsFunctionOfSubject() {
            Expressions.assertThat("subject", function, is(anything()));
        }

        @Test(expected = AssertionError.class)
        public void throwsAssertionError_ifMatcherRejectsFunctionOfSubject() {
            Expressions.assertThat("subject", function, not(anything()));
        }

        @Test
        public void errorMessage_describesSubjectFunctionMatcherAndMismatch() {
            String message = Throwables.messageThrownBy(() -> Expressions.assertThat("subject", function, not(anything())));

            assertThat(message, is(Diagnosis.of("subject", function, not(anything()), function.apply("subject"))));
        }
    }

    public static class SatisfiedThat {
        @Test
        public void returnsTrue_ifMatcherAcceptsFunctionOfSubject() {
            boolean result = Expressions.satisfiedThat("subject", identity(), is(anything()));

            assertThat(result, is(true));
        }

        @Test
        public void returnsFalse_ifMatcherRejectsFunctionOfSubject() {
            boolean result = Expressions.satisfiedThat("subject", identity(), not(anything()));

            assertThat(result, is(false));
        }
    }
}

@@ -201,14 +201,63 @@
 nit.
+jupiter.api.Nested;%0Aimport org.junit.jupiter.api.
 Test;%0A
-
 %0Aimp
@@ -433,16 +433,77 @@
 chers.*;
+%0Aimport static org.junit.jupiter.api.Assertions.assertThrows;
 %0A%0Apublic
@@ -550,16 +550,28 @@
 ests %7B%0A%0A
+    @Nested%0A
     publ
@@ -569,31 +569,24 @@
 %0A    public 
-static 
 class Assert
@@ -882,41 +882,8 @@
 Test
-(expected = AssertionError.class)
 %0A   
@@ -950,32 +950,114 @@
 onOfSubject() %7B%0A
+            assertThrows(%0A                    AssertionError.class, () -%3E%0A        
             Expr
@@ -1104,32 +1104,33 @@
 not(anything()))
+)
 ;%0A        %7D%0A%0A   
@@ -1475,24 +1475,36 @@
    %7D%0A    %7D%0A%0A
+    @Nested%0A
     public s
@@ -1502,23 +1502,16 @@
  public 
-static 
 class Sa

Convert more tests to JUnit 5