@Test public void testThatBindingContextMustBeNotNull() { try { RegionSelectableWorldMapPane.ensureValidBindingContext(null); fail("should not come here"); } catch (IllegalArgumentException expected) { assertEquals("bindingContext must be not null", expected.getMessage()); } catch (Exception notExpected) { fail("Exception '" + notExpected.getClass().getName() + "' is not expected"); } }
@Test public void testThatPropertiesObjectAreFilledWithDefaultValuesIfAllPropertyValuesAreNull() { //preparation propertiesObject.northBound = null; propertiesObject.eastBound = null; propertiesObject.southBound = null; propertiesObject.westBound = null; //execution RegionSelectableWorldMapPane.ensureValidBindingContext(bindingContext); //verification assertEquals(Double.valueOf(75.0), propertiesObject.northBound); assertEquals(Double.valueOf(30.0), propertiesObject.eastBound); assertEquals(Double.valueOf(35.0), propertiesObject.southBound); assertEquals(Double.valueOf(-15.0), propertiesObject.westBound); }
@Test /** * It suffices to test one invalid property value, since the implementation responsible for testing whether * the property values are valid is well tested in {@link RegionSelectableWorldMapPane_BoundingValuesValidation} */ public void testThatIllegalArgumentExceptionIsThrownIfAnyPropertyValueIsInvalid() { //preparation bindingContext.getPropertySet().setValue(NORTH_BOUND, null); try { //execution RegionSelectableWorldMapPane.ensureValidBindingContext(bindingContext); } catch (IllegalArgumentException expected) { //verification assertEquals("Given geo-bounds (" + null + ", " + EAST_BOUND + ", " + SOUTH_BOUND + ", " + WEST_BOUND + " are invalid.", expected.getMessage()); } catch (Exception notExpected) { fail("Exception '" + notExpected.getClass().getName() + "' not expected"); } }
@Test public void testValidValuesAreNotChanged() { //preparation propertiesObject.northBound = 15.0; propertiesObject.eastBound = 15.0; propertiesObject.southBound = -15.0; propertiesObject.westBound = -15.0; final PropertyContainer objectBacked = PropertyContainer.createObjectBacked(propertiesObject); //execution RegionSelectableWorldMapPane.ensureValidBindingContext(new BindingContext(objectBacked)); //verification assertEquals(Double.valueOf(15.0), propertiesObject.northBound); assertEquals(Double.valueOf(15.0), propertiesObject.eastBound); assertEquals(Double.valueOf(-15.0), propertiesObject.southBound); assertEquals(Double.valueOf(-15.0), propertiesObject.westBound); }
private void assertIllegalArgumentExceptionIfPropertyIsMissing(String propertyName) { //preparation bindingContext.getPropertySet().removeProperty(bindingContext.getPropertySet().getProperty(propertyName)); //execution try { RegionSelectableWorldMapPane.ensureValidBindingContext(bindingContext); fail("should not come here"); } catch (IllegalArgumentException expected) { //verification assertEquals("bindingContext must contain a property named " + propertyName, expected.getMessage()); } catch (Exception notExpected) { fail("Exception '" + notExpected.getClass().getName() + "' not expected"); } }
RegionSelectableWorldMapPane.ensureValidBindingContext(bindingContext); this.bindingContext = bindingContext;
/** * Creates a RegionSelectableWorldMapPane. * * @param dataModel The data model to be used * @param bindingContext The binding context which has to contain at least the following properties: * {@link #NORTH_BOUND northBound} , * {@link #SOUTH_BOUND southBound}, {@link #WEST_BOUND westBound}, and * {@link #EAST_BOUND eastBound}. If all these property values are null, default values * will be used. The property values are considered valid when the latitude values are * within the allowed latitude range [-90, 90], the longitude values are within the * allowed longitude range [-180, 180], the northBound is bigger than the southBound, * the eastBound is bigger than the westBound, and no value is null. In this case, * the world map will be initialized with these values. * @throws IllegalArgumentException If the bindingContext is null, it does not contain the expected properties or * the properties do not contain valid values */ public RegionSelectableWorldMapPane(WorldMapPaneDataModel dataModel, BindingContext bindingContext) { ensureValidBindingContext(bindingContext); this.bindingContext = bindingContext; worldMapPane = new FigureEditorAwareWorldMapPane(dataModel, new SelectionOverlay(dataModel)); panSupport = new RegionSelectionDecoratingPanSupport(worldMapPane.getLayerCanvas()); worldMapPane.setPanSupport(panSupport); figureEditor = new DefaultFigureEditor(worldMapPane.getLayerCanvas()); regionSelectionInteractor = new RegionSelectionInteractor(); worldMapPane.getLayerCanvas().addMouseMotionListener(cursorChanger); }