diff --git a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/ShardingSphereMetaDataTest.java b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/ShardingSphereMetaDataTest.java index 9220183637953..d9c1147adbdb9 100644 --- a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/ShardingSphereMetaDataTest.java +++ b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/ShardingSphereMetaDataTest.java @@ -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 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 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)); + } }