<commit_before>import unittest

from pkg_resources import resource_string
from .. import parse, parser, tree


def setup_java_class(content_to_add):
    """ returns an example java class with the
        given content_to_add contained within a method.
    """
    template = """
public class Lambda {

    public static void main(String args[]) {
        %s
    }
}
        """
    return template % content_to_add


class LambdaSupportTest(unittest.TestCase):
    """ Contains tests for java 8 lambda syntax. """

    def assert_contains_lambda_expression_in_m(
            self, clazz, method_name='main'):
        """ asserts that the given tree contains a method with the supplied
            method name containing a lambda expression.
        """
        if not clazz.children:
            self.fail('No class found.')
        for path, node in clazz.filter(tree.LambdaExpression):
            for p in reversed(path):
                if isinstance(p, tree.MethodDeclaration):
                    self.assertEqual(p.name, method_name)
                    return node, path
        self.fail()

    def test_lambda_support_no_parameters_no_body(self):
        """ tests support for lambda with no parameters and no body. """
        self.assert_contains_lambda_expression_in_m(
            parse.parse(setup_java_class("() -> {};")))

    def test_lambda_support_no_parameters_expression_body(self):
        """ tests support for lambda with no parameters and an<commit_msg>set a fail message when no lambda expression is found.<commit_after>import unittest

from pkg_resources import resource_string
from .. import parse, parser, tree


def setup_java_class(content_to_add):
    """ returns an example java class with the
        given content_to_add contained within a method.
    """
    template = """
public class Lambda {

    public static void main(String args[]) {
        %s
    }
}
        """
    return template % content_to_add


class LambdaSupportTest(unittest.TestCase):
    """ Contains tests for java 8 lambda syntax. """

    def assert_contains_lambda_expression_in_m(
            self, clazz, method_name='main'):
        """ asserts that the given tree contains a method with the supplied
            method name containing a lambda expression.
        """
        if not clazz.children:
            self.fail('No class found.')
        for path, node in clazz.filter(tree.LambdaExpression):
            for p in reversed(path):
                if isinstance(p, tree.MethodDeclaration):
                    self.assertEqual(p.name, method_name)
                    return node, path
        self.fail('No lambda expression found.')

    def test_lambda_support_no_parameters_no_body(self):
        """ tests support for lambda with no parameters and no body. """
        self.assert_contains_lambda_expression_in_m(
            parse.parse(setup_java_class("() -> {};")))

    def test_lambda_support_no_parameters_expression_body(self):
        """ tests support for lambda with no parameters and an
{'fraction_non_alphanumeric': 0.083223249669749, 'fraction_numerical': 0.0006605019815059445, 'mean_word_length': 2.627544910179641, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5755744', 'n_tokens_mistral': 796, 'n_tokens_neox': 769, 'n_words': 249}