use rule for exception test in paretovertex.
@@ -15,8 +15,10 @@ import io.improbable.keanu.vertices.dbl.nonprobabilistic.ConstantDoubleVertex;
import io.improbable.keanu.vertices.utility.GraphAssertionException;
import org.apache.commons.math3.distribution.ParetoDistribution;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
+import org.junit.rules.ExpectedException;
import java.util.ArrayList;
import java.util.List;
@@ -32,6 +34,9 @@ public class ParetoVertexTest {
private KeanuRandom random;
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
@Before
public void setup() {
random = new KeanuRandom(1);
@@ -85,7 +90,7 @@ public class ParetoVertexTest {
LogProbGraphContract.matchesKnownLogDensity(logProbGraph, expected);
}
- @Test(expected = GraphAssertionException.class)
+ @Test
public void logProbGraphIsNegInfIfLocationOrScaleIsNotPositive() {
DoubleVertex location = ConstantVertex.of(-1., 1.);
DoubleVertex scale = ConstantVertex.of(0., 3.);
@@ -94,6 +99,10 @@ public class ParetoVertexTest {
LogProbGraphValueFeeder.feedValue(logProbGraph, scale, scale.getValue());
LogProbGraphValueFeeder.feedValue(logProbGraph, paretoVertex, DoubleTensor.create(2., 2.));
+
+ thrown.expect(GraphAssertionException.class);
+ thrown.expectMessage("Location and scale must be strictly positive");
+
LogProbGraphValueFeeder.feedValueAndCascade(logProbGraph, location, location.getValue());
}
