Skip to content

Commit

Permalink
test(*): add test coverage for map imports
Browse files Browse the repository at this point in the history
Signed-off-by: Jonathan Casey <[email protected]>
  • Loading branch information
jonathan-casey committed Nov 3, 2023
1 parent 0746a66 commit 60415e5
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions test/codegen/fromcto/java/javavisitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,36 @@ describe('JavaVisitor', function () {
acceptSpy.withArgs(javaVisit, Object.assign({},param,{mode:'setter'})).calledTwice.should.be.ok;
mockEndClassFile.withArgs(mockClassDeclaration, param).calledOnce.should.be.ok;
});

it('should write a class declaration, including imports for java.util Map & HashMap types', () => {
mockClassDeclaration.getIdentifierFieldName.returns('employeeID');
sandbox.restore();
sandbox.stub(ModelUtil, 'isMap').callsFake(() => {
return true;
});
javaVisit.visitClassDeclaration(mockClassDeclaration, param);

mockStartClassFile.withArgs(mockClassDeclaration, param).calledOnce.should.be.ok;
param.fileWriter.writeLine.callCount.should.deep.equal(9);
param.fileWriter.writeLine.getCall(0).args.should.deep.equal([0, 'import fruit.oranges;']);
param.fileWriter.writeLine.getCall(1).args.should.deep.equal([0, 'import fruit.apples;']);
param.fileWriter.writeLine.getCall(2).args.should.deep.equal([0, 'import java.util.HashMap;']);
param.fileWriter.writeLine.getCall(3).args.should.deep.equal([0, 'import java.util.Map;']);
param.fileWriter.writeLine.getCall(4).args.should.deep.equal([0, 'import com.fasterxml.jackson.annotation.*;']);
param.fileWriter.writeLine.getCall(5).args.should.deep.equal([0, '']);
param.fileWriter.writeLine.getCall(6).args.should.deep.equal([0, 'public class Bob {']);
param.fileWriter.writeLine.getCall(7).args.should.deep.equal([1, `
// the accessor for the identifying field
public String getID() {
return this.getEmployeeID();
}
`]);
param.fileWriter.writeLine.getCall(8).args.should.deep.equal([0, '}']);
acceptSpy.withArgs(javaVisit, Object.assign({},param,{mode:'field'})).calledTwice.should.be.ok;
acceptSpy.withArgs(javaVisit, Object.assign({},param,{mode:'getter'})).calledTwice.should.be.ok;
acceptSpy.withArgs(javaVisit, Object.assign({},param,{mode:'setter'})).calledTwice.should.be.ok;
mockEndClassFile.withArgs(mockClassDeclaration, param).calledOnce.should.be.ok;
});
});

describe('visitField', () => {
Expand Down

0 comments on commit 60415e5

Please sign in to comment.