DATAKV-101 - Favor Iterable over Collection types for KeyValueOperations.

Change return types for Adapter and Operations from Collection types to Iterable. Added count(keyspace) to KeyValueAdapter.

Original pull request: #8.
This commit is contained in:
Christoph Strobl
2015-05-08 09:30:31 +02:00
committed by Thomas Darimont
parent 16dc4b5e7d
commit 952a901164
10 changed files with 198 additions and 36 deletions

View File

@@ -0,0 +1,92 @@
/*
* Copyright 2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.keyvalue.core;
import static org.hamcrest.collection.IsEmptyCollection.*;
import static org.hamcrest.collection.IsIterableContainingInOrder.*;
import static org.hamcrest.core.IsInstanceOf.*;
import static org.hamcrest.core.IsNull.*;
import static org.hamcrest.core.IsSame.*;
import static org.junit.Assert.*;
import static org.springframework.data.keyvalue.core.IterableConverter.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import org.junit.Test;
/**
* @author Christoph Strobl
*/
public class IterableConverterUnitTests {
/**
* @see DATAKV-101
*/
@Test
public void toListShouldReturnEmptyListWhenSourceIsNull() {
assertThat(toList(null), notNullValue());
}
/**
* @see DATAKV-101
*/
@Test
public void toListShouldReturnEmptyListWhenSourceEmpty() {
assertThat(toList(Collections.emptySet()), empty());
}
/**
* @see DATAKV-101
*/
@Test
public void toListShouldReturnSameObjectWhenSourceIsAlreadyListType() {
List<String> source = new ArrayList<String>();
assertThat(toList(source), sameInstance(source));
}
/**
* @see DATAKV-101
*/
@Test
public void toListShouldReturnListWhenSourceIsNonListType() {
Set<String> source = new HashSet<String>();
source.add("tyrion");
assertThat(toList(source), instanceOf(List.class));
}
/**
* @see DATAKV-101
*/
@Test
public void toListShouldHoldValuesInOrderOfSource() {
Set<String> source = new LinkedHashSet<String>();
source.add("tyrion");
source.add("jaime");
assertThat(toList(source), contains(source.toArray(new String[2])));
}
}

View File

@@ -362,11 +362,9 @@ public class KeyValueTemplateUnitTests {
* @see DATACMNS-525
*/
@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void countShouldReturnCollectionSize() {
Collection foo = Arrays.asList(FOO_ONE, FOO_ONE);
when(adapterMock.getAllOf(Foo.class.getName())).thenReturn(foo);
when(adapterMock.count(Foo.class.getName())).thenReturn(2L);
assertThat(template.count(Foo.class), is(2L));
}