class RESTUtils {

    public static <T, U> Response checkNullableEntitiesAndRemap(T entity, U entity2,
                                                                BiFunction<T, U, ?> remapFunction) {
        if (entity != null && entity2 != null) {
            return okWithEntity(remapFunction.apply(entity, entity2));
        } else {
            return notFound();
        }
    }

}

class RESTUtilsTest {

    @Test
    public void checkNullableEntitiesAndRemapTest() {

        Response response = RESTUtils.checkNullableEntitiesAndRemap(1l, null, (a, b) -> "");
        assertEquals(404, response.getStatus());
        response = RESTUtils.checkNullableEntitiesAndRemap(null, "", (a, b) -> "");
        assertEquals(404, response.getStatus());
        response = RESTUtils.checkNullableEntitiesAndRemap("", "", (a, b) -> "ENTITY");
        assertEquals(200, response.getStatus());
        assertEquals("ENTITY", response.getEntity());
    }

}