Skip to content

Commit

Permalink
Fixing @mock Presubmit with new Java formatting
Browse files Browse the repository at this point in the history
Bug: 1490300
Change-Id: I823ea1cecb4e0da0b92c07ff896453f970f229c0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4918411
Commit-Queue: Andrew Grieve <agrieve@chromium.org>
Reviewed-by: Andrew Grieve <agrieve@chromium.org>
Auto-Submit: Sam Maier <smaier@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1207619}
  • Loading branch information
Sam Maier authored and Chromium LUCI CQ committed Oct 10, 2023
1 parent 97613a3 commit b8a66a0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
9 changes: 8 additions & 1 deletion PRESUBMIT.py
Original file line number Diff line number Diff line change
Expand Up @@ -6991,7 +6991,14 @@ def _FilterFile(affected_file):
continue

if mock_annotation.search(line):
next_line_is_annotated = True
field_type_search = field_type.search(line)
if field_type_search:
fully_qualified_class = _DoClassLookup(
field_type_search.group(1), fully_qualified_class_map,
package)
mocked_by_annotation_classes.add(fully_qualified_class)
else:
next_line_is_annotated = True
continue

m = mock_function_regex.search(line)
Expand Down
16 changes: 13 additions & 3 deletions PRESUBMIT_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4914,8 +4914,7 @@ def testTruePositives(self):
MockFile('path/OneTest.java', [
'import a.b.c.Bar;',
'import a.b.c.Foo;',
'@Mock',
'public static Foo f = new Foo();',
'@Mock public static Foo f = new Foo();',
'Mockito.mock(new Bar(a, b, c))'
]),
MockFile('path/TwoTest.java', [
Expand Down Expand Up @@ -4964,14 +4963,25 @@ def testTrueNegatives(self):
'package a.b.c;',
'@Mock',
'public static Baz<abc> b;',
'Mockito.mock(Baz.class)']),
'Mockito.mock(Baz.class)'
]),
MockFile('path/SixTest.java', [
'package a.b.c;',
'import android.view.View;',
'import java.ArrayList;',
'Mockito.spy(new View())',
'Mockito.mock(ArrayList.class)'
]),
MockFile('path/SevenTest.java', [
'package a.b.c;',
'@Mock private static Seven s;',
'Mockito.mock(Seven.class)'
]),
MockFile('path/EightTest.java', [
'package a.b.c;',
'@Spy Eight e = new Eight2();',
'Mockito.py(new Eight())'
]),
]
errors = PRESUBMIT.CheckMockAnnotation(mock_input, MockOutputApi())
self.assertEqual(0, len(errors))
Expand Down

0 comments on commit b8a66a0

Please sign in to comment.