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 java.util.function.Predicate;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;

public class SubjectFunctionPredicateExpressionTests {
    private static final String SUBJECT = "subject";
    private static final Function<String, String> FUNCTION = Named.function("function", String::toUpperCase);
    private static final Predicate<String> ANY_VALUE = Named.predicate("any value", t -> true);

    public static class AssertThat {
        @Test
        public void returnsWithoutThrowing_ifPredicateAcceptsFunctionOfSubject() {
            Expressions.assertThat(SUBJECT, FUNCTION, ANY_VALUE);
        }

        @Test(expected = AssertionError.class)
        public void throwsAssertionError_ifPredicateRejectsFunctionOfSubject() {
            Expressions.assertThat(SUBJECT, FUNCTION, ANY_VALUE.negate());
        }

        @Test
        public void errorMessage_describesSubjectFunctionPredicateAndDerivedValue() {
            String message = Throwables.messageThrownBy(() -> Expressions.assertThat(SUBJECT, FUNCTION, ANY_VALUE.negate()));

            assertThat(message, is(Diagnosis.of(SUBJECT, FUNCTION, ANY_VALUE.negate(), FUNCTION.apply(SUBJECT))));
        }
    }

    public static class SatisfiedThat {
        @Test
        public void returnsTrue_ifPredicateAcceptsFunctionOfSubject() {
            boolean result = Expressions.satisfiedThat(SUBJECT, FUNCTION, ANY_VALUE);
            assertThat(result, is(true));
        }

        @Test
        public void returnsFalse_ifPredicateRejectsFunctionOfSubject() {
            boolean result = Expressions.satisfiedThat(SUBJECT, FUNCTION, ANY_VALUE.negate());
            assertThat(result, is(false));
        }
    }
}

@@ -140,50 +140,36 @@
 ort 
-com.dhemery.expressions.helpers.Throwables
+org.junit.jupiter.api.Nested
 ;%0Aim
@@ -183,16 +183,28 @@
 g.junit.
+jupiter.api.
 Test;%0A%0Ai
@@ -368,16 +368,77 @@
 hers.is;
+%0Aimport static org.junit.jupiter.api.Assertions.assertThrows;
 %0A%0Apublic
@@ -742,24 +742,36 @@
  -%3E true);%0A%0A
+    @Nested%0A
     public s
@@ -986,41 +986,8 @@
 Test
-(expected = AssertionError.class)
 %0A   
@@ -1080,70 +1080,45 @@
     
-Expressions.assertThat(SUBJECT, FUNCTION, ANY_VALUE.negate());
+AssertionError thrown = assertThrows(
 %0A   
@@ -1118,35 +1118,32 @@
 ws(%0A        
-%7D%0A%0A
         
 @Test%0A      
@@ -1134,156 +1134,54 @@
     
-@Test%0A        public void errorMessage_describesSubjectFunctionPredicateAndDerivedValue() %7B%0A            String message = Throwables.messageThrownBy(
+    AssertionError.class,%0A                    
 () -
@@ -1243,20 +1243,32 @@
 egate())
+%0A            
 );%0A
-%0A
         
@@ -1286,15 +1286,27 @@
 hat(
-m
+thrown.getM
 essage
+()
 , is
@@ -1399,24 +1399,36 @@
    %7D%0A    %7D%0A%0A
+    @Nested%0A
     public s

Convert more tests to JUnit 5