DATACASS-352 - Polishing.
Reformat code. Add ticket references to test methods. Deprecate Comparator IT instances because of their unintuitive names and re-introduce it under INSTANCE.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2016 the original author or authors
|
||||
* Copyright 2013-2017 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.
|
||||
@@ -89,7 +89,7 @@ public class BasicCassandraPersistentEntity<T> extends BasicPersistentEntity<T,
|
||||
public BasicCassandraPersistentEntity(TypeInformation<T> typeInformation, CassandraMappingContext mappingContext,
|
||||
CassandraPersistentEntityMetadataVerifier verifier) {
|
||||
|
||||
super(typeInformation, CassandraPersistentPropertyComparator.IT);
|
||||
super(typeInformation, CassandraPersistentPropertyComparator.INSTANCE);
|
||||
|
||||
this.mappingContext = mappingContext;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2014 the original author or authors
|
||||
* Copyright 2013-2017 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.
|
||||
@@ -21,12 +21,19 @@ import java.util.Comparator;
|
||||
* {@link Comparator} implementation that uses {@link Column#value()}.
|
||||
*
|
||||
* @author Matthew T. Adams
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
public enum CassandraColumnAnnotationComparator implements Comparator<Column> {
|
||||
|
||||
/**
|
||||
* The sole instance of this class.
|
||||
* Comparator instance.
|
||||
*/
|
||||
INSTANCE,
|
||||
|
||||
/**
|
||||
* @deprecated as of 1.5, use {@link #INSTANCE}
|
||||
*/
|
||||
@Deprecated
|
||||
IT;
|
||||
|
||||
@Override
|
||||
|
||||
@@ -51,6 +51,9 @@ public enum CassandraPersistentPropertyComparator implements Comparator<Cassandr
|
||||
@Deprecated
|
||||
IT;
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public int compare(CassandraPersistentProperty left, CassandraPersistentProperty right) {
|
||||
|
||||
@@ -75,7 +78,7 @@ public enum CassandraPersistentPropertyComparator implements Comparator<Cassandr
|
||||
boolean rightIsPrimaryKey = right.isPrimaryKeyColumn();
|
||||
|
||||
if (leftIsPrimaryKey && rightIsPrimaryKey) {
|
||||
return CassandraPrimaryKeyColumnAnnotationComparator.IT.compare(left.findAnnotation(PrimaryKeyColumn.class),
|
||||
return CassandraPrimaryKeyColumnAnnotationComparator.INSTANCE.compare(left.findAnnotation(PrimaryKeyColumn.class),
|
||||
right.findAnnotation(PrimaryKeyColumn.class));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2014 the original author or authors
|
||||
* Copyright 2013-2017 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.
|
||||
@@ -29,16 +29,30 @@ import org.springframework.cassandra.core.PrimaryKeyType;
|
||||
* <li>{@link PrimaryKeyColumn#ordering()}.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @see PrimaryKeyType#compareTo(PrimaryKeyType)
|
||||
* @see Ordering#compareTo(Ordering)
|
||||
* @author Matthew T. Adams
|
||||
* @author John Blum
|
||||
* @author Mark Paluch
|
||||
* @see PrimaryKeyType#compare(PrimaryKeyType, PrimaryKeyType)
|
||||
* @see Ordering#compare(Ordering, Ordering)
|
||||
* @see java.util.Comparator
|
||||
* @see org.springframework.data.cassandra.mapping.PrimaryKeyColumn
|
||||
*/
|
||||
public enum CassandraPrimaryKeyColumnAnnotationComparator implements Comparator<PrimaryKeyColumn> {
|
||||
|
||||
/**
|
||||
* Comparator instance.
|
||||
*/
|
||||
INSTANCE,
|
||||
|
||||
/**
|
||||
* @deprecated as of 1.5, use {@link #INSTANCE}
|
||||
*/
|
||||
@Deprecated
|
||||
IT;
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public int compare(PrimaryKeyColumn left, PrimaryKeyColumn right) {
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.springframework.data.cassandra.mapping;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.data.cassandra.mapping.CassandraPersistentPropertyComparator.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -30,7 +31,6 @@ import org.springframework.cassandra.core.cql.CqlIdentifier;
|
||||
* functionality of the {@link CassandraPersistentPropertyComparator} class.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.springframework.data.cassandra.mapping.CassandraPersistentPropertyComparator
|
||||
* @since 1.5.0
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
@@ -40,54 +40,82 @@ public class CassandraPersistentPropertyComparatorUnitTests {
|
||||
|
||||
@Mock CassandraPersistentProperty right;
|
||||
|
||||
/**
|
||||
* @see DATACASS-248
|
||||
*/
|
||||
@Test
|
||||
public void leftAndRightAreNullReturnsZero() {
|
||||
assertThat(CassandraPersistentPropertyComparator.IT.compare(null, null)).isEqualTo(0);
|
||||
|
||||
assertThat(INSTANCE.compare(null, null)).isEqualTo(0);
|
||||
|
||||
verifyZeroInteractions(left);
|
||||
verifyZeroInteractions(right);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACASS-248
|
||||
*/
|
||||
@Test
|
||||
public void leftIsNotNullAndRightIsNullReturnsOne() {
|
||||
assertThat(CassandraPersistentPropertyComparator.IT.compare(left, null)).isEqualTo(1);
|
||||
|
||||
assertThat(INSTANCE.compare(left, null)).isEqualTo(1);
|
||||
|
||||
verifyZeroInteractions(left);
|
||||
verifyZeroInteractions(right);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACASS-248
|
||||
*/
|
||||
@Test
|
||||
public void leftIsNullAndRightIsNotNullReturnsMinusOne() {
|
||||
assertThat(CassandraPersistentPropertyComparator.IT.compare(null, right)).isEqualTo(-1);
|
||||
|
||||
assertThat(INSTANCE.compare(null, right)).isEqualTo(-1);
|
||||
|
||||
verifyZeroInteractions(left);
|
||||
verifyZeroInteractions(right);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACASS-248
|
||||
*/
|
||||
@Test
|
||||
public void leftAndRightAreEqualReturnsZero() {
|
||||
assertThat(CassandraPersistentPropertyComparator.IT.compare(left, left)).isEqualTo(0);
|
||||
assertThat(CassandraPersistentPropertyComparator.IT.compare(right, right)).isEqualTo(0);
|
||||
|
||||
assertThat(INSTANCE.compare(left, left)).isEqualTo(0);
|
||||
assertThat(INSTANCE.compare(right, right)).isEqualTo(0);
|
||||
|
||||
verifyZeroInteractions(left);
|
||||
verifyZeroInteractions(right);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACASS-248
|
||||
*/
|
||||
@Test
|
||||
public void leftAndRightAreCompositePrimaryKeysReturnsZero() {
|
||||
|
||||
when(left.isCompositePrimaryKey()).thenReturn(true);
|
||||
when(right.isCompositePrimaryKey()).thenReturn(true);
|
||||
|
||||
assertThat(CassandraPersistentPropertyComparator.IT.compare(left, right)).isEqualTo(0);
|
||||
assertThat(INSTANCE.compare(left, right)).isEqualTo(0);
|
||||
|
||||
verify(left, times(1)).isCompositePrimaryKey();
|
||||
verify(right, times(1)).isCompositePrimaryKey();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACASS-248
|
||||
*/
|
||||
@Test
|
||||
public void leftIsCompositePrimaryKeyReturnsMinusOne() {
|
||||
|
||||
when(left.isCompositePrimaryKey()).thenReturn(true);
|
||||
when(left.isPrimaryKeyColumn()).thenReturn(false);
|
||||
when(right.isCompositePrimaryKey()).thenReturn(false);
|
||||
when(right.isPrimaryKeyColumn()).thenReturn(false);
|
||||
|
||||
assertThat(CassandraPersistentPropertyComparator.IT.compare(left, right)).isEqualTo(-1);
|
||||
assertThat(INSTANCE.compare(left, right)).isEqualTo(-1);
|
||||
|
||||
verify(left, times(1)).isCompositePrimaryKey();
|
||||
verify(left, times(1)).isPrimaryKeyColumn();
|
||||
@@ -95,14 +123,18 @@ public class CassandraPersistentPropertyComparatorUnitTests {
|
||||
verify(right, times(1)).isPrimaryKeyColumn();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACASS-248
|
||||
*/
|
||||
@Test
|
||||
public void leftIsPrimaryKeyColumnReturnsMinusOne() {
|
||||
|
||||
when(left.isCompositePrimaryKey()).thenReturn(false);
|
||||
when(left.isPrimaryKeyColumn()).thenReturn(true);
|
||||
when(right.isCompositePrimaryKey()).thenReturn(false);
|
||||
when(right.isPrimaryKeyColumn()).thenReturn(false);
|
||||
|
||||
assertThat(CassandraPersistentPropertyComparator.IT.compare(left, right)).isEqualTo(-1);
|
||||
assertThat(INSTANCE.compare(left, right)).isEqualTo(-1);
|
||||
|
||||
verify(left, times(1)).isCompositePrimaryKey();
|
||||
verify(left, times(1)).isPrimaryKeyColumn();
|
||||
@@ -110,14 +142,18 @@ public class CassandraPersistentPropertyComparatorUnitTests {
|
||||
verify(right, times(1)).isPrimaryKeyColumn();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACASS-248
|
||||
*/
|
||||
@Test
|
||||
public void rightIsCompositePrimaryKeyReturnsOne() {
|
||||
|
||||
when(left.isCompositePrimaryKey()).thenReturn(false);
|
||||
when(left.isPrimaryKeyColumn()).thenReturn(false);
|
||||
when(right.isCompositePrimaryKey()).thenReturn(true);
|
||||
when(right.isPrimaryKeyColumn()).thenReturn(false);
|
||||
|
||||
assertThat(CassandraPersistentPropertyComparator.IT.compare(left, right)).isEqualTo(1);
|
||||
assertThat(INSTANCE.compare(left, right)).isEqualTo(1);
|
||||
|
||||
verify(left, times(1)).isCompositePrimaryKey();
|
||||
verify(left, times(1)).isPrimaryKeyColumn();
|
||||
@@ -125,14 +161,18 @@ public class CassandraPersistentPropertyComparatorUnitTests {
|
||||
verify(right, times(1)).isPrimaryKeyColumn();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACASS-248
|
||||
*/
|
||||
@Test
|
||||
public void rightIsPrimaryKeyColumnReturnsOne() {
|
||||
|
||||
when(left.isCompositePrimaryKey()).thenReturn(false);
|
||||
when(left.isPrimaryKeyColumn()).thenReturn(false);
|
||||
when(right.isCompositePrimaryKey()).thenReturn(false);
|
||||
when(right.isPrimaryKeyColumn()).thenReturn(true);
|
||||
|
||||
assertThat(CassandraPersistentPropertyComparator.IT.compare(left, right)).isEqualTo(1);
|
||||
assertThat(INSTANCE.compare(left, right)).isEqualTo(1);
|
||||
|
||||
verify(left, times(1)).isCompositePrimaryKey();
|
||||
verify(left, times(1)).isPrimaryKeyColumn();
|
||||
@@ -140,6 +180,9 @@ public class CassandraPersistentPropertyComparatorUnitTests {
|
||||
verify(right, times(1)).isPrimaryKeyColumn();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACASS-248
|
||||
*/
|
||||
@Test
|
||||
public void compareLeftAndRightNamesReturnsNegativeValue() {
|
||||
|
||||
@@ -150,7 +193,7 @@ public class CassandraPersistentPropertyComparatorUnitTests {
|
||||
when(left.getColumnName()).thenReturn(CqlIdentifier.cqlId("left"));
|
||||
when(right.getColumnName()).thenReturn(CqlIdentifier.cqlId("right"));
|
||||
|
||||
assertThat(CassandraPersistentPropertyComparator.INSTANCE.compare(left, right)).isLessThan(0);
|
||||
assertThat(INSTANCE.compare(left, right)).isLessThan(0);
|
||||
|
||||
verify(left, times(1)).isCompositePrimaryKey();
|
||||
verify(left, times(1)).isPrimaryKeyColumn();
|
||||
@@ -173,9 +216,9 @@ public class CassandraPersistentPropertyComparatorUnitTests {
|
||||
CassandraPersistentProperty another = persistentEntity.getPersistentProperty("anotherAnnotated");
|
||||
CassandraPersistentProperty plain = persistentEntity.getPersistentProperty("plain");
|
||||
|
||||
assertThat(CassandraPersistentPropertyComparator.IT.compare(annotated, plain)).isLessThanOrEqualTo(-1);
|
||||
assertThat(CassandraPersistentPropertyComparator.IT.compare(plain, annotated)).isGreaterThanOrEqualTo(1);
|
||||
assertThat(CassandraPersistentPropertyComparator.IT.compare(another, another)).isEqualTo(0);
|
||||
assertThat(INSTANCE.compare(annotated, plain)).isLessThanOrEqualTo(-1);
|
||||
assertThat(INSTANCE.compare(plain, annotated)).isGreaterThanOrEqualTo(1);
|
||||
assertThat(INSTANCE.compare(another, another)).isEqualTo(0);
|
||||
}
|
||||
|
||||
static class TwoColumns {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2016 the original author or authors
|
||||
* Copyright 2013-2017 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.
|
||||
@@ -13,10 +13,10 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.cassandra.mapping;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.springframework.data.cassandra.mapping.CassandraPrimaryKeyColumnAnnotationComparator.*;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.UUID;
|
||||
@@ -31,19 +31,19 @@ import org.springframework.cassandra.core.PrimaryKeyType;
|
||||
* and functionality of the {@link CassandraPrimaryKeyColumnAnnotationComparator} class.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.springframework.data.cassandra.mapping.CassandraPrimaryKeyColumnAnnotationComparator
|
||||
* @since 1.5.0
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
public class CassandraPrimaryKeyColumnAnnotationComparatorUnitTests {
|
||||
|
||||
private static PrimaryKeyColumn entityOne;
|
||||
private static PrimaryKeyColumn entityTwo;
|
||||
private static PrimaryKeyColumn entityThree;
|
||||
private static PrimaryKeyColumn entityFour;
|
||||
private static PrimaryKeyColumn entityFive;
|
||||
static PrimaryKeyColumn entityOne;
|
||||
static PrimaryKeyColumn entityTwo;
|
||||
static PrimaryKeyColumn entityThree;
|
||||
static PrimaryKeyColumn entityFour;
|
||||
static PrimaryKeyColumn entityFive;
|
||||
|
||||
@BeforeClass
|
||||
public static void setup() throws Exception {
|
||||
|
||||
entityOne = EntityOne.class.getDeclaredField("id").getAnnotation(PrimaryKeyColumn.class);
|
||||
entityTwo = EntityTwo.class.getDeclaredField("id").getAnnotation(PrimaryKeyColumn.class);
|
||||
entityThree = EntityThree.class.getDeclaredField("id").getAnnotation(PrimaryKeyColumn.class);
|
||||
@@ -51,32 +51,48 @@ public class CassandraPrimaryKeyColumnAnnotationComparatorUnitTests {
|
||||
entityFive = EntityFive.class.getDeclaredField("id").getAnnotation(PrimaryKeyColumn.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACASS-248
|
||||
*/
|
||||
@Test
|
||||
public void compareTypes() {
|
||||
assertThat(CassandraPrimaryKeyColumnAnnotationComparator.IT.compare(entityOne, entityTwo)).isEqualTo(1);
|
||||
assertThat(CassandraPrimaryKeyColumnAnnotationComparator.IT.compare(entityTwo, entityTwo)).isEqualTo(0);
|
||||
assertThat(CassandraPrimaryKeyColumnAnnotationComparator.IT.compare(entityTwo, entityOne)).isEqualTo(-1);
|
||||
|
||||
assertThat(INSTANCE.compare(entityOne, entityTwo)).isEqualTo(1);
|
||||
assertThat(INSTANCE.compare(entityTwo, entityTwo)).isEqualTo(0);
|
||||
assertThat(INSTANCE.compare(entityTwo, entityOne)).isEqualTo(-1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACASS-248
|
||||
*/
|
||||
@Test
|
||||
public void compareOrdinals() {
|
||||
assertThat(CassandraPrimaryKeyColumnAnnotationComparator.IT.compare(entityOne, entityThree)).isEqualTo(-1);
|
||||
assertThat(CassandraPrimaryKeyColumnAnnotationComparator.IT.compare(entityThree, entityThree)).isEqualTo(0);
|
||||
assertThat(CassandraPrimaryKeyColumnAnnotationComparator.IT.compare(entityThree, entityOne)).isEqualTo(1);
|
||||
|
||||
assertThat(INSTANCE.compare(entityOne, entityThree)).isEqualTo(-1);
|
||||
assertThat(INSTANCE.compare(entityThree, entityThree)).isEqualTo(0);
|
||||
assertThat(INSTANCE.compare(entityThree, entityOne)).isEqualTo(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACASS-248
|
||||
*/
|
||||
@Test
|
||||
public void compareName() {
|
||||
assertThat(CassandraPrimaryKeyColumnAnnotationComparator.IT.compare(entityOne, entityFour)).isEqualTo(-1);
|
||||
assertThat(CassandraPrimaryKeyColumnAnnotationComparator.IT.compare(entityFour, entityFour)).isEqualTo(0);
|
||||
assertThat(CassandraPrimaryKeyColumnAnnotationComparator.IT.compare(entityFour, entityOne)).isEqualTo(1);
|
||||
|
||||
assertThat(INSTANCE.compare(entityOne, entityFour)).isEqualTo(-1);
|
||||
assertThat(INSTANCE.compare(entityFour, entityFour)).isEqualTo(0);
|
||||
assertThat(INSTANCE.compare(entityFour, entityOne)).isEqualTo(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACASS-248
|
||||
*/
|
||||
@Test
|
||||
public void compareOrdering() {
|
||||
assertThat(CassandraPrimaryKeyColumnAnnotationComparator.IT.compare(entityOne, entityFive)).isEqualTo(-1);
|
||||
assertThat(CassandraPrimaryKeyColumnAnnotationComparator.IT.compare(entityFive, entityFive)).isEqualTo(0);
|
||||
assertThat(CassandraPrimaryKeyColumnAnnotationComparator.IT.compare(entityFive, entityOne)).isEqualTo(1);
|
||||
|
||||
assertThat(INSTANCE.compare(entityOne, entityFive)).isEqualTo(-1);
|
||||
assertThat(INSTANCE.compare(entityFive, entityFive)).isEqualTo(0);
|
||||
assertThat(INSTANCE.compare(entityFive, entityOne)).isEqualTo(1);
|
||||
}
|
||||
|
||||
static class EntityOne {
|
||||
|
||||
Reference in New Issue
Block a user