Skip to content

Commit ae9f631

Browse files
committed
Improving Unit test coverage
1 parent aa0c0b1 commit ae9f631

File tree

6 files changed

+110
-12
lines changed

6 files changed

+110
-12
lines changed

src/main/java/org/socialsignin/spring/data/dynamodb/query/QueryExpressionCountQuery.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,8 @@
2323
*/
2424
public class QueryExpressionCountQuery<T> extends AbstractSingleEntityQuery<Long> {
2525

26-
private DynamoDBQueryExpression<T> queryExpression;
27-
28-
private Class<T> domainClass;
29-
26+
private final DynamoDBQueryExpression<T> queryExpression;
27+
private final Class<T> domainClass;
3028

3129
public QueryExpressionCountQuery(DynamoDBOperations dynamoDBOperations, Class<T> clazz,
3230
DynamoDBQueryExpression<T> queryExpression) {
@@ -37,7 +35,7 @@ public QueryExpressionCountQuery(DynamoDBOperations dynamoDBOperations, Class<T>
3735

3836
@Override
3937
public Long getSingleResult() {
40-
return new Long(dynamoDBOperations.count(domainClass, queryExpression));
38+
return Long.valueOf(dynamoDBOperations.count(domainClass, queryExpression));
4139
}
4240

4341
}

src/main/java/org/socialsignin/spring/data/dynamodb/query/QueryRequestCountQuery.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818
import com.amazonaws.services.dynamodbv2.model.QueryRequest;
1919
import org.socialsignin.spring.data.dynamodb.core.DynamoDBOperations;
2020

21-
public class QueryRequestCountQuery<T> extends AbstractSingleEntityQuery<Long> {
21+
public class QueryRequestCountQuery extends AbstractSingleEntityQuery<Long> {
2222

23-
private DynamoDBOperations dynamoDBOperations;
24-
private QueryRequest queryRequest;
23+
private final DynamoDBOperations dynamoDBOperations;
24+
private final QueryRequest queryRequest;
2525

26-
public QueryRequestCountQuery(DynamoDBOperations dynamoDBOperations,Class<T> clazz,QueryRequest queryRequest) {
26+
public QueryRequestCountQuery(DynamoDBOperations dynamoDBOperations, QueryRequest queryRequest) {
2727
super(null, Long.class);
2828
this.queryRequest = queryRequest;
2929
this.dynamoDBOperations = dynamoDBOperations;
@@ -32,7 +32,7 @@ public QueryRequestCountQuery(DynamoDBOperations dynamoDBOperations,Class<T> cla
3232
@Override
3333
public Long getSingleResult() {
3434

35-
return new Long(dynamoDBOperations.count(clazz, queryRequest));
35+
return Long.valueOf(dynamoDBOperations.count(clazz, queryRequest));
3636
}
3737

3838
}

src/main/java/org/socialsignin/spring/data/dynamodb/repository/query/DynamoDBEntityWithHashAndRangeKeyCriteria.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ protected Query<Long> buildFinderCountQuery(DynamoDBOperations dynamoDBOperation
223223
QueryRequest queryRequest = buildQueryRequest(tableName, getGlobalSecondaryIndexName(),
224224
getHashKeyAttributeName(), getRangeKeyAttributeName(), this.getRangeKeyPropertyName(),
225225
getHashKeyConditions(), getRangeKeyConditions());
226-
return new QueryRequestCountQuery<T>(dynamoDBOperations,entityInformation.getJavaType(), queryRequest);
226+
return new QueryRequestCountQuery(dynamoDBOperations, queryRequest);
227227

228228
} else {
229229
DynamoDBQueryExpression<T> queryExpression = buildQueryExpression();

src/main/java/org/socialsignin/spring/data/dynamodb/repository/query/DynamoDBEntityWithHashKeyOnlyCriteria.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ protected Query<Long> buildFinderCountQuery(DynamoDBOperations dynamoDBOperation
7171
List<Condition> hashKeyConditions = getHashKeyConditions();
7272
QueryRequest queryRequest = buildQueryRequest(dynamoDBOperations.getOverriddenTableName(clazz, entityInformation.getDynamoDBTableName()),
7373
getGlobalSecondaryIndexName(), getHashKeyAttributeName(), null, null, hashKeyConditions, null);
74-
return new QueryRequestCountQuery<>(dynamoDBOperations, entityInformation.getJavaType(), queryRequest);
74+
return new QueryRequestCountQuery(dynamoDBOperations, queryRequest);
7575

7676
} else {
7777
return new ScanExpressionCountQuery<>(dynamoDBOperations, clazz, buildScanExpression(),pageQuery);
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package org.socialsignin.spring.data.dynamodb.query;
2+
3+
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBQueryExpression;
4+
import com.amazonaws.services.dynamodbv2.model.QueryRequest;
5+
import org.junit.Before;
6+
import org.junit.Test;
7+
import org.junit.runner.RunWith;
8+
import org.mockito.Mock;
9+
import org.mockito.junit.MockitoJUnitRunner;
10+
import org.socialsignin.spring.data.dynamodb.core.DynamoDBOperations;
11+
import org.socialsignin.spring.data.dynamodb.domain.sample.User;
12+
13+
import java.util.Random;
14+
15+
import static org.junit.Assert.assertEquals;
16+
import static org.mockito.Mockito.when;
17+
18+
@RunWith(MockitoJUnitRunner.class)
19+
public class QueryExpressionCountQueryTest {
20+
21+
private static final Random r = new Random();
22+
@Mock
23+
private DynamoDBOperations dynamoDBOperations;
24+
@Mock
25+
private DynamoDBQueryExpression<User> queryExpression;
26+
27+
private QueryExpressionCountQuery<User> underTest;
28+
29+
@Before
30+
public void setUp() {
31+
underTest = new QueryExpressionCountQuery(dynamoDBOperations, User.class, queryExpression);
32+
}
33+
34+
@Test
35+
public void testGetSingleResult() {
36+
int expected = r.nextInt();
37+
when(dynamoDBOperations.count(User.class, queryExpression)).thenReturn(expected);
38+
39+
Long actual = underTest.getSingleResult();
40+
41+
assertEquals(Long.valueOf(expected), actual);
42+
}
43+
44+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/**
2+
* Copyright © 2013 spring-data-dynamodb (https://github.com/derjust/spring-data-dynamodb)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.socialsignin.spring.data.dynamodb.query;
17+
18+
import com.amazonaws.services.dynamodbv2.model.QueryRequest;
19+
import org.junit.Before;
20+
import org.junit.Test;
21+
import org.junit.runner.RunWith;
22+
import org.mockito.Mock;
23+
import org.mockito.junit.MockitoJUnitRunner;
24+
import org.socialsignin.spring.data.dynamodb.core.DynamoDBOperations;
25+
26+
import java.util.Random;
27+
28+
import static org.junit.Assert.assertEquals;
29+
import static org.mockito.Mockito.when;
30+
31+
@RunWith(MockitoJUnitRunner.class)
32+
public class QueryRequestCountQueryTest {
33+
34+
private static final Random r = new Random();
35+
@Mock
36+
private DynamoDBOperations dynamoDBOperations;
37+
@Mock
38+
private QueryRequest queryRequest;
39+
40+
private QueryRequestCountQuery underTest;
41+
42+
@Before
43+
public void setUp() {
44+
underTest = new QueryRequestCountQuery(dynamoDBOperations, queryRequest);
45+
}
46+
47+
@Test
48+
public void testGetSingleResult() {
49+
int expected = r.nextInt();
50+
when(dynamoDBOperations.count(Long.class, queryRequest)).thenReturn(expected);
51+
52+
Long actual = underTest.getSingleResult();
53+
54+
assertEquals(Long.valueOf(expected), actual);
55+
}
56+
}

0 commit comments

Comments
 (0)