### Question:
CriterionController implements Observer { public void close() { myModel.getElement().deleteObserver(this); } CriterionController(BinCriteriaModel mainModel, CriterionModel model); void close(); @Override void update(Observable o, Object arg);  }### Answer:
@Test public void testInitialValuesNumber() { BinCriteriaModel mainModel = createMainModel(); BinCriteriaElement element = new BinCriteriaElement(); element.setCriteriaType(new UniqueCriteria()); element.setField(ourNumberField); CriterionModel model = new CriterionModel(element); CriterionController controller = new CriterionController(mainModel, model); assertEquals(2, model.getBinTypes().size()); assertEquals(UniqueCriteria.CRITERIA_TYPE, model.getBinTypes().get(0)); assertEquals(RangeCriteria.CRITERIA_TYPE, model.getBinTypes().get(1)); controller.close(); }
@Test public void testInitialValuesString() { BinCriteriaModel mainModel = createMainModel(); BinCriteriaElement element = new BinCriteriaElement(); element.setCriteriaType(new UniqueCriteria()); element.setField(ourStringField); CriterionModel model = new CriterionModel(element); CriterionController controller = new CriterionController(mainModel, model); assertEquals(1, model.getBinTypes().size()); assertEquals(UniqueCriteria.CRITERIA_TYPE, model.getBinTypes().get(0)); controller.close(); }
@Test public void testNumberType() { BinCriteriaModel mainModel = createMainModel(); BinCriteriaElement element = new BinCriteriaElement(); CriterionModel model = new CriterionModel(element); CriterionController controller = new CriterionController(mainModel, model); element.setField(ourNumberField); assertEquals(2, model.getBinTypes().size()); assertEquals(UniqueCriteria.CRITERIA_TYPE, element.getCriteriaType().getCriteriaType()); assertEquals(UniqueCriteria.CRITERIA_TYPE, model.getBinTypes().get(0)); assertEquals(RangeCriteria.CRITERIA_TYPE, model.getBinTypes().get(1)); element.setCriteriaType(CriteriaTypeFactory.getInstance().newCriteriaType(model.getBinTypes().get(1))); assertEquals(RangeCriteria.CRITERIA_TYPE, element.getCriteriaType().getCriteriaType()); assertEquals(10, ((RangeCriteria)element.getCriteriaType()).getBinWidth(), 0); controller.close(); element.setField(ourStringField); assertEquals(2, model.getBinTypes().size()); assertEquals(UniqueCriteria.CRITERIA_TYPE, model.getBinTypes().get(0)); assertEquals(RangeCriteria.CRITERIA_TYPE, model.getBinTypes().get(1)); }
@Test public void testStringFieldChangedToStringField() { EasyMockSupport support = new EasyMockSupport(); @SuppressWarnings("unchecked") ListChangeListener<String> listener = support.createMock(ListChangeListener.class); support.replayAll(); BinCriteriaModel mainModel = createMainModel(); BinCriteriaElement element = new BinCriteriaElement(); CriterionModel model = new CriterionModel(element); CriterionController controller = new CriterionController(mainModel, model); element.setField(ourStringField); assertEquals(1, model.getBinTypes().size()); assertEquals(UniqueCriteria.CRITERIA_TYPE, model.getBinTypes().get(0)); model.getBinTypes().addListener(listener); element.setField(ourStringField2); controller.close(); }
@Test public void testStringType() { BinCriteriaModel mainModel = createMainModel(); BinCriteriaElement element = new BinCriteriaElement(); CriterionModel model = new CriterionModel(element); CriterionController controller = new CriterionController(mainModel, model); element.setField(ourStringField); assertEquals(1, model.getBinTypes().size()); assertEquals(UniqueCriteria.CRITERIA_TYPE, model.getBinTypes().get(0)); assertEquals(UniqueCriteria.CRITERIA_TYPE, model.getElement().getCriteriaType().getCriteriaType()); controller.close(); }