package org.corpus_tools.annis.gui;

import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import org.junit.jupiter.api.Test;
import org.tomlj.Toml;
import org.tomlj.TomlParseResult;

class ServiceStarterDesktopTest {


  @Test
  void testUnpackToml() {
    TomlParseResult toml = Toml.parse(
        "[main]\n" + "test =\"value\"\n" + "b = [42, 23]\n" + "nested_array = [[1,2]]");
    Map<String, Object> unpacked = ServiceStarterDesktop.unpackToml(toml);

    assertEquals(1, unpacked.size());
    assertTrue(unpacked.get("main") instanceof Map);
    @SuppressWarnings("unchecked")
    Map<String, Object> main = (Map<String, Object>) unpacked.get("main");
    assertEquals(3, main.size());

    assertEquals("value", main.get("test"));
    assertTrue(main.get("b") instanceof List);
    @SuppressWarnings("unchecked")
    List<Object> b = (List<Object>) main.get("b");
    assertEquals(2, b.size());
    assertEquals(42l, b.get(0));
    assertEquals(23l, b.get(1));

    assertTrue(main.get("nested_array") instanceof List);
    @SuppressWarnings("unchecked")
    List<Object> nestedArray = (List<Object>) main.get("nested_array");
    assertEquals(1, nestedArray.size());
    assertTrue(nestedArray.get(0) instanceof List);
    assertEquals(Arrays.asList(1l, 2l), nestedArray.get(0));
  }

}

@@ -71,273 +71,1961 @@
 sert
-True;%0Aimport static org.junit.jupiter.api.Assertions.assertEquals;%0A%0Aimport java.util.Arrays;%0Aimport java.util.List;%0Aimport java.util.Map;%0Aimport org.junit.jupiter.api.Test;%0Aimport org.tomlj.Toml;%0Aimport org.tomlj.TomlParseResult;%0A%0Aclass ServiceStarterDesktopTest %7B%0A
+NotNull;%0Aimport static org.junit.Assert.assertNull;%0Aimport static org.junit.Assert.assertTrue;%0Aimport static org.junit.jupiter.api.Assertions.assertEquals;%0A%0Aimport com.github.mvysny.kaributesting.v8.MockVaadin;%0Aimport com.vaadin.spring.internal.UIScopeImpl;%0Aimport java.util.Arrays;%0Aimport java.util.List;%0Aimport java.util.Map;%0Aimport org.junit.jupiter.api.AfterEach;%0Aimport org.junit.jupiter.api.BeforeEach;%0Aimport org.junit.jupiter.api.Test;%0Aimport org.springframework.beans.factory.BeanFactory;%0Aimport org.springframework.beans.factory.annotation.Autowired;%0Aimport org.springframework.boot.test.context.SpringBootTest;%0Aimport org.springframework.security.core.Authentication;%0Aimport org.springframework.security.core.context.SecurityContext;%0Aimport org.springframework.security.oauth2.core.user.OAuth2User;%0Aimport org.springframework.test.context.ActiveProfiles;%0Aimport org.springframework.test.context.web.WebAppConfiguration;%0Aimport org.tomlj.Toml;%0Aimport org.tomlj.TomlParseResult;%0A%0A@SpringBootTest%0A@ActiveProfiles(%7B%22desktop%22, %22test%22, %22headless%22%7D)%0A@WebAppConfiguration%0Aclass ServiceStarterDesktopTest %7B%0A%0A  @Autowired%0A  private BeanFactory beanFactory;%0A%0A  private AnnisUI ui;%0A%0A  @BeforeEach%0A  public void setup() %7B%0A    UIScopeImpl.setBeanStoreRetrievalStrategy(new SingletonBeanStoreRetrievalStrategy());%0A    ui = beanFactory.getBean(AnnisUI.class);%0A    MockVaadin.setup(() -%3E ui);%0A  %7D%0A%0A  @AfterEach%0A  public void tearDown() %7B%0A    MockVaadin.tearDown();%0A  %7D%0A%0A  @Test%0A  void testDesktopAuthConfigured() %7B%0A    assertNotNull(ui.getLastAccessToken());%0A    SecurityContext ctx = ui.getSecurityContext();%0A    assertNotNull(ctx);%0A    Authentication auth = ctx.getAuthentication();%0A    assertNotNull(auth);%0A%0A    assertTrue(auth.isAuthenticated());%0A    assertEquals(%22desktop%22, auth.getName());%0A    assertNull(auth.getDetails());%0A    assertEquals(ui.getLastAccessToken(), auth.getCredentials());%0A    assertTrue(auth.getPrincipal() instanceof OAuth2User);%0A  %7D
 %0A%0A  

Add some more tests for the desktop starter to check the DesktopAuthentication is created correctly