### Question:
RiskScalePresentation extends PresentationModel<ScaleCriterion> { @Override public AbstractValueModel getModel(String property) { if (property.equals(PROPERTY_RISK)) { return new RiskValueModel(); } else if (property.equals(PROPERTY_RISK_DIFFERENCE)) { return new RiskDifferenceValueModel(); } else if (property.equals(PROPERTY_NNT)) { return new NNTValueModel(); } else if (property.equals(PROPERTY_NNT_LABEL)) { return new NNTLabelValueModel(); } return super.getModel(property); } RiskScalePresentation(ScaleCriterion criterion); @Override AbstractValueModel getModel(String property); static final String PROPERTY_RISK; static final String PROPERTY_RISK_DIFFERENCE; static final String PROPERTY_NNT; static final String PROPERTY_NNT_LABEL; }### Answer:
@Test public void testRiskDifferenceModelShouldGiveCorrectValue() { Object actual = d_pm.getModel(OddsRatioScalePresentation.PROPERTY_RISK_DIFFERENCE).getValue(); Object expected = d_criterion.getScale().getEnd() - d_criterion.getScale().getStart(); assertEquals(expected, actual); }
@Test public void testRiskDifferenceModelShouldFireOnScaleChange() { ValueModel model = d_pm.getModel(OddsRatioScalePresentation.PROPERTY_RISK_DIFFERENCE); fi.smaa.jsmaa.model.Interval interval = new fi.smaa.jsmaa.model.Interval(0.8, 0.99); Object expected = interval.getEnd() - interval.getStart(); assertValueModelFires(model, interval, expected); }
@Test public void testNNTModelShouldGiveCorrectValue() { Object actual = d_pm.getModel(OddsRatioScalePresentation.PROPERTY_NNT).getValue(); Object expected = 1D / (d_criterion.getScale().getEnd() - d_criterion.getScale().getStart()); assertEquals(expected, actual); }
@Test public void testNNTModelShouldFireOnScaleChange() { ValueModel model = d_pm.getModel(OddsRatioScalePresentation.PROPERTY_NNT); fi.smaa.jsmaa.model.Interval interval = new fi.smaa.jsmaa.model.Interval(0.8, 0.99); Object expected = 1D / (interval.getEnd() - interval.getStart()); assertValueModelFires(model, interval, expected); }
@Test public void testNNTLabelModelShouldGiveCorrectValue() { Object actual = d_pm.getModel(OddsRatioScalePresentation.PROPERTY_NNT_LABEL).getValue(); Object expected = "NNT"; assertEquals(expected, actual); }
@Test public void testNNTLabelModelShouldFireOnScaleChange() { ValueModel model = d_pm.getModel(OddsRatioScalePresentation.PROPERTY_NNT_LABEL); Object expected = "NNH"; PropertyChangeListener mock = JUnitUtil.mockListener(model, "value", null, expected); model.addValueChangeListener(mock); d_criterion.setAscending(false); assertEquals(expected, model.getValue()); verify(mock); }