-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SITMAP-229] SetScaleCommand as NavCommand
Change-Id: Ib3a2170d79322aef532753ec8e1bd50292f6c1f6 Signed-off-by: Frank Gasdorf <[email protected]>
- Loading branch information
Showing
2 changed files
with
98 additions
and
12 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
...roject.tests/src/org/locationtech/udig/project/internal/commands/SetScaleCommandTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package org.locationtech.udig.project.internal.commands; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
import org.easymock.EasyMock; | ||
import org.eclipse.core.runtime.IProgressMonitor; | ||
import org.junit.Test; | ||
import org.locationtech.udig.project.internal.render.ViewportModel; | ||
|
||
public class SetScaleCommandTest { | ||
|
||
private static final double SCALE_TO_SET = 1 / 5000; | ||
|
||
private static final double PREVIOUS_SCALE = 1 / 500; | ||
|
||
@Test | ||
public void testCopy() throws Exception { | ||
SetScaleCommand setScaleCommand = new SetScaleCommand(SCALE_TO_SET); | ||
assertNotSame(setScaleCommand, setScaleCommand.copy()); | ||
} | ||
|
||
@Test | ||
public void ifModelIsSetSetScaleIsCalled() throws Exception { | ||
SetScaleCommand setScaleCommand = new SetScaleCommand(SCALE_TO_SET); | ||
ViewportModel mockedViewportModel = EasyMock.createMock(ViewportModel.class); | ||
IProgressMonitor monitor = EasyMock.createNiceMock(IProgressMonitor.class); | ||
EasyMock.expect(mockedViewportModel.getScaleDenominator()).andReturn(PREVIOUS_SCALE).once(); | ||
mockedViewportModel.setScale(SCALE_TO_SET); | ||
EasyMock.expectLastCall().times(1); | ||
|
||
EasyMock.replay(mockedViewportModel); | ||
setScaleCommand.setViewportModel(mockedViewportModel); | ||
setScaleCommand.run(monitor); | ||
EasyMock.verify(mockedViewportModel); | ||
} | ||
|
||
@Test | ||
public void rollbackSetsPreviousScaleFromModel() throws Exception { | ||
SetScaleCommand setScaleCommand = new SetScaleCommand(SCALE_TO_SET); | ||
ViewportModel mockedViewportModel = EasyMock.createMock(ViewportModel.class); | ||
IProgressMonitor monitor = EasyMock.createNiceMock(IProgressMonitor.class); | ||
// get scale from model on first execution | ||
EasyMock.expect(mockedViewportModel.getScaleDenominator()).andReturn(PREVIOUS_SCALE).once(); | ||
mockedViewportModel.setScale(SCALE_TO_SET); | ||
EasyMock.expectLastCall().times(1); | ||
// on roll-back, reset previous scale denominator | ||
mockedViewportModel.setScale(PREVIOUS_SCALE); | ||
EasyMock.expectLastCall().times(1); | ||
|
||
EasyMock.replay(mockedViewportModel); | ||
setScaleCommand.setViewportModel(mockedViewportModel); | ||
setScaleCommand.run(monitor); | ||
setScaleCommand.rollback(monitor); | ||
EasyMock.verify(mockedViewportModel); | ||
} | ||
|
||
@Test | ||
public void commandNameNotNull() throws Exception { | ||
assertNotNull("Command name expected", new SetScaleCommand(SCALE_TO_SET).getName()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters