ConsistencyLevelConverter implements Converter<ConsistencyLevel> { @Override public ConsistencyLevel convertFrom(String value) { if (Strings.isNullOrEmpty(value)) { throw new ParameterException("Couldn't convert empty string to a Cassandra consistency level."); } try { return ConsistencyLevel.valueOf(value.toUpperCase(Locale.ENGLISH)); } catch (Exception e) { throw new ParameterException(e.getMessage(), e); } }  @Override ConsistencyLevel convertFrom(String value); @Override String convertTo(ConsistencyLevel value);  }
@Test public void convertFromValidString() throws Exception { final ConsistencyLevel consistencyLevel = new ConsistencyLevelConverter().convertFrom("QUORUM"); assertEquals(ConsistencyLevel.QUORUM, consistencyLevel); }
@Test public void convertFromValidMixedCaseString() throws Exception { final ConsistencyLevel consistencyLevel = new ConsistencyLevelConverter().convertFrom("local_One"); assertEquals(ConsistencyLevel.LOCAL_ONE, consistencyLevel); }
@Test public void convertFromInvalidString() throws Exception { expectedException.expect(ParameterException.class); expectedException.expectMessage("No enum constant com.datastax.driver.core.ConsistencyLevel.FOOBAR"); new ConsistencyLevelConverter().convertFrom("foobar"); }
@Test public void convertFromNull() throws Exception { expectedException.expect(ParameterException.class); expectedException.expectMessage("Couldn't convert empty string to a Cassandra consistency level."); new ConsistencyLevelConverter().convertFrom(null); }
@Test public void convertFromEmptyString() throws Exception { expectedException.expect(ParameterException.class); expectedException.expectMessage("Couldn't convert empty string to a Cassandra consistency level."); new ConsistencyLevelConverter().convertFrom(""); }