Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an API to check if a custom shifter is set. #1062

Merged
merged 1 commit into from
Jul 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,12 @@ public static void setCoordinateShifter(CoordinateShifter coordinateShifter) {
CoordinateShifterManager.coordinateShifter =
coordinateShifter == null ? DEFAULT : coordinateShifter;
}

/**
* Check whether the current shifter is the default one.
* @return true if using default shifter.
*/
public static boolean isUsingDefaultShifter() {
return coordinateShifter == DEFAULT;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be equals instead of ==

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems use == doesn't have any issue here as coordinateShifter will be the same object of DEFAULT when using default shifter. Do you have any other reasons for using equals here?

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
import java.util.Arrays;
import java.util.List;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.*;

public class ShifterTest {

Expand Down Expand Up @@ -54,6 +52,17 @@ public void basic_coordinate_shifter_manager_creation() throws Exception {
assertNotNull(coordinateShifterManager);
}

@Test
public void default_shifter(){
assertTrue(CoordinateShifterManager.isUsingDefaultShifter());

CoordinateShifter shifter = new TestCoordinateShifter();
CoordinateShifterManager.setCoordinateShifter(shifter);
assertFalse(CoordinateShifterManager.isUsingDefaultShifter());

CoordinateShifterManager.setCoordinateShifter(null);
assertTrue(CoordinateShifterManager.isUsingDefaultShifter());
}

@Test
public void point_basic_shift() throws Exception {
Expand Down