DATAKV-105 - Polishing.

Moved KeySpaceResolver interfaces into mapping package. Let defaulting happen in BasicKeyValuePersistentEntity so that ClassNameKeySpaceResolver can be made package protected.

FowardingCloseableIterator is now generically typed and not bound to Map.Entry.

Original pull request: #11.
This commit is contained in:
Oliver Gierke
2015-05-19 17:34:11 +02:00
parent f19a6c0faf
commit e3733ab9b5
10 changed files with 75 additions and 87 deletions

View File

@@ -22,21 +22,24 @@ import static org.mockito.Mockito.*;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.NoSuchElementException;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.springframework.data.util.CloseableIterator;
/**
* @author Christoph Strobl
* @author Thomas Darimont
* @author Oliver Gierke
*/
@RunWith(MockitoJUnitRunner.class)
public class ForwardingCloseableIteratorUnitTests<K, V> {
@Mock Iterator<Map.Entry<K, V>> iteratorMock;
@Mock Iterator<Entry<K, V>> iteratorMock;
@Mock Runnable closeActionMock;
/**
@@ -47,22 +50,33 @@ public class ForwardingCloseableIteratorUnitTests<K, V> {
when(iteratorMock.hasNext()).thenReturn(true);
assertThat(new ForwardingCloseableIterator<K, V>(iteratorMock).hasNext(), is(true));
CloseableIterator<Entry<K, V>> iterator = new ForwardingCloseableIterator<Entry<K, V>>(iteratorMock);
verify(iteratorMock, times(1)).hasNext();
try {
assertThat(iterator.hasNext(), is(true));
verify(iteratorMock, times(1)).hasNext();
} finally {
iterator.close();
}
}
/**
* @see DATAKV-99
*/
@Test
@SuppressWarnings("unchecked")
public void nextShoudDelegateToWrappedIterator() {
when(iteratorMock.next()).thenReturn((Map.Entry<K, V>) mock(Map.Entry.class));
when(iteratorMock.next()).thenReturn((Entry<K, V>) mock(Map.Entry.class));
assertThat(new ForwardingCloseableIterator<K, V>(iteratorMock).next(), notNullValue());
CloseableIterator<Entry<K, V>> iterator = new ForwardingCloseableIterator<Entry<K, V>>(iteratorMock);
verify(iteratorMock, times(1)).next();
try {
assertThat(iterator.next(), notNullValue());
verify(iteratorMock, times(1)).next();
} finally {
iterator.close();
}
}
/**
@@ -73,7 +87,13 @@ public class ForwardingCloseableIteratorUnitTests<K, V> {
when(iteratorMock.next()).thenThrow(new NoSuchElementException());
new ForwardingCloseableIterator<K, V>(iteratorMock).next();
CloseableIterator<Entry<K, V>> iterator = new ForwardingCloseableIterator<Entry<K, V>>(iteratorMock);
try {
iterator.next();
} finally {
iterator.close();
}
}
/**
@@ -82,7 +102,7 @@ public class ForwardingCloseableIteratorUnitTests<K, V> {
@Test
public void closeShouldDoNothingByDefault() {
new ForwardingCloseableIterator<K, V>(iteratorMock).close();
new ForwardingCloseableIterator<Entry<K, V>>(iteratorMock).close();
verifyZeroInteractions(iteratorMock);
}
@@ -93,7 +113,7 @@ public class ForwardingCloseableIteratorUnitTests<K, V> {
@Test
public void closeShouldInvokeConfiguredCloseAction() {
new ForwardingCloseableIterator<K, V>(iteratorMock, closeActionMock).close();
new ForwardingCloseableIterator<Entry<K, V>>(iteratorMock, closeActionMock).close();
verify(closeActionMock, times(1)).run();
}

View File

@@ -1,31 +0,0 @@
/*
* 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 ort.springframework.data.keyvalue.core.mapping.context;
import org.junit.Test;
import org.springframework.data.keyvalue.core.mapping.context.KeyValueMappingContext;
public class KeyValueMappingContextUnitTests {
/**
* @see DATAKV-105
*/
@Test(expected = IllegalArgumentException.class)
public void shouldThrowExceptionWhenKeySpaceResolverIsNull() {
new KeyValueMappingContext(null);
}
}