From ea6b972819ed5a7f618038bd8ccdb38826377c65 Mon Sep 17 00:00:00 2001 From: ryzzaki Date: Thu, 23 Jan 2020 14:14:35 +0000 Subject: [PATCH] feat: test for mocking frameworks practice --- .../JavaMockingFrameworkUsedPractice.spec.ts | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 src/practices/Java/JavaMockingFrameworkUsedPractice.spec.ts diff --git a/src/practices/Java/JavaMockingFrameworkUsedPractice.spec.ts b/src/practices/Java/JavaMockingFrameworkUsedPractice.spec.ts new file mode 100644 index 000000000..417275fc6 --- /dev/null +++ b/src/practices/Java/JavaMockingFrameworkUsedPractice.spec.ts @@ -0,0 +1,50 @@ +import { JavaMockingFrameworkUsedPractice } from './JavaMockingFrameworkUsed'; +import { PracticeEvaluationResult, ProgrammingLanguage } from '../../model'; +import { TestContainerContext, createTestContainer } from '../../inversify.config'; +import { IPackageInspector } from '../../inspectors/IPackageInspector'; + +describe('JavaMockingFrameworkUsedPractice', () => { + let practice: JavaMockingFrameworkUsedPractice; + let containerCtx: TestContainerContext; + let packageInspector: IPackageInspector; + + beforeAll(() => { + containerCtx = createTestContainer(); + containerCtx.container.bind('JavaMockingFrameworkUsedPractice').to(JavaMockingFrameworkUsedPractice); + practice = containerCtx.container.get('JavaMockingFrameworkUsedPractice'); + packageInspector = containerCtx.practiceContext.packageInspector; + }); + + it('Detects Java Mocking framework', async () => { + packageInspector.hasOneOfPackages = () => true; + + const result = await practice.evaluate(containerCtx.practiceContext); + expect(result).toEqual(PracticeEvaluationResult.practicing); + }); + + it('Did not detect Java Mocking framework', async () => { + packageInspector.hasOneOfPackages = () => false; + + const result = await practice.evaluate(containerCtx.practiceContext); + expect(result).toEqual(PracticeEvaluationResult.notPracticing); + }); + + it('Did not recognize packageInspector', async () => { + const result = await practice.evaluate({ ...containerCtx.practiceContext, packageInspector: undefined }); + expect(result).toEqual(PracticeEvaluationResult.unknown); + }); + + it('Is applicable if it is Java', async () => { + containerCtx.practiceContext.projectComponent.language = ProgrammingLanguage.Java; + + const result = await practice.isApplicable(containerCtx.practiceContext); + expect(result).toEqual(true); + }); + + it('Is applicable if it is not Java', async () => { + containerCtx.practiceContext.projectComponent.language = ProgrammingLanguage.Python; + + const result = await practice.isApplicable(containerCtx.practiceContext); + expect(result).toEqual(false); + }); +});