Skip to content

Commit

Permalink
HSEARCH-3877 Replace SubTest.expectException with Assertions.assertTh…
Browse files Browse the repository at this point in the history
…rownBy()

For consistency, and because custom code is not necessary in this case.
  • Loading branch information
yrodiere committed Apr 2, 2020
1 parent 475ae65 commit af4f1ec
Show file tree
Hide file tree
Showing 121 changed files with 862 additions and 1,452 deletions.
Expand Up @@ -84,7 +84,7 @@ public void testValid() {
public void testInvalid() {
String invalidVersionString = versionString.substring( 0, versionString.length() - 1 ) + "-A-B";
doMock( invalidVersionString );
assertThatThrownBy( () -> ElasticsearchClientUtils.getElasticsearchVersion( clientMock ) )
assertThatThrownBy( () -> ElasticsearchClientUtils.getElasticsearchVersion( clientMock ) )
.is( matching( ExceptionMatcherBuilder.isException( SearchException.class )
.withMessage( "HSEARCH400080" )
.causedBy( SearchException.class )
Expand Down
Expand Up @@ -7,6 +7,7 @@
package org.hibernate.search.backend.elasticsearch.dialect.impl;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

import org.hibernate.search.backend.elasticsearch.ElasticsearchVersion;
import org.hibernate.search.backend.elasticsearch.dialect.model.impl.Elasticsearch56ModelDialect;
Expand All @@ -21,7 +22,6 @@
import org.hibernate.search.backend.elasticsearch.dialect.protocol.impl.Elasticsearch70ProtocolDialect;
import org.hibernate.search.backend.elasticsearch.dialect.protocol.impl.ElasticsearchProtocolDialect;
import org.hibernate.search.util.common.SearchException;
import org.hibernate.search.util.impl.test.SubTest;
import org.hibernate.search.util.impl.test.annotation.TestForIssue;
import org.hibernate.search.util.impl.test.rule.ExpectedLog4jLog;

Expand Down Expand Up @@ -388,26 +388,24 @@ public void es800() {
}

private void testUnsupported(String unsupportedVersionString) {
SubTest.expectException(
"Test unsupported version " + unsupportedVersionString,
assertThatThrownBy(
() -> {
dialectFactory.createModelDialect( ElasticsearchVersion.of( unsupportedVersionString ) );
}
},
"Test unsupported version " + unsupportedVersionString
)
.assertThrown()
.isInstanceOf( SearchException.class )
.hasMessageContaining( "HSEARCH400081" )
.hasMessageContaining( "'" + unsupportedVersionString + "'" );
}

private void testAmbiguous(String versionString) {
SubTest.expectException(
"Test ambiguous version " + versionString,
assertThatThrownBy(
() -> {
dialectFactory.createModelDialect( ElasticsearchVersion.of( versionString ) );
}
},
"Test ambiguous version " + versionString
)
.assertThrown()
.isInstanceOf( SearchException.class )
.hasMessageContaining( "HSEARCH400561" )
.hasMessageContaining( "Ambiguous Elasticsearch version: '" + versionString + "'." )
Expand Down
Expand Up @@ -18,7 +18,7 @@
import org.hibernate.search.backend.lucene.lowlevel.writer.impl.IndexWriterProvider;
import org.hibernate.search.engine.reporting.spi.EventContexts;
import org.hibernate.search.util.common.reporting.EventContext;
import org.hibernate.search.util.impl.test.SubTest;
import org.assertj.core.api.Assertions;

import org.junit.After;
import org.junit.Before;
Expand Down Expand Up @@ -92,8 +92,7 @@ public void commit_runtimeException() {
indexWriterDelegatorMock.commit();
expectLastCall().andThrow( exception );
replayAll();
SubTest.expectException( () -> accessor.commit() )
.assertThrown()
Assertions.assertThatThrownBy( () -> accessor.commit() )
.isSameAs( exception );
verifyAll();
}
Expand Down Expand Up @@ -127,8 +126,7 @@ public void commitOrDelay_runtimeException() {
indexWriterDelegatorMock.commitOrDelay();
expectLastCall().andThrow( exception );
replayAll();
SubTest.expectException( () -> accessor.commitOrDelay() )
.assertThrown()
Assertions.assertThatThrownBy( () -> accessor.commitOrDelay() )
.isSameAs( exception );
verifyAll();
}
Expand All @@ -150,8 +148,7 @@ public void refresh_runtimeException() {
indexReaderProviderMock.refresh();
expectLastCall().andThrow( exception );
replayAll();
SubTest.expectException( () -> accessor.refresh() )
.assertThrown()
Assertions.assertThatThrownBy( () -> accessor.refresh() )
.isSameAs( exception );
verifyAll();
}
Expand Down
Expand Up @@ -21,7 +21,7 @@
import org.hibernate.search.backend.lucene.work.impl.IndexingWorkExecutionContext;
import org.hibernate.search.engine.reporting.spi.EventContexts;
import org.hibernate.search.util.common.reporting.EventContext;
import org.hibernate.search.util.impl.test.SubTest;
import org.assertj.core.api.Assertions;

import org.junit.Test;

Expand Down Expand Up @@ -94,8 +94,8 @@ public void error_workExecute() throws IOException {
expectWorkGetInfo( 50 );
indexAccessorMock.cleanUpAfterFailure( workException, workInfo( 50 ) );
replayAll();
SubTest.expectException( () -> processor.submit( failingWork ) )
.assertThrown().isSameAs( workException );
Assertions.assertThatThrownBy( () -> processor.submit( failingWork ) )
.isSameAs( workException );
verifyAll();

// Subsequent works must be executed regardless of previous failures in the same batch
Expand Down Expand Up @@ -127,8 +127,7 @@ public void error_forceCommit() throws IOException {
expectLastCall().andThrow( commitException );
indexAccessorMock.cleanUpAfterFailure( commitException, "Commit after a set of index works" );
replayAll();
SubTest.expectException( () -> processor.forceCommit() )
.assertThrown()
Assertions.assertThatThrownBy( () -> processor.forceCommit() )
.isSameAs( commitException );
verifyAll();

Expand Down Expand Up @@ -157,8 +156,7 @@ public void error_forceRefresh() {
indexAccessorMock.refresh();
expectLastCall().andThrow( refreshException );
replayAll();
SubTest.expectException( () -> processor.forceRefresh() )
.assertThrown()
Assertions.assertThatThrownBy( () -> processor.forceRefresh() )
.isSameAs( refreshException );
verifyAll();
}
Expand Down
Expand Up @@ -24,7 +24,7 @@
import org.hibernate.search.util.impl.integrationtest.common.rule.BackendConfiguration;
import org.hibernate.search.util.impl.integrationtest.mapper.orm.OrmSetupHelper;
import org.hibernate.search.util.impl.integrationtest.mapper.orm.OrmUtils;
import org.hibernate.search.util.impl.test.SubTest;
import org.assertj.core.api.Assertions;

import org.junit.Before;
import org.junit.Rule;
Expand Down Expand Up @@ -86,7 +86,7 @@ public void search_separateQueries() {

@Test
public void search_singleQuery() {
SubTest.expectException(
Assertions.assertThatThrownBy(
() -> OrmUtils.withinJPATransaction( entityManagerFactory, entityManager -> {
SearchSession searchSession = Search.session( entityManager );

Expand All @@ -100,7 +100,6 @@ public void search_singleQuery() {
// end::cross-backend-search[]
} )
)
.assertThrown()
.isInstanceOf( SearchException.class )
.hasMessageContaining( "A multi-index scope cannot include both " )
.hasMessageContaining( " and another type of index" );
Expand Down
Expand Up @@ -21,7 +21,7 @@
import org.hibernate.search.util.impl.integrationtest.common.rule.BackendConfiguration;
import org.hibernate.search.util.impl.integrationtest.mapper.orm.OrmSetupHelper;
import org.hibernate.search.util.impl.integrationtest.mapper.orm.OrmUtils;
import org.hibernate.search.util.impl.test.SubTest;
import org.assertj.core.api.Assertions;

import org.junit.Before;
import org.junit.Rule;
Expand Down Expand Up @@ -108,22 +108,20 @@ public void smoke() {

SearchMapping searchMapping = Search.mapping( entityManagerFactory );

SubTest.expectException(
Assertions.assertThatThrownBy(
() -> {
searchMapping.scope( Human.class ).predicate()
.match().field( "parents.parents.nickname" );
}
)
.assertThrown()
.isInstanceOf( SearchException.class )
.hasMessageContaining( "Unknown field" );
SubTest.expectException(
Assertions.assertThatThrownBy(
() -> {
searchMapping.scope( Human.class ).predicate()
.match().field( "parents.parents.parents.name" );
}
)
.assertThrown()
.isInstanceOf( SearchException.class )
.hasMessageContaining( "Unknown field" );

Expand Down
Expand Up @@ -21,7 +21,7 @@
import org.hibernate.search.util.impl.integrationtest.common.rule.BackendConfiguration;
import org.hibernate.search.util.impl.integrationtest.mapper.orm.OrmSetupHelper;
import org.hibernate.search.util.impl.integrationtest.mapper.orm.OrmUtils;
import org.hibernate.search.util.impl.test.SubTest;
import org.assertj.core.api.Assertions;

import org.junit.Before;
import org.junit.Rule;
Expand Down Expand Up @@ -110,22 +110,20 @@ public void smoke() {

SearchMapping searchMapping = Search.mapping( entityManagerFactory );

SubTest.expectException(
Assertions.assertThatThrownBy(
() -> {
searchMapping.scope( Human.class ).predicate()
.match().field( "parents.parents.parents.nickname" );
}
)
.assertThrown()
.isInstanceOf( SearchException.class )
.hasMessageContaining( "Unknown field" );
SubTest.expectException(
Assertions.assertThatThrownBy(
() -> {
searchMapping.scope( Human.class ).predicate()
.match().field( "parents.parents.parents.parents.name" );
}
)
.assertThrown()
.isInstanceOf( SearchException.class )
.hasMessageContaining( "Unknown field" );
}
Expand Down
Expand Up @@ -18,7 +18,7 @@
import org.hibernate.search.engine.environment.bean.BeanReference;
import org.hibernate.search.engine.environment.bean.BeanResolver;
import org.hibernate.search.engine.testsupport.util.AbstractBeanResolverPartialMock;
import org.hibernate.search.util.impl.test.SubTest;
import org.assertj.core.api.Assertions;

import org.junit.Test;

Expand Down Expand Up @@ -260,8 +260,7 @@ public void invalidType() {
EasyMock.expect( sourceMock.get( key ) ).andReturn( (Optional) Optional.of( invalidTypeValue ) );
EasyMock.expect( sourceMock.resolve( key ) ).andReturn( Optional.of( resolvedKey ) );
replayAll();
SubTest.expectException( () -> property.get( sourceMock ) )
.assertThrown()
Assertions.assertThatThrownBy( () -> property.get( sourceMock ) )
.hasMessageContaining(
"Unable to convert configuration property '" + resolvedKey
+ "' with value '" + invalidTypeValue + "':"
Expand Down Expand Up @@ -290,12 +289,11 @@ public void invalidReference() {
EasyMock.expect( beanResolverMock.resolve( StubBean.class, "name" ) )
.andThrow( simulatedFailure );
replayAll();
SubTest.expectException(
Assertions.assertThatThrownBy(
() -> {
property.getAndMap( sourceMock, beanResolverMock::resolve );
}
)
.assertThrown()
.hasCause( simulatedFailure )
.hasMessageContaining(
"Unable to convert configuration property '" + resolvedKey
Expand Down Expand Up @@ -327,12 +325,11 @@ public void multiValued_invalidReference() {
.andThrow( simulatedFailure );
bean1Mock.close(); // Expect the first bean holder to be closed
replayAll();
SubTest.expectException(
Assertions.assertThatThrownBy(
() -> {
property.getAndMap( sourceMock, beanResolverMock::resolve );
}
)
.assertThrown()
.hasCause( simulatedFailure )
.hasMessageContaining(
"Unable to convert configuration property '" + resolvedKey
Expand Down
Expand Up @@ -15,7 +15,7 @@
import java.util.function.Function;

import org.hibernate.search.util.common.SearchException;
import org.hibernate.search.util.impl.test.SubTest;
import org.assertj.core.api.Assertions;

import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down Expand Up @@ -101,8 +101,7 @@ public void withDefault() {
EasyMock.expect( sourceMock.get( key ) ).andReturn( (Optional) Optional.of( invalidStringValue ) );
EasyMock.expect( sourceMock.resolve( key ) ).andReturn( Optional.of( resolvedKey ) );
replayAll();
SubTest.expectException( () -> property.get( sourceMock ) )
.assertThrown()
Assertions.assertThatThrownBy( () -> property.get( sourceMock ) )
.hasMessageContaining(
"Unable to convert configuration property '" + resolvedKey
+ "' with value '" + invalidStringValue + "':"
Expand All @@ -116,8 +115,7 @@ public void withDefault() {
EasyMock.expect( sourceMock.get( key ) ).andReturn( (Optional) Optional.of( invalidTypeValue ) );
EasyMock.expect( sourceMock.resolve( key ) ).andReturn( Optional.of( resolvedKey ) );
replayAll();
SubTest.expectException( () -> property.get( sourceMock ) )
.assertThrown()
Assertions.assertThatThrownBy( () -> property.get( sourceMock ) )
.hasMessageContaining(
"Unable to convert configuration property '" + resolvedKey
+ "' with value '" + invalidTypeValue + "':"
Expand All @@ -140,8 +138,7 @@ public void withoutDefault() {
EasyMock.expect( sourceMock.get( key ) ).andReturn( (Optional) Optional.of( invalidStringValue ) );
EasyMock.expect( sourceMock.resolve( key ) ).andReturn( Optional.of( resolvedKey ) );
replayAll();
SubTest.expectException( () -> property.get( sourceMock ) )
.assertThrown()
Assertions.assertThatThrownBy( () -> property.get( sourceMock ) )
.hasMessageContaining(
"Unable to convert configuration property '" + resolvedKey
+ "' with value '" + invalidStringValue + "':"
Expand All @@ -155,8 +152,7 @@ public void withoutDefault() {
EasyMock.expect( sourceMock.get( key ) ).andReturn( (Optional) Optional.of( invalidTypeValue ) );
EasyMock.expect( sourceMock.resolve( key ) ).andReturn( Optional.of( resolvedKey ) );
replayAll();
SubTest.expectException( () -> property.get( sourceMock ) )
.assertThrown()
Assertions.assertThatThrownBy( () -> property.get( sourceMock ) )
.hasMessageContaining(
"Unable to convert configuration property '" + resolvedKey
+ "' with value '" + invalidTypeValue + "':"
Expand All @@ -181,8 +177,7 @@ public void multiValued() {
EasyMock.expect( sourceMock.get( key ) ).andReturn( (Optional) Optional.of( invalidStringValue ) );
EasyMock.expect( sourceMock.resolve( key ) ).andReturn( Optional.of( resolvedKey ) );
replayAll();
SubTest.expectException( () -> property.get( sourceMock ) )
.assertThrown()
Assertions.assertThatThrownBy( () -> property.get( sourceMock ) )
.hasMessageContaining(
"Unable to convert configuration property '" + resolvedKey
+ "' with value '" + invalidStringValue + "':"
Expand All @@ -197,8 +192,7 @@ public void multiValued() {
EasyMock.expect( sourceMock.get( key ) ).andReturn( (Optional) Optional.of( commaSeparatedStringValue ) );
EasyMock.expect( sourceMock.resolve( key ) ).andReturn( Optional.of( resolvedKey ) );
replayAll();
SubTest.expectException( () -> property.get( sourceMock ) )
.assertThrown()
Assertions.assertThatThrownBy( () -> property.get( sourceMock ) )
.hasMessageContaining(
"Unable to convert configuration property '" + resolvedKey
+ "' with value '" + commaSeparatedStringValue + "':"
Expand All @@ -213,8 +207,7 @@ public void multiValued() {
EasyMock.expect( sourceMock.get( key ) ).andReturn( (Optional) Optional.of( invalidTypeValueCollection ) );
EasyMock.expect( sourceMock.resolve( key ) ).andReturn( Optional.of( resolvedKey ) );
replayAll();
SubTest.expectException( () -> property.get( sourceMock ) )
.assertThrown()
Assertions.assertThatThrownBy( () -> property.get( sourceMock ) )
.hasMessageContaining(
"Unable to convert configuration property '" + resolvedKey
+ "' with value '" + invalidTypeValueCollection + "':"
Expand All @@ -228,8 +221,7 @@ public void multiValued() {
EasyMock.expect( sourceMock.get( key ) ).andReturn( (Optional) Optional.of( invalidTypeValue ) );
EasyMock.expect( sourceMock.resolve( key ) ).andReturn( Optional.of( resolvedKey ) );
replayAll();
SubTest.expectException( () -> property.get( sourceMock ) )
.assertThrown()
Assertions.assertThatThrownBy( () -> property.get( sourceMock ) )
.hasMessageContaining(
"Unable to convert configuration property '" + resolvedKey
+ "' with value '" + invalidTypeValue + "':"
Expand Down

0 comments on commit af4f1ec

Please sign in to comment.