DATACASS-202 - Polishing.

Add author tags. Extend date range in headers. Simplify resolution by removing intermediate variables. Add test to verify ConsistencyLevel resolution. Guard consistency level against null.

Originall pull request: #54.
This commit is contained in:
Mark Paluch
2016-07-28 15:12:58 +02:00
parent da263df25c
commit 43ab34ac54
3 changed files with 112 additions and 31 deletions

View File

@@ -0,0 +1,91 @@
/*
* Copyright 2016 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.cassandra.core;
import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.Matchers.*;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
/**
* Unit tests for {@link ConsistencyLevelResolver}.
*
* @author Mark Paluch
* @see DATACASS-202
*/
@RunWith(Parameterized.class)
public class ConsistencyLevelResolverUnitTests {
private final ConsistencyLevel from;
private final com.datastax.driver.core.ConsistencyLevel expected;
public ConsistencyLevelResolverUnitTests(ConsistencyLevel from, com.datastax.driver.core.ConsistencyLevel expected) {
this.from = from;
this.expected = expected;
}
@Parameters(name = "{0}")
public static List<Object[]> parameters() {
Map<ConsistencyLevel, com.datastax.driver.core.ConsistencyLevel> expectations = new LinkedHashMap<ConsistencyLevel, com.datastax.driver.core.ConsistencyLevel>();
expectations.put(ConsistencyLevel.ALL, com.datastax.driver.core.ConsistencyLevel.ALL);
expectations.put(ConsistencyLevel.ANY, com.datastax.driver.core.ConsistencyLevel.ANY);
expectations.put(ConsistencyLevel.QUOROM, com.datastax.driver.core.ConsistencyLevel.QUORUM);
expectations.put(ConsistencyLevel.QUORUM, com.datastax.driver.core.ConsistencyLevel.QUORUM);
expectations.put(ConsistencyLevel.LOCAL_QUOROM, com.datastax.driver.core.ConsistencyLevel.LOCAL_QUORUM);
expectations.put(ConsistencyLevel.LOCAL_QUORUM, com.datastax.driver.core.ConsistencyLevel.LOCAL_QUORUM);
expectations.put(ConsistencyLevel.EACH_QUOROM, com.datastax.driver.core.ConsistencyLevel.EACH_QUORUM);
expectations.put(ConsistencyLevel.EACH_QUORUM, com.datastax.driver.core.ConsistencyLevel.EACH_QUORUM);
expectations.put(ConsistencyLevel.LOCAL_ONE, com.datastax.driver.core.ConsistencyLevel.LOCAL_ONE);
expectations.put(ConsistencyLevel.LOCAL_SERIAL, com.datastax.driver.core.ConsistencyLevel.LOCAL_SERIAL);
expectations.put(ConsistencyLevel.SERIAL, com.datastax.driver.core.ConsistencyLevel.SERIAL);
expectations.put(ConsistencyLevel.ONE, com.datastax.driver.core.ConsistencyLevel.ONE);
expectations.put(ConsistencyLevel.TWO, com.datastax.driver.core.ConsistencyLevel.TWO);
expectations.put(ConsistencyLevel.THREE, com.datastax.driver.core.ConsistencyLevel.THREE);
List<Object[]> parameters = new ArrayList<Object[]>();
for (Entry<ConsistencyLevel, com.datastax.driver.core.ConsistencyLevel> entry : expectations.entrySet()) {
parameters.add(new Object[] { entry.getKey(), entry.getValue() });
}
return parameters;
}
/**
* @see DATACASS-202
*/
@Test
public void shouldResolveCorrectly() {
assertThat(ConsistencyLevelResolver.resolve(from), is(equalTo(expected)));
}
}