Skip to content

Commit

Permalink
feat: test for mocking frameworks practice
Browse files Browse the repository at this point in the history
  • Loading branch information
ryzzaki committed Jan 23, 2020
1 parent 0453a03 commit ea6b972
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/practices/Java/JavaMockingFrameworkUsedPractice.spec.ts
Original file line number Diff line number Diff line change
@@ -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 = <IPackageInspector>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);
});
});

0 comments on commit ea6b972

Please sign in to comment.