### Question:
BehaviorManager { public String addBehavior(CareBehaviorTypeWrapper behavior, SubsystemContext<CareSubsystemModel> context) { if (behaviorNameExists(behavior.getName(), context)) { throw new ErrorEventException(CareErrors.duplicateName(behavior.getName())); } validateTimeWindows(context, behavior); validateBehaviorType(behavior, context); behavior.setId(UUID.randomUUID().toString()); context.setVariable(BehaviorMonitor.BEHAVIOR_KEY.create(behavior.getId()), behavior.toMap()); BehaviorUtil.addStringToSet(behavior.getId(), CareSubsystemCapability.ATTR_BEHAVIORS, context.model()); BehaviorMonitor.initBehavior(behavior.getId(), context); broadcastBehaviorEvent(behavior, context, CareSubsystemCapability.BehaviorActionEvent.BEHAVIORACTION_ADDED); return behavior.getId(); } BehaviorManager(); void bind(SubsystemContext<CareSubsystemModel> context); CareBehaviorTypeWrapper getBehaviorFromContext(String id, SubsystemContext<CareSubsystemModel> context); List<CareBehaviorTypeWrapper> listCareBehaviors(SubsystemContext<CareSubsystemModel> context); List<CareBehaviorTemplate> listCareBehaviorTemplates(SubsystemContext<CareSubsystemModel> context); void loadOptions(List<BehaviorOption> options, CareBehaviorTemplate template); void updateBehavior(CareBehaviorTypeWrapper behavior, SubsystemContext<CareSubsystemModel> context); boolean removeBehavior(String id, SubsystemContext<CareSubsystemModel> context); String addBehavior(CareBehaviorTypeWrapper behavior, SubsystemContext<CareSubsystemModel> context); boolean behaviorNameExists(String name, SubsystemContext<CareSubsystemModel> context); boolean behaviorNameExists(CareBehaviorTypeWrapper behaviorWrapper, SubsystemContext<CareSubsystemModel> context); CareBehaviorTypeWrapper loadBehaviorByName(String name, SubsystemContext<CareSubsystemModel> context);  }### Answer:
@Test public void testAddBehavior(){ CareBehavior behavior = BehaviorFixtures.createCareBehavior(); behavior.setTimeWindows(null); String behaviorId=manager.addBehavior(new CareBehaviorTypeWrapper(behavior.toMap()), context); assertNotNull(behaviorId); assertTrue(context.model().getBehaviors().contains(behaviorId)); Map<String,Object>behavMap=context.getVariable(BehaviorMonitor.BEHAVIOR_KEY.create(behaviorId)).as(TypeMarker.mapOf(String.class, Object.class)); CareBehavior behaviorConfig = new CareBehavior(behavMap); CareBehaviorTypeWrapper tw=manager.listCareBehaviors(context).get(0); assertEquals("behavior should be stored in context var",behaviorId,behaviorConfig.getId()); try{ String id2=manager.addBehavior(new CareBehaviorTypeWrapper(behavior.toMap()), context); assertTrue("should have thrown exception",false); } catch(Exception e){ } MessageBody event = BehaviorActionEvent.builder() .withBehaviorId(behaviorId) .withBehaviorAction(BehaviorActionEvent.BEHAVIORACTION_ADDED) .withBehaviorName(behavior.getName()).build(); assertEquals(event.getAttributes(), broadcasts.getValue().getAttributes()); }