From 01f6e848ef11361ad987d9455a1d7fc6656e1e5d Mon Sep 17 00:00:00 2001 From: Alexandra Batey Date: Wed, 14 Mar 2018 20:38:41 +0000 Subject: [PATCH] #195 bug fix dont throw null pointer when rows is empty --- .../scassandra/http/client/PrimingRequest.java | 2 +- .../http/client/PrimingClientTest.java | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/java-client/src/main/java/org/scassandra/http/client/PrimingRequest.java b/java-client/src/main/java/org/scassandra/http/client/PrimingRequest.java index 28becaac..6ec514e5 100644 --- a/java-client/src/main/java/org/scassandra/http/client/PrimingRequest.java +++ b/java-client/src/main/java/org/scassandra/http/client/PrimingRequest.java @@ -355,7 +355,7 @@ public Map getConfig() { public static class ThenBuilder { private List variable_types; - private List> rows; + private List> rows = new ArrayList<>(); private Result result; private Long fixedDelay; private Map config = new HashMap(); diff --git a/java-client/src/test/java/org/scassandra/http/client/PrimingClientTest.java b/java-client/src/test/java/org/scassandra/http/client/PrimingClientTest.java index 925ed37b..e78d8040 100644 --- a/java-client/src/test/java/org/scassandra/http/client/PrimingClientTest.java +++ b/java-client/src/test/java/org/scassandra/http/client/PrimingClientTest.java @@ -26,6 +26,7 @@ import static com.github.tomakehurst.wiremock.client.WireMock.*; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.scassandra.cql.PrimitiveType.*; import static org.scassandra.http.client.BatchQueryPrime.batchQueryPrime; @@ -921,4 +922,21 @@ public void testRetrievingOfMultiPreparedPrimesFailed() { //when underTest.retrieveQueryPrimes(); } + + // bug fix https://github.com/scassandra/scassandra-server/issues/195 + @Test + public void primeWithEmptyRowsDoesntThrowNullPointer() { + //given + stubFor(post(urlEqualTo(PRIME_PREPARED_PATH)).willReturn(aResponse().withStatus(200))); + PrimingRequest pr = PrimingRequest.preparedStatementBuilder() + .withQuery("select * from people") + .withThen(PrimingRequest.then().withVariableTypes(TEXT)) + .build(); + //when + underTest.prime(pr); + + //then + List> rows = pr.getThen().getRows(); + assertTrue(rows.isEmpty()); + } }