### Question:
DrugOrder extends Order { public void setAutoExpireDateBasedOnDuration() { if (DISCONTINUE != getAction() && getAutoExpireDate() == null) { setAutoExpireDate(getDosingInstructionsInstance().getAutoExpireDate(this)); } } DrugOrder();  DrugOrder(Integer orderId); @Override DrugOrder copy(); boolean isDrugOrder(); Concept getDoseUnits(); void setDoseUnits(Concept doseUnits); OrderFrequency getFrequency(); void setFrequency(OrderFrequency frequency); Boolean getAsNeeded(); void setAsNeeded(Boolean asNeeded); Double getQuantity(); void setQuantity(Double quantity); Concept getQuantityUnits(); void setQuantityUnits(Concept quantityUnits); Drug getDrug(); void setDrug(Drug drug); String getAsNeededCondition(); void setAsNeededCondition(String asNeededCondition); Concept getRoute(); void setRoute(Concept route); void setDose(Double dose); Double getDose(); Class<? extends DosingInstructions> getDosingType(); void setDosingType(Class<? extends DosingInstructions> dosingType); DosingInstructions getDosingInstructionsInstance(); Integer getNumRefills(); void setNumRefills(Integer numRefills); void setDosingInstructions(String dosingInstructions); String getDosingInstructions(); Integer getDuration(); void setDuration(Integer duration); Concept getDurationUnits(); void setDurationUnits(Concept durationUnits); String getBrandName(); void setBrandName(String brandName); Boolean getDispenseAsWritten(); void setDispenseAsWritten(Boolean dispenseAsWritten); @Override DrugOrder cloneForDiscontinuing(); @Override DrugOrder cloneForRevision(); void setAutoExpireDateBasedOnDuration(); @Override String toString(); void setDosing(DosingInstructions di); @Override boolean hasSameOrderableAs(Order otherOrder); String getDrugNonCoded(); void setDrugNonCoded(String drugNonCoded); boolean isNonCodedDrug(); static final long serialVersionUID; }### Answer:
@Test public void setAutoExpireDateBasedOnDuration_shouldNotCalculateForDiscontinueAction() { DrugOrder drugOrder = new DrugOrder(); drugOrder.setAction(Order.Action.DISCONTINUE); Date expectedAutoExpireDate = new Date(); drugOrder.setAutoExpireDate(expectedAutoExpireDate); drugOrder.setAutoExpireDateBasedOnDuration(); assertEquals(expectedAutoExpireDate, drugOrder.getAutoExpireDate()); }
@Test public void setAutoExpireDateBasedOnDuration_shouldNotCalculateIfAutoExpireDateAlreadySet() { DrugOrder drugOrder = new DrugOrder(); Date expectedAutoExpireDate = new Date(); drugOrder.setAutoExpireDate(expectedAutoExpireDate); drugOrder.setAutoExpireDateBasedOnDuration(); assertEquals(expectedAutoExpireDate, drugOrder.getAutoExpireDate()); }