ContractRegistry { public ContractInfo registerContract(CtClass targetClass, CtClass contractClass) { if (isContractClass(contractClass)) { return getContractInfo(contractClass); } ContractInfo contractInfo = new ContractInfo(targetClass, contractClass); contractMap.put(contractClass, contractInfo); targetMap.put(targetClass, contractInfo); return contractInfo; } ContractRegistry(); ContractInfo registerContract(CtClass targetClass, CtClass contractClass); ContractInfo getContractInfo(CtClass contractClass); boolean isContractClass(CtClass clazz); boolean hasRegisteredContract(CtClass targetClass); ContractInfo getContractInfoForTargetClass(CtClass targetClass); CtClass getExternalContract(CtClass type, CtClass affectedClass); ListOrderedSet<ContractInfo> getContractsForTypes(ListOrderedSet<CtClass> types, CtClass affectedClass); void registerExternalContract(XmlLocalConfiguration xmlLocalConfiguration); static final ContractRegistry INSTANCE; }
@Test public void testRegisterContract() { ContractInfo contractInfo = contractRegistry.registerContract(targetClass, contractClass); assertEquals(targetClass, contractInfo.getTargetClass()); assertEquals(contractClass, contractInfo.getContractClass()); assertTrue(contractInfo.getInnerContractClasses().isEmpty()); assertEquals(1, contractInfo.getAllContractClasses().size()); assertTrue(contractInfo.getAllContractClasses().contains(contractClass)); }
@Test public void testRegisterContractForAlreadyRegisteredContract() { ContractInfo contractInfo = contractRegistry.registerContract(targetClass, contractClass); assertEquals(contractInfo, contractRegistry.registerContract(targetClass, contractClass)); }
@Test public void testGetAllContractClasses() { ContractInfo contractInfo = contractRegistry.registerContract(targetClass, contractClass); assertEquals(1, contractInfo.getAllContractClasses().size()); assertTrue(contractInfo.getAllContractClasses().contains(contractClass)); }