@Test public void givenClass_whenAddMember() throws Exception { // given final ApplicationFeatureId classId = ApplicationFeatureId.newClass("com.mycompany.Bar"); final ApplicationFeatureId propertyId = ApplicationFeatureId.newMember("com.mycompany.Bar", "foo"); final ApplicationFeatureId actionId = ApplicationFeatureId.newMember("com.mycompany.Bar", "boz"); final ApplicationFeature classFeature = new ApplicationFeature(classId); final ApplicationFeature propertyFeature = new ApplicationFeature(propertyId); propertyFeature.setMemberType(ApplicationMemberType.PROPERTY); final ApplicationFeature actionFeature = new ApplicationFeature(actionId); actionFeature.setMemberType(ApplicationMemberType.ACTION); classFeature.addToMembers(propertyId, ApplicationMemberType.PROPERTY); classFeature.addToMembers(actionId, ApplicationMemberType.ACTION); ApplicationClass applicationClass = new ApplicationClass(classId); applicationClass.applicationFeatureRepository = mockApplicationFeatureRepository; applicationClass.container = mockContainer; // then context.checking( new Expectations() { { allowing(mockApplicationFeatureRepository).findFeature(classId); will(returnValue(classFeature)); allowing(mockApplicationFeatureRepository).findFeature(propertyId); will(returnValue(propertyFeature)); allowing(mockApplicationFeatureRepository).findFeature(actionId); will(returnValue(actionFeature)); oneOf(mockContainer) .newViewModelInstance( ApplicationClassProperty.class, propertyId.asEncodedString()); will(returnValue(new ApplicationClassProperty(propertyId))); oneOf(mockContainer) .newViewModelInstance(ApplicationClassAction.class, actionId.asEncodedString()); will(returnValue(new ApplicationClassAction(actionId))); } }); // when final List<ApplicationClassProperty> properties = applicationClass.getProperties(); // then assertThat(properties.size(), is(1)); // when final List<ApplicationClassAction> actions = applicationClass.getActions(); // then assertThat(actions.size(), is(1)); }
@Test public void givenPackage_whenAddPackageAndClass() throws Exception { // given final ApplicationFeatureId applicationFeatureId = ApplicationFeatureId.newPackage("com.mycompany"); final ApplicationFeatureId packageFeatureId = ApplicationFeatureId.newPackage("com.mycompany.flob"); final ApplicationFeatureId classFeatureId = ApplicationFeatureId.newClass("com.mycompany.Bar"); final ApplicationFeature applicationFeature = new ApplicationFeature(applicationFeatureId); applicationFeature.addToContents(packageFeatureId); applicationFeature.addToContents(classFeatureId); ApplicationPackage applicationFeatureVM = new ApplicationPackage(applicationFeatureId); applicationFeatureVM.applicationFeatureRepository = mockApplicationFeatureRepository; applicationFeatureVM.container = mockContainer; // then context.checking( new Expectations() { { allowing(mockApplicationFeatureRepository).findFeature(applicationFeatureId); will(returnValue(applicationFeature)); oneOf(mockContainer) .newViewModelInstance( ApplicationPackage.class, packageFeatureId.asEncodedString()); will(returnValue(new ApplicationPackage())); oneOf(mockContainer) .newViewModelInstance(ApplicationClass.class, classFeatureId.asEncodedString()); will(returnValue(new ApplicationClass())); } }); // when final List<ApplicationFeatureViewModel> contents = applicationFeatureVM.getContents(); // then assertThat(contents.size(), is(2)); }