Skip to content

Commit d6e9406

Browse files
Use inline Java in assert pattern test (#1248)
Co-authored-by: Marinaaaa <gabidolboebka@gmail.com>
1 parent cdf80fa commit d6e9406

2 files changed

Lines changed: 13 additions & 16 deletions

File tree

test/patterns/assert_in_code/Book.java

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
# SPDX-FileCopyrightText: Copyright (c) 2019-2026 Aibolit
22
# SPDX-License-Identifier: MIT
33

4-
import os.path
5-
from pathlib import Path
4+
from textwrap import dedent
65
from unittest import TestCase
76

87
from aibolit.patterns.assert_in_code.assert_in_code import AssertInCode
98
from aibolit.ast_framework import AST
10-
from aibolit.utils.ast_builder import build_ast
9+
from aibolit.utils.ast_builder import build_ast_from_string
1110

1211

1312
class AssertInCodeTestCase(TestCase):
14-
cur_file_dir = Path(os.path.realpath(__file__)).parent
15-
1613
def test_assert_in_code(self):
17-
file = Path(self.cur_file_dir, 'Book.java')
18-
ast = AST.build_from_javalang(build_ast(file))
19-
self.assertEqual(AssertInCode().value(ast), [6])
14+
content = dedent(
15+
'''\
16+
class Book {
17+
void foo(String x) {
18+
assert x != null; // here
19+
}
20+
}
21+
'''
22+
)
23+
ast = AST.build_from_javalang(build_ast_from_string(content))
24+
self.assertEqual(AssertInCode().value(ast), [3])

0 commit comments

Comments
 (0)