'Java slenium wont getProperty when i use switch case

here is my simple code for getting a browser

   public WebDriver initializeDriver() {
        WebDriver driver;
        String browser = System.getProperty("browser");
        switch (browser) {
            case "Chrome" -> {
                WebDriverManager.chromedriver().setup();
                driver = new ChromeDriver();
            }
            case "firefox" -> {
                WebDriverManager.firefoxdriver().setup();
                driver = new FirefoxDriver();
            }
            default -> throw new IllegalStateException("invalid browser name use chrome or firefox" + browser);
        }
        driver.manage().window().maximize();
        return driver;
    }

but when I run mvn test or mvn test -Dbrowser=chrome its throws an error

this is the error

Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:testCompile (default-testCompile) on project SampleAutomationCode: Compilation failure: Compilation failure

and its point the case "Chrome" -> { line as error some one can you help me to solve this



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source