首页 > 解决方案 > 在Java中使用默认说明符声明Hashmap时如何将Hashmap传递给另一个类(不同的包)

问题描述

Hacker Rank 提出了 SDET 编码挑战。

结构

在此处输入图像描述

类 DataEntryAutomationTest

public class DataEntryAutomationTest {

private static WebDriver driver = null;
private static String pagUrl = null;

static Map<String, String> data = null;

@SuppressWarnings("unchecked")
@BeforeClass
public static void setup() {  //code for initializing driver.         
    data = new HashMap() {
        {
            put("11", "day");
            put("July", "month");
            put("1990", "year");
            put("favorite_language", "Java,Python");
            put("favorite_os", "Linux,Mac OSX");
            put("favorite_idea", "IntelliJ IDEA");
        }
    };

    pagUrl = "http://localhost:8080/home.html";
}

 @Test
    public void testFillDateOfBirth() {
       DataEntryAutomation.fillDateOfBirth(driver, pagUrl);
 }

 @Test
    public void testAnswerQuestions() {
       DataEntryAutomation.answerQuestions(driver, pagUrl);
 }

类 DataEntryAutomation

public class DataEntryAutomation {

    public static void fillDateOfBirth(WebDriver driver, String pageUrl) {
       //add code to fill the survey
}


public static void answerQuestions(WebDriver driver, String pageUrl) {
     //add code to fill the survey
}

如何将 HashMap 传递给DataEntryAutomation 类,以便我可以使用 HashMap 来填写调查。我的理解是如果没有提到修饰符,那么默认的访问说明符是包。类可以访问同一个包中其他类的成员,但在包外它显示为私有。限制: 我只能编辑 DataEntryAutomation 类

标签: javahashmapparameter-passing

解决方案


推荐阅读