You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2021/09/26 12:22:48 UTC

[GitHub] [dubbo] DiegoKrupitza commented on a change in pull request #8913: Add unit test for StandardMetadataServiceURLBuilder

DiegoKrupitza commented on a change in pull request #8913:
URL: https://github.com/apache/dubbo/pull/8913#discussion_r716195894



##########
File path: dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/client/metadata/StandardMetadataServiceURLBuilderTest.java
##########
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.dubbo.registry.client.metadata;
+
+import org.apache.dubbo.common.URL;
+import org.apache.dubbo.config.ApplicationConfig;
+import org.apache.dubbo.metadata.MetadataService;
+import org.apache.dubbo.registry.client.DefaultServiceInstance;
+import org.apache.dubbo.rpc.model.ApplicationModel;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import java.util.List;
+
+import static org.apache.dubbo.registry.client.metadata.MetadataServiceURLBuilderTest.serviceInstance;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.mockito.Mockito.spy;
+
+/**
+ * {@link StandardMetadataServiceURLBuilder} Test
+ */
+public class StandardMetadataServiceURLBuilderTest {
+
+    private StandardMetadataServiceURLBuilder builder = new StandardMetadataServiceURLBuilder();
+
+
+    @BeforeAll
+    public static void setUp() {
+        ApplicationConfig applicationConfig = new ApplicationConfig("demo");
+        applicationConfig.setMetadataServicePort(7001);
+        ApplicationModel.defaultModel().getApplicationConfigManager().setApplication(applicationConfig);
+    }
+
+    @AfterAll
+    public static void clearUp() {
+        ApplicationModel.reset();
+    }
+
+    @Test
+    public void testBuild() {
+        // test generateUrlWithoutMetadata
+        List<URL> urls = builder.build(new DefaultServiceInstance("test", "127.0.0.1", 8080, ApplicationModel.defaultModel()));
+        assertEquals(1, urls.size());

Review comment:
       You could use Hamcrest here to test the size in a more `fluent` way. 
   For example here you can write: `assertThat(urls, hasSize(1));`
   
   In general this is not really necessary but since Hamcrest is in the project dependencies it would be nice to use it to make Testing more pleasing for the eye (easier reading and writing)




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org