From 4ec5dbdbd67d29f751b3087d8ce9b54244c0ab4a Mon Sep 17 00:00:00 2001 From: sayyidhussain Date: Mon, 25 Sep 2023 12:47:08 +0530 Subject: [PATCH 1/2] Junit for ShardingSphereMetaData (#28564) --- .../metadata/ShardingSphereMetaDataTest.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) 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 28980753c5663..1d0fa15f74673 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 @@ -91,4 +91,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)); + } } From 60fe72f6ca57f785329c0e0098ce1546ae548355 Mon Sep 17 00:00:00 2001 From: sayyidhussain Date: Mon, 25 Sep 2023 21:51:47 +0530 Subject: [PATCH 2/2] code style fixes ShardingSphereMetaDataTest (#28564) --- .../infra/metadata/ShardingSphereMetaDataTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 1d0fa15f74673..180f1883374db 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 @@ -91,7 +91,7 @@ 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); @@ -102,7 +102,7 @@ void assertContainsDatabase() { new RuleMetaData(Collections.singleton(globalResourceHeldRule)), configProps); assertTrue(metaData.containsDatabase("foo_db")); } - + @Test void assertGetDatabase() { ResourceHeldRule globalResourceHeldRule = mock(ResourceHeldRule.class); @@ -111,6 +111,6 @@ void assertGetDatabase() { 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)); + assertThat(metaData.getDatabase("foo_db"), is(database)); } }