Skip to content

Commit

Permalink
Merge pull request #1 from davidmoten/master
Browse files Browse the repository at this point in the history
Update with DaveMoten last commits
  • Loading branch information
maxamel committed Sep 26, 2014
2 parents 3adeb4c + 7386dde commit 8617933
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/main/java/com/github/davidmoten/rtree/Backpressure.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
*/
final class Backpressure {

private Backpressure() {
// prevent instantiation
}

static <T> ImmutableStack<NodePosition<T>> search(
final Func1<? super Geometry, Boolean> condition,
final Subscriber<? super Entry<T>> subscriber, ImmutableStack<NodePosition<T>> stack,
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/github/davidmoten/rtree/Comparators.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
*
*/
public final class Comparators {

private Comparators() {
//prevent instantiation
}

public static final Comparator<ListPair<?>> overlapListPairComparator = toComparator(Functions.overlapListPair);

Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/github/davidmoten/rtree/Functions.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
*/
public final class Functions {

private Functions() {
// prevent instantiation
}

public static final Func1<ListPair<? extends HasGeometry>, Double> overlapListPair = new Func1<ListPair<? extends HasGeometry>, Double>() {

@Override
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/com/github/davidmoten/rtree/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ private Util() {
// prevent instantiation
}

static void instantiateForTestCoveragePurposesOnly() {
new Util();
}

/**
* Returns the minimum bounding rectangle of a number of items. Benchmarks
* below indicate that when the number of items is >1 this method is more
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,15 @@

import com.github.davidmoten.rtree.geometry.Geometry;
import com.github.davidmoten.util.ImmutableStack;
import com.github.davidmoten.util.TestingUtil;

public class BackpressureTest {

@Test
public void testConstructorIsPrivate() {
TestingUtil.callConstructorAndCheckIsPrivate(Backpressure.class);
}

@SuppressWarnings("unchecked")
@Test
public void testBackpressureSearch() {
Expand Down
14 changes: 14 additions & 0 deletions src/test/java/com/github/davidmoten/rtree/ComparatorsTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.github.davidmoten.rtree;

import org.junit.Test;

import com.github.davidmoten.util.TestingUtil;

public class ComparatorsTest {

@Test
public void testConstructorIsPrivate() {
TestingUtil.callConstructorAndCheckIsPrivate(Comparators.class);
}

}
13 changes: 13 additions & 0 deletions src/test/java/com/github/davidmoten/rtree/FunctionsTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.github.davidmoten.rtree;

import org.junit.Test;

import com.github.davidmoten.util.TestingUtil;

public class FunctionsTest {

@Test
public void testConstructorIsPrivate() {
TestingUtil.callConstructorAndCheckIsPrivate(Functions.class);
}
}
4 changes: 3 additions & 1 deletion src/test/java/com/github/davidmoten/rtree/UtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

import org.junit.Test;

import com.github.davidmoten.util.TestingUtil;

public class UtilTest {

@Test
public void coverPrivateConstructor() {
Util.instantiateForTestCoveragePurposesOnly();
TestingUtil.callConstructorAndCheckIsPrivate(Util.class);
}

}
47 changes: 47 additions & 0 deletions src/test/java/com/github/davidmoten/util/TestingUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.github.davidmoten.util;

import static org.junit.Assert.assertTrue;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Modifier;

/**
* Utility methods for unit tests.
*
* @author dave
*
*/
public class TestingUtil {

/**
* Checks that a class has a no-argument private constructor and calls that
* constructor to instantiate the class.
*
* @param cls
*/
public static <T> void callConstructorAndCheckIsPrivate(Class<T> cls) {
Constructor<T> constructor;
try {
constructor = cls.getDeclaredConstructor();
} catch (NoSuchMethodException e1) {
throw new RuntimeException(e1);
} catch (SecurityException e1) {
throw new RuntimeException(e1);
}
assertTrue(Modifier.isPrivate(constructor.getModifiers()));
constructor.setAccessible(true);
try {
constructor.newInstance();
} catch (InstantiationException e) {
throw new RuntimeException(e);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
} catch (IllegalArgumentException e) {
throw new RuntimeException(e);
} catch (InvocationTargetException e) {
throw new RuntimeException(e);
}
}

}

0 comments on commit 8617933

Please sign in to comment.