mirror of https://github.com/apache/cassandra
Use assertThatThrownBy in reflective class-loading tests
This commit is contained in:
parent
1906aa5b5f
commit
af8410a0cf
|
|
@ -21,9 +21,9 @@ package org.apache.cassandra.db.marshal;
|
|||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import org.apache.cassandra.config.DatabaseDescriptor;
|
||||
|
|
@ -45,15 +45,9 @@ public class TypeParserTest
|
|||
public void testRejectsNonAbstractTypeWithoutInitializing() throws SyntaxException
|
||||
{
|
||||
ClassLoadingTestSupport.assertNotInitialized(ClassLoadingTestNonAssignable.class);
|
||||
try
|
||||
{
|
||||
TypeParser.parse(ClassLoadingTestNonAssignable.class.getName());
|
||||
fail("Should not pass");
|
||||
}
|
||||
catch (ConfigurationException e)
|
||||
{
|
||||
assertTrue(e.getMessage().contains("must extend or implement " + AbstractType.class.getName()));
|
||||
}
|
||||
assertThatThrownBy(() -> TypeParser.parse(ClassLoadingTestNonAssignable.class.getName()))
|
||||
.isInstanceOf(ConfigurationException.class)
|
||||
.hasMessageContaining("must extend or implement " + AbstractType.class.getName());
|
||||
|
||||
assertFalse(ClassLoadingTestSupport.wasInitialized(ClassLoadingTestNonAssignable.class));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ import org.apache.cassandra.utils.ClassLoadingTestNonAssignable;
|
|||
import org.apache.cassandra.utils.ClassLoadingTestSupport;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
|
||||
public class DiagnosticEventPersistenceTest
|
||||
{
|
||||
|
|
@ -55,15 +55,9 @@ public class DiagnosticEventPersistenceTest
|
|||
{
|
||||
ClassLoadingTestSupport.assertNotInitialized(ClassLoadingTestNonAssignable.class);
|
||||
|
||||
try
|
||||
{
|
||||
getEventClass(ClassLoadingTestNonAssignable.class.getName());
|
||||
fail("Expected InvalidClassException for a non-DiagnosticEvent class");
|
||||
}
|
||||
catch (InvalidClassException e)
|
||||
{
|
||||
assertThat(e.getMessage()).contains("must be of type DiagnosticEvent");
|
||||
}
|
||||
assertThatThrownBy(() -> getEventClass(ClassLoadingTestNonAssignable.class.getName()))
|
||||
.isInstanceOf(InvalidClassException.class)
|
||||
.hasMessageContaining("must be of type DiagnosticEvent");
|
||||
|
||||
assertThat(ClassLoadingTestSupport.wasInitialized(ClassLoadingTestNonAssignable.class)).isFalse();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,6 +46,7 @@ import org.apache.cassandra.utils.JVMStabilityInspector;
|
|||
import org.apache.cassandra.utils.KillerForTests;
|
||||
import org.apache.cassandra.utils.concurrent.Refs;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
|
@ -64,15 +65,9 @@ public class SecondaryIndexManagerTest extends CQLTester
|
|||
public void rejectsNonIndexClassWithoutInitializing()
|
||||
{
|
||||
ClassLoadingTestSupport.assertNotInitialized(ClassLoadingTestNonAssignable.class);
|
||||
try
|
||||
{
|
||||
SecondaryIndexManager.loadIndexClass(ClassLoadingTestNonAssignable.class.getName());
|
||||
fail("Should not pass");
|
||||
}
|
||||
catch (ConfigurationException e)
|
||||
{
|
||||
assertTrue(e.getMessage().contains("must extend or implement " + Index.class.getName()));
|
||||
}
|
||||
assertThatThrownBy(() -> SecondaryIndexManager.loadIndexClass(ClassLoadingTestNonAssignable.class.getName()))
|
||||
.isInstanceOf(ConfigurationException.class)
|
||||
.hasMessageContaining("must extend or implement " + Index.class.getName());
|
||||
|
||||
assertFalse(ClassLoadingTestSupport.wasInitialized(ClassLoadingTestNonAssignable.class));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,6 +39,8 @@ import org.apache.cassandra.utils.ByteBufferUtil;
|
|||
import org.apache.cassandra.utils.ClassLoadingTestNonAssignable;
|
||||
import org.apache.cassandra.utils.ClassLoadingTestSupport;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
|
||||
|
||||
public class IndexModeTest
|
||||
{
|
||||
|
|
@ -217,15 +219,9 @@ public class IndexModeTest
|
|||
ColumnMetadata cd = ColumnMetadata.regularColumn(cfm, ByteBufferUtil.bytes("TestColumnMetadata"), BytesType.instance);
|
||||
|
||||
ClassLoadingTestSupport.assertNotInitialized(ClassLoadingTestNonAssignable.class);
|
||||
try
|
||||
{
|
||||
IndexMode.getMode(cd, Collections.singletonMap("analyzer_class", ClassLoadingTestNonAssignable.class.getName()));
|
||||
Assert.fail("Should not pass");
|
||||
}
|
||||
catch (ConfigurationException e)
|
||||
{
|
||||
Assert.assertTrue(e.getMessage().contains("must extend or implement " + AbstractAnalyzer.class.getName()));
|
||||
}
|
||||
assertThatThrownBy(() -> IndexMode.getMode(cd, Collections.singletonMap("analyzer_class", ClassLoadingTestNonAssignable.class.getName())))
|
||||
.isInstanceOf(ConfigurationException.class)
|
||||
.hasMessageContaining("must extend or implement " + AbstractAnalyzer.class.getName());
|
||||
|
||||
Assert.assertFalse(ClassLoadingTestSupport.wasInitialized(ClassLoadingTestNonAssignable.class));
|
||||
}
|
||||
|
|
@ -249,15 +245,9 @@ public class IndexModeTest
|
|||
ColumnMetadata cd = ColumnMetadata.regularColumn(cfm, ByteBufferUtil.bytes("TestColumnMetadata"), UTF8Type.instance);
|
||||
|
||||
ClassLoadingTestSupport.assertNotInitialized(ClassLoadingTestNonAssignable.class);
|
||||
try
|
||||
{
|
||||
IndexMode.validateAnalyzer(Collections.singletonMap("analyzer_class", ClassLoadingTestNonAssignable.class.getName()), cd);
|
||||
Assert.fail("Should not pass");
|
||||
}
|
||||
catch (ConfigurationException e)
|
||||
{
|
||||
Assert.assertTrue(e.getMessage().contains("must extend or implement " + AbstractAnalyzer.class.getName()));
|
||||
}
|
||||
assertThatThrownBy(() -> IndexMode.validateAnalyzer(Collections.singletonMap("analyzer_class", ClassLoadingTestNonAssignable.class.getName()), cd))
|
||||
.isInstanceOf(ConfigurationException.class)
|
||||
.hasMessageContaining("must extend or implement " + AbstractAnalyzer.class.getName());
|
||||
|
||||
Assert.assertFalse(ClassLoadingTestSupport.wasInitialized(ClassLoadingTestNonAssignable.class));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ import org.apache.cassandra.utils.ClassLoadingTestNonAssignable;
|
|||
import org.apache.cassandra.utils.ClassLoadingTestSupport;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
|
|
@ -52,19 +53,11 @@ public class CipherFactoryTest
|
|||
TransparentDataEncryptionOptions options = EncryptionContextGenerator.createEncryptionOptions();
|
||||
options.key_provider.class_name = ClassLoadingTestNonAssignable.class.getName();
|
||||
|
||||
try
|
||||
{
|
||||
new CipherFactory(options);
|
||||
fail("Expected CipherFactory construction to be rejected for a non-KeyProvider class");
|
||||
}
|
||||
catch (RuntimeException e)
|
||||
{
|
||||
// CipherFactory wraps the load failure; the cause is the type-check ConfigurationException
|
||||
Throwable cause = e.getCause();
|
||||
assertNotNull(cause);
|
||||
assertThat(cause).isInstanceOf(ConfigurationException.class);
|
||||
assertThat(cause.getMessage()).contains("must extend or implement " + KeyProvider.class.getName());
|
||||
}
|
||||
// CipherFactory wraps the load failure; the cause is the type-check ConfigurationException
|
||||
assertThatThrownBy(() -> new CipherFactory(options))
|
||||
.isInstanceOf(RuntimeException.class)
|
||||
.hasCauseInstanceOf(ConfigurationException.class)
|
||||
.hasStackTraceContaining("must extend or implement " + KeyProvider.class.getName());
|
||||
|
||||
assertThat(ClassLoadingTestSupport.wasInitialized(ClassLoadingTestNonAssignable.class)).isFalse();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,9 +49,9 @@ import org.apache.cassandra.config.Config;
|
|||
import org.apache.cassandra.config.DatabaseDescriptor;
|
||||
import org.apache.cassandra.exceptions.ConfigurationException;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
public class FBUtilitiesTest
|
||||
|
|
@ -60,15 +60,9 @@ public class FBUtilitiesTest
|
|||
public void testTypedClassForNameRejectsWithoutInitializing()
|
||||
{
|
||||
ClassLoadingTestSupport.assertNotInitialized(ClassLoadingTestNonAssignable.class);
|
||||
try
|
||||
{
|
||||
FBUtilities.classForNameWithoutInitialization(ClassLoadingTestNonAssignable.class.getName(), "test class", Runnable.class);
|
||||
fail("Should not pass");
|
||||
}
|
||||
catch (ConfigurationException e)
|
||||
{
|
||||
assertTrue(e.getMessage().contains("must extend or implement " + Runnable.class.getName()));
|
||||
}
|
||||
assertThatThrownBy(() -> FBUtilities.classForNameWithoutInitialization(ClassLoadingTestNonAssignable.class.getName(), "test class", Runnable.class))
|
||||
.isInstanceOf(ConfigurationException.class)
|
||||
.hasMessageContaining("must extend or implement " + Runnable.class.getName());
|
||||
|
||||
assertFalse(ClassLoadingTestSupport.wasInitialized(ClassLoadingTestNonAssignable.class));
|
||||
}
|
||||
|
|
@ -77,15 +71,9 @@ public class FBUtilitiesTest
|
|||
public void testTypedConstructRejectsWithoutInitializing()
|
||||
{
|
||||
ClassLoadingTestSupport.assertNotInitialized(ClassLoadingTestNonAssignable.class);
|
||||
try
|
||||
{
|
||||
FBUtilities.construct(ClassLoadingTestNonAssignable.class.getName(), "test class", Runnable.class);
|
||||
fail("Should not pass");
|
||||
}
|
||||
catch (ConfigurationException e)
|
||||
{
|
||||
assertTrue(e.getMessage().contains("must extend or implement " + Runnable.class.getName()));
|
||||
}
|
||||
assertThatThrownBy(() -> FBUtilities.construct(ClassLoadingTestNonAssignable.class.getName(), "test class", Runnable.class))
|
||||
.isInstanceOf(ConfigurationException.class)
|
||||
.hasMessageContaining("must extend or implement " + Runnable.class.getName());
|
||||
|
||||
assertFalse(ClassLoadingTestSupport.wasInitialized(ClassLoadingTestNonAssignable.class));
|
||||
}
|
||||
|
|
@ -94,15 +82,9 @@ public class FBUtilitiesTest
|
|||
public void testTypedInstanceOrConstructRejectsWithoutInitializing()
|
||||
{
|
||||
ClassLoadingTestSupport.assertNotInitialized(ClassLoadingTestNonAssignable.class);
|
||||
try
|
||||
{
|
||||
FBUtilities.instanceOrConstruct(ClassLoadingTestNonAssignable.class.getName(), "test class", Runnable.class);
|
||||
fail("Should not pass");
|
||||
}
|
||||
catch (ConfigurationException e)
|
||||
{
|
||||
assertTrue(e.getMessage().contains("must extend or implement " + Runnable.class.getName()));
|
||||
}
|
||||
assertThatThrownBy(() -> FBUtilities.instanceOrConstruct(ClassLoadingTestNonAssignable.class.getName(), "test class", Runnable.class))
|
||||
.isInstanceOf(ConfigurationException.class)
|
||||
.hasMessageContaining("must extend or implement " + Runnable.class.getName());
|
||||
|
||||
assertFalse(ClassLoadingTestSupport.wasInitialized(ClassLoadingTestNonAssignable.class));
|
||||
}
|
||||
|
|
@ -111,17 +93,10 @@ public class FBUtilitiesTest
|
|||
public void testNewAuditLoggerRejectsWrongTypeWithoutInitializing()
|
||||
{
|
||||
ClassLoadingTestSupport.assertNotInitialized(ClassLoadingTestNonAssignable.class);
|
||||
try
|
||||
{
|
||||
FBUtilities.newAuditLogger(ClassLoadingTestNonAssignable.class.getName(), Collections.emptyMap());
|
||||
fail("Should not pass");
|
||||
}
|
||||
catch (ConfigurationException e)
|
||||
{
|
||||
Throwable cause = e.getCause();
|
||||
assertTrue(cause instanceof ConfigurationException);
|
||||
assertTrue(cause.getMessage().contains("must extend or implement " + IAuditLogger.class.getName()));
|
||||
}
|
||||
assertThatThrownBy(() -> FBUtilities.newAuditLogger(ClassLoadingTestNonAssignable.class.getName(), Collections.emptyMap()))
|
||||
.isInstanceOf(ConfigurationException.class)
|
||||
.hasRootCauseInstanceOf(ConfigurationException.class)
|
||||
.hasStackTraceContaining("must extend or implement " + IAuditLogger.class.getName());
|
||||
|
||||
assertFalse(ClassLoadingTestSupport.wasInitialized(ClassLoadingTestNonAssignable.class));
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue