Skip to content

Commit

Permalink
JavaPMDBear: Remove use of generic no cover
Browse files Browse the repository at this point in the history
Add test to check for prerequisites

Closes coala#2769
  • Loading branch information
kx-chen committed Dec 3, 2018
1 parent cf4af5b commit 9e816d1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion bears/java/JavaPMDBear.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class JavaPMDBear:
'Duplication'}

@classmethod
def check_prerequisites(cls): # pragma: no cover
def check_prerequisites(cls):
if which('bash') is None:
return 'bash is not installed.'
elif which('pmd') is None and which('run.sh') is None:
Expand Down
20 changes: 20 additions & 0 deletions tests/java/JavaPMDBearTest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from unittest import mock, TestCase

from bears.java.JavaPMDBear import JavaPMDBear
from coalib.testing.LocalBearTestHelper import verify_local_bear

Expand Down Expand Up @@ -29,6 +31,24 @@ class Hello {
"""


class JavaPMDBearPrerequisiteTest(TestCase):
def test_check_prerequisites(self):
with mock.patch('bears.java.JavaPMDBear.which') as mock_which:
mock_which.side_effect = [None, None, None]
self.assertEqual(JavaPMDBear.check_prerequisites(),
'bash is not installed.')

mock_which.side_effect = ['path/to/bash', None, None]
self.assertEqual(JavaPMDBear.check_prerequisites(),
('PMD is missing. Make sure to install it from '
'<https://pmd.github.io/>'))

mock_which.side_effect = ['path/to/bash',
'path/to/pmd',
'path/to/run']
self.assertEqual(JavaPMDBear.check_prerequisites(), True)


JavaPMDBearTest = verify_local_bear(
JavaPMDBear, valid_files=(good_file,), invalid_files=(bad_file,),
tempfile_kwargs={'suffix': '.java'})

0 comments on commit 9e816d1

Please sign in to comment.