Skip to content

Commit

Permalink
Junit for ShardingSphereMetaData (#28564) (#28576)
Browse files Browse the repository at this point in the history
* Junit for ShardingSphereMetaData (#28564)

* code style fixes ShardingSphereMetaDataTest (#28564)
  • Loading branch information
sayyidhussain authored Sep 28, 2023
1 parent 5eb742b commit b103ffa
Showing 1 changed file with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,26 @@ private ShardingSphereDatabase mockDatabase(final ResourceMetaData resourceMetaD
when(result.getRuleMetaData()).thenReturn(new RuleMetaData(Collections.singleton(databaseResourceHeldRule)));
return result;
}

@Test
void assertContainsDatabase() {
ResourceHeldRule<?> globalResourceHeldRule = mock(ResourceHeldRule.class);
ShardingSphereDatabase database = mockDatabase(mock(ResourceMetaData.class, RETURNS_DEEP_STUBS), new MockedDataSource(), globalResourceHeldRule);
Map<String, ShardingSphereDatabase> databases = new HashMap<>(Collections.singletonMap("foo_db", database));
ConfigurationProperties configProps = new ConfigurationProperties(new Properties());
ShardingSphereMetaData metaData = new ShardingSphereMetaData(databases, mock(ResourceMetaData.class),
new RuleMetaData(Collections.singleton(globalResourceHeldRule)), configProps);
assertTrue(metaData.containsDatabase("foo_db"));
}

@Test
void assertGetDatabase() {
ResourceHeldRule<?> globalResourceHeldRule = mock(ResourceHeldRule.class);
ShardingSphereDatabase database = mockDatabase(mock(ResourceMetaData.class, RETURNS_DEEP_STUBS), new MockedDataSource(), globalResourceHeldRule);
Map<String, ShardingSphereDatabase> databases = new HashMap<>(Collections.singletonMap("foo_db", database));
ConfigurationProperties configProps = new ConfigurationProperties(new Properties());
ShardingSphereMetaData metaData = new ShardingSphereMetaData(databases, mock(ResourceMetaData.class),
new RuleMetaData(Collections.singleton(globalResourceHeldRule)), configProps);
assertThat(metaData.getDatabase("foo_db"), is(database));
}
}

0 comments on commit b103ffa

Please sign in to comment.