forked from apache/cassandra-java-driver
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
core/src/test/java/com/datastax/oss/driver/internal/core/resolver/ResolverProviderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.datastax.oss.driver.internal.core.resolver; | ||
|
||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; | ||
|
||
import com.datastax.oss.driver.internal.core.resolver.mockResolver.MockResolverFactory; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
public class ResolverProviderTest { | ||
|
||
@Before | ||
public void resetState() { | ||
ResolverProvider.resetBooleansForTesting(); | ||
} | ||
|
||
@Test(expected = IllegalStateException.class) | ||
public void should_not_allow_setting_twice() { | ||
try { | ||
MockResolverFactory first = new MockResolverFactory(); | ||
MockResolverFactory second = new MockResolverFactory(); | ||
ResolverProvider.setDefaultResolverFactory(first); | ||
ResolverProvider.setDefaultResolverFactory(second); | ||
} catch (IllegalStateException ex) { | ||
assertThat(ex.getMessage()) | ||
.isEqualTo( | ||
"Cannot change default resolver factory: this method has already been called. You can set " | ||
+ "default resolver factory only once."); | ||
throw ex; | ||
} | ||
} | ||
|
||
@Test(expected = IllegalStateException.class) | ||
public void should_not_allow_setting_once_in_use() { | ||
try { | ||
ResolverProvider.getResolver(ResolverProviderTest.class); | ||
MockResolverFactory first = new MockResolverFactory(); | ||
ResolverProvider.setDefaultResolverFactory(first); | ||
} catch (IllegalStateException ex) { | ||
assertThat(ex.getMessage()) | ||
.isEqualTo( | ||
"Cannot change default resolver factory: ResolverProvider has already returned an instance of a " | ||
+ "Resolver to use. Default resolver factory needs to be set up before first use by any class."); | ||
throw ex; | ||
} | ||
} | ||
|
||
@Test | ||
public void should_allow_setting_once() { | ||
MockResolverFactory first = new MockResolverFactory(); | ||
ResolverProvider.setDefaultResolverFactory(first); | ||
} | ||
} |