From ca535bb7f63f5c7cbe2cb66fed59a8146ae28e23 Mon Sep 17 00:00:00 2001 From: Jonathan Casey Date: Tue, 10 Oct 2023 17:32:23 +0100 Subject: [PATCH] feat(dcs): add test cases Signed-off-by: Jonathan Casey --- test/codegen/fromcto/java/javavisitor.js | 45 ++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/test/codegen/fromcto/java/javavisitor.js b/test/codegen/fromcto/java/javavisitor.js index a7bca99d..f284f450 100644 --- a/test/codegen/fromcto/java/javavisitor.js +++ b/test/codegen/fromcto/java/javavisitor.js @@ -21,6 +21,8 @@ const sinon = require('sinon'); const JavaVisitor = require('../../../../lib/codegen/fromcto/java/javavisitor.js'); const ClassDeclaration = require('@accordproject/concerto-core').ClassDeclaration; +const MapDeclaration = require('@accordproject/concerto-core').MapDeclaration; +const ModelUtil = require('@accordproject/concerto-core').ModelUtil; const EnumDeclaration = require('@accordproject/concerto-core').EnumDeclaration; const EnumValueDeclaration = require('@accordproject/concerto-core').EnumValueDeclaration; const Field = require('@accordproject/concerto-core').Field; @@ -29,6 +31,8 @@ const ModelManager = require('@accordproject/concerto-core').ModelManager; const RelationshipDeclaration = require('@accordproject/concerto-core').RelationshipDeclaration; const FileWriter = require('@accordproject/concerto-util').FileWriter; +let sandbox = sinon.createSandbox(); + describe('JavaVisitor', function () { let javaVisit; let mockFileWriter; @@ -413,6 +417,47 @@ describe('JavaVisitor', function () { param.fileWriter.writeLine.withArgs(1, 'private JavaType[] Bob;').calledOnce.should.be.ok; }); + it('should write a line with a HashMap', () => { + let param = { + fileWriter: mockFileWriter, + mode: 'field' + }; + + sandbox.restore(); + sandbox.stub(ModelUtil, 'isMap').callsFake(() => { + return true; + }); + + const mockField = sinon.createStubInstance(Field); + const getAllDeclarations = sinon.stub(); + + mockField.dummy = 'Dummy Value'; + mockField.getModelFile.returns({ getAllDeclarations: getAllDeclarations }); + + const mockMapDeclaration = sinon.createStubInstance(MapDeclaration); + const findStub = sinon.stub(); + const getKeyType = sinon.stub(); + const getValueType = sinon.stub(); + + mockField.getName.returns('Bob'); + mockField.getType.returns('SpecialType'); + + getAllDeclarations.returns({ find: findStub }); + findStub.returns(mockMapDeclaration); + getKeyType.returns('String'); + getValueType.returns('String'); + mockField.getName.returns('Map1'); + mockMapDeclaration.getName.returns('Map1'); + mockMapDeclaration.isMapDeclaration.returns(true); + mockMapDeclaration.getKey.returns({ getType: getKeyType }); + mockMapDeclaration.getValue.returns({ getType: getValueType }); + + javaVisit.visitField(mockField,param); + + param.fileWriter.writeLine.withArgs(1, 'private Map Map1 = new HashMap<>();').calledOnce.should.be.ok; + sandbox.reset(); + }); + it('should write a line defining a field', () => { let mockField = sinon.createStubInstance(Field); mockField.isField.returns(true);