Search in sources :

Example 46 with Arrays.asList

use of java.util.Arrays.asList in project sonarqube by SonarSource.

the class InstalledActionTest method filter_by_plugin_type.

@Test
public void filter_by_plugin_type() throws IOException {
    when(serverPluginRepository.getPlugins()).thenReturn(Arrays.asList(newInstalledPlugin(new PluginInfo("foo-external-1").setName("foo-external-1"), PluginType.EXTERNAL), newInstalledPlugin(new PluginInfo("foo-bundled-1").setName("foo-bundled-1"), PluginType.BUNDLED), newInstalledPlugin(new PluginInfo("foo-external-2").setName("foo-external-2"), PluginType.EXTERNAL)));
    db.pluginDbTester().insertPlugin(p -> p.setKee("foo-external-1"), p -> p.setType(Type.EXTERNAL), p -> p.setUpdatedAt(100L));
    db.pluginDbTester().insertPlugin(p -> p.setKee("foo-bundled-1"), p -> p.setType(Type.BUNDLED), p -> p.setUpdatedAt(101L));
    db.pluginDbTester().insertPlugin(p -> p.setKee("foo-external-2"), p -> p.setType(Type.EXTERNAL), p -> p.setUpdatedAt(102L));
    // no type param
    String response = tester.newRequest().execute().getInput();
    JsonArray jsonArray = Json.parse(response).asObject().get("plugins").asArray();
    assertThat(jsonArray).hasSize(3);
    assertThat(jsonArray).extracting(JsonValue::asObject).extracting(members -> members.get("key").asString()).containsExactlyInAnyOrder("foo-external-1", "foo-bundled-1", "foo-external-2");
    // type param == BUNDLED
    response = tester.newRequest().setParam("type", "BUNDLED").execute().getInput();
    jsonArray = Json.parse(response).asObject().get("plugins").asArray();
    assertThat(jsonArray).hasSize(1);
    assertThat(jsonArray).extracting(JsonValue::asObject).extracting(members -> members.get("key").asString()).containsExactlyInAnyOrder("foo-bundled-1");
    // type param == EXTERNAL
    response = tester.newRequest().setParam("type", "EXTERNAL").execute().getInput();
    jsonArray = Json.parse(response).asObject().get("plugins").asArray();
    assertThat(jsonArray).hasSize(2);
    assertThat(jsonArray).extracting(JsonValue::asObject).extracting(members -> members.get("key").asString()).containsExactlyInAnyOrder("foo-external-1", "foo-external-2");
}
Also used : JsonArray(com.hazelcast.internal.json.JsonArray) JsonValue(com.hazelcast.internal.json.JsonValue) Arrays(java.util.Arrays) Type(org.sonar.db.plugin.PluginDto.Type) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RunWith(org.junit.runner.RunWith) JsonArray(com.hazelcast.internal.json.JsonArray) Random(java.util.Random) ServerPlugin(org.sonar.server.plugins.ServerPlugin) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) DataProviderRunner(com.tngtech.java.junit.dataprovider.DataProviderRunner) Collections.singletonList(java.util.Collections.singletonList) Mockito.verifyZeroInteractions(org.mockito.Mockito.verifyZeroInteractions) Json(com.hazelcast.internal.json.Json) PluginInfo(org.sonar.core.platform.PluginInfo) WebService(org.sonar.api.server.ws.WebService) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) Arrays.asList(java.util.Arrays.asList) Version(org.sonar.updatecenter.common.Version) Plugin(org.sonar.updatecenter.common.Plugin) ServerPluginRepository(org.sonar.server.plugins.ServerPluginRepository) RETURNS_DEEP_STUBS(org.mockito.Mockito.RETURNS_DEEP_STUBS) JsonObject(com.hazelcast.internal.json.JsonObject) DbTester(org.sonar.db.DbTester) FileAndMd5(org.sonar.server.plugins.PluginFilesAndMd5.FileAndMd5) System2(org.sonar.api.utils.System2) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider) JsonAssert.assertJson(org.sonar.test.JsonAssert.assertJson) IOException(java.io.IOException) Test(org.junit.Test) UpdateCenterMatrixFactory(org.sonar.server.plugins.UpdateCenterMatrixFactory) Mockito.when(org.mockito.Mockito.when) WsActionTester(org.sonar.server.ws.WsActionTester) File(java.io.File) Rule(org.junit.Rule) PluginType(org.sonar.server.plugins.PluginType) UpdateCenter(org.sonar.updatecenter.common.UpdateCenter) Optional(java.util.Optional) Action(org.sonar.api.server.ws.WebService.Action) TemporaryFolder(org.junit.rules.TemporaryFolder) Mockito.mock(org.mockito.Mockito.mock) JsonValue(com.hazelcast.internal.json.JsonValue) PluginInfo(org.sonar.core.platform.PluginInfo) Test(org.junit.Test)

Example 47 with Arrays.asList

use of java.util.Arrays.asList in project guava by google.

the class ListsTest method suite.

// suite
@GwtIncompatible
public static Test suite() {
    TestSuite suite = new TestSuite();
    suite.addTestSuite(ListsTest.class);
    suite.addTest(ListTestSuiteBuilder.using(new TestStringListGenerator() {

        @Override
        protected List<String> create(String[] elements) {
            String[] rest = new String[elements.length - 1];
            System.arraycopy(elements, 1, rest, 0, elements.length - 1);
            return Lists.asList(elements[0], rest);
        }
    }).named("Lists.asList, 2 parameter").withFeatures(CollectionSize.SEVERAL, CollectionSize.ONE, CollectionFeature.SERIALIZABLE, CollectionFeature.ALLOWS_NULL_VALUES).createTestSuite());
    suite.addTest(ListTestSuiteBuilder.using(new TestStringListGenerator() {

        @Override
        protected List<String> create(String[] elements) {
            String[] rest = new String[elements.length - 2];
            System.arraycopy(elements, 2, rest, 0, elements.length - 2);
            return Lists.asList(elements[0], elements[1], rest);
        }
    }).named("Lists.asList, 3 parameter").withFeatures(CollectionSize.SEVERAL, CollectionFeature.SERIALIZABLE, CollectionFeature.ALLOWS_NULL_VALUES).createTestSuite());
    final Function<String, String> removeFirst = new RemoveFirstFunction();
    suite.addTest(ListTestSuiteBuilder.using(new TestStringListGenerator() {

        @Override
        protected List<String> create(String[] elements) {
            List<String> fromList = Lists.newArrayList();
            for (String element : elements) {
                fromList.add("q" + checkNotNull(element));
            }
            return Lists.transform(fromList, removeFirst);
        }
    }).named("Lists.transform, random access, no nulls").withFeatures(CollectionSize.ANY, ListFeature.REMOVE_OPERATIONS, CollectionFeature.SERIALIZABLE, CollectionFeature.ALLOWS_NULL_QUERIES).createTestSuite());
    suite.addTest(ListTestSuiteBuilder.using(new TestStringListGenerator() {

        @Override
        protected List<String> create(String[] elements) {
            List<String> fromList = Lists.newLinkedList();
            for (String element : elements) {
                fromList.add("q" + checkNotNull(element));
            }
            return Lists.transform(fromList, removeFirst);
        }
    }).named("Lists.transform, sequential access, no nulls").withFeatures(CollectionSize.ANY, ListFeature.REMOVE_OPERATIONS, CollectionFeature.SERIALIZABLE, CollectionFeature.ALLOWS_NULL_QUERIES).createTestSuite());
    suite.addTest(ListTestSuiteBuilder.using(new TestStringListGenerator() {

        @Override
        protected List<String> create(String[] elements) {
            List<String> fromList = Lists.newArrayList(elements);
            return Lists.transform(fromList, Functions.<String>identity());
        }
    }).named("Lists.transform, random access, nulls").withFeatures(CollectionSize.ANY, ListFeature.REMOVE_OPERATIONS, CollectionFeature.SERIALIZABLE, CollectionFeature.ALLOWS_NULL_VALUES).createTestSuite());
    suite.addTest(ListTestSuiteBuilder.using(new TestStringListGenerator() {

        @Override
        protected List<String> create(String[] elements) {
            List<String> fromList = Lists.newLinkedList(asList(elements));
            return Lists.transform(fromList, Functions.<String>identity());
        }
    }).named("Lists.transform, sequential access, nulls").withFeatures(CollectionSize.ANY, ListFeature.REMOVE_OPERATIONS, CollectionFeature.SERIALIZABLE, CollectionFeature.ALLOWS_NULL_VALUES).createTestSuite());
    suite.addTest(ListTestSuiteBuilder.using(new TestStringListGenerator() {

        @Override
        protected List<String> create(String[] elements) {
            List<String> list = Lists.newArrayList();
            for (int i = elements.length - 1; i >= 0; i--) {
                list.add(elements[i]);
            }
            return Lists.reverse(list);
        }
    }).named("Lists.reverse[ArrayList]").withFeatures(CollectionSize.ANY, CollectionFeature.ALLOWS_NULL_VALUES, ListFeature.GENERAL_PURPOSE).createTestSuite());
    suite.addTest(ListTestSuiteBuilder.using(new TestStringListGenerator() {

        @Override
        protected List<String> create(String[] elements) {
            String[] reverseElements = new String[elements.length];
            for (int i = elements.length - 1, j = 0; i >= 0; i--, j++) {
                reverseElements[j] = elements[i];
            }
            return Lists.reverse(asList(reverseElements));
        }
    }).named("Lists.reverse[Arrays.asList]").withFeatures(CollectionSize.ANY, CollectionFeature.ALLOWS_NULL_VALUES, ListFeature.SUPPORTS_SET).createTestSuite());
    suite.addTest(ListTestSuiteBuilder.using(new TestStringListGenerator() {

        @Override
        protected List<String> create(String[] elements) {
            List<String> list = Lists.newLinkedList();
            for (int i = elements.length - 1; i >= 0; i--) {
                list.add(elements[i]);
            }
            return Lists.reverse(list);
        }
    }).named("Lists.reverse[LinkedList]").withFeatures(CollectionSize.ANY, CollectionFeature.ALLOWS_NULL_VALUES, ListFeature.GENERAL_PURPOSE).createTestSuite());
    suite.addTest(ListTestSuiteBuilder.using(new TestStringListGenerator() {

        @Override
        protected List<String> create(String[] elements) {
            ImmutableList.Builder<String> builder = ImmutableList.builder();
            for (int i = elements.length - 1; i >= 0; i--) {
                builder.add(elements[i]);
            }
            return Lists.reverse(builder.build());
        }
    }).named("Lists.reverse[ImmutableList]").withFeatures(CollectionSize.ANY, CollectionFeature.ALLOWS_NULL_QUERIES).createTestSuite());
    suite.addTest(ListTestSuiteBuilder.using(new CharactersOfStringGenerator()).named("Lists.charactersOf[String]").withFeatures(CollectionSize.ANY, CollectionFeature.SERIALIZABLE, CollectionFeature.ALLOWS_NULL_QUERIES).createTestSuite());
    suite.addTest(ListTestSuiteBuilder.using(new CharactersOfCharSequenceGenerator()).named("Lists.charactersOf[CharSequence]").withFeatures(CollectionSize.ANY, CollectionFeature.ALLOWS_NULL_QUERIES).createTestSuite());
    return suite;
}
Also used : CharactersOfCharSequenceGenerator(com.google.common.collect.testing.google.ListGenerators.CharactersOfCharSequenceGenerator) CharactersOfStringGenerator(com.google.common.collect.testing.google.ListGenerators.CharactersOfStringGenerator) TestSuite(junit.framework.TestSuite) ListTestSuiteBuilder(com.google.common.collect.testing.ListTestSuiteBuilder) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) LinkedList(java.util.LinkedList) List(java.util.List) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) TestStringListGenerator(com.google.common.collect.testing.TestStringListGenerator) GwtIncompatible(com.google.common.annotations.GwtIncompatible)

Example 48 with Arrays.asList

use of java.util.Arrays.asList in project gocd by gocd.

the class GoFileConfigDataSourceTest method shouldReloadConfigUsingFullSaveNormalFlowWithLastValidPartialsIfUpdatingWithLastKnownPartialsFails_onLoad.

@Test
public void shouldReloadConfigUsingFullSaveNormalFlowWithLastValidPartialsIfUpdatingWithLastKnownPartialsFails_onLoad() throws Exception {
    CruiseConfig cruiseConfig = new BasicCruiseConfig();
    PartialConfigMother.withPipeline("P1");
    List lastKnownPartials = Arrays.asList(PartialConfigMother.withPipeline("P1"));
    List lastValidPartials = Arrays.asList(PartialConfigMother.withPipeline("P2"), PartialConfigMother.withPipeline("P3"));
    GoConfigHolder goConfigHolder = new GoConfigHolder(cruiseConfig, cruiseConfig);
    ArgumentCaptor<FullConfigUpdateCommand> commandArgumentCaptor = ArgumentCaptor.forClass(FullConfigUpdateCommand.class);
    ArgumentCaptor<List> listArgumentCaptor = ArgumentCaptor.forClass(List.class);
    ArgumentCaptor<String> stringArgumentCaptor = ArgumentCaptor.forClass(String.class);
    when(systemEnvironment.getCruiseConfigFile()).thenReturn("");
    when(goConfigFileReader.fileLocation()).thenReturn(new File(""));
    when(goConfigFileReader.configXml()).thenReturn("config_xml");
    when(xmlLoader.deserializeConfig("config_xml")).thenReturn(cruiseConfig);
    when(cachedGoPartials.lastKnownPartials()).thenReturn(lastKnownPartials);
    when(cachedGoPartials.lastValidPartials()).thenReturn(lastValidPartials);
    when(fullConfigSaveNormalFlow.execute(commandArgumentCaptor.capture(), listArgumentCaptor.capture(), stringArgumentCaptor.capture())).thenThrow(new GoConfigInvalidException(null, Collections.emptyList())).thenReturn(goConfigHolder);
    dataSource.reloadEveryTime();
    GoConfigHolder configHolder = dataSource.load();
    assertThat(configHolder, is(goConfigHolder));
    assertThat(commandArgumentCaptor.getValue().configForEdit(), is(cruiseConfig));
    assertThat(listArgumentCaptor.getValue(), is(lastValidPartials));
    assertThat(stringArgumentCaptor.getValue(), is("Filesystem"));
}
Also used : FullConfigUpdateCommand(com.thoughtworks.go.config.update.FullConfigUpdateCommand) Arrays.asList(java.util.Arrays.asList) File(java.io.File) GoConfigInvalidException(com.thoughtworks.go.config.exceptions.GoConfigInvalidException) Test(org.junit.jupiter.api.Test)

Example 49 with Arrays.asList

use of java.util.Arrays.asList in project ART-TIME by Artezio.

the class HoursRepositoryTest method testGetManagersForApproveByEmployee.

@Test
public void testGetManagersForApproveByEmployee() {
    Date start = new Date();
    Date finish = getOffsetDate(3);
    Period period = new Period(start, finish);
    Employee manager1 = new Employee("manager1");
    Employee manager2 = new Employee("manager2");
    Employee manager3 = new Employee("manager3");
    Employee manager4 = new Employee("manager4");
    Employee manager5 = new Employee("manager5");
    Project project1 = new Project();
    project1.setManagers(Arrays.asList(manager1));
    Project project2 = new Project();
    project2.setManagers(Arrays.asList(manager2, manager3));
    Project project3 = new Project();
    project3.setManagers(Arrays.asList(manager2, manager4, manager5));
    Employee employee1 = new Employee("employee1");
    Employee employee2 = new Employee("employee2");
    HourType actualType = new HourType("actual type");
    actualType.setActualTime(true);
    Hours hours1 = createHours(project1, employee1, getOffsetDate(2), actualType, new BigDecimal(8));
    Hours hours2 = createHours(project2, employee1, getOffsetDate(2), actualType, new BigDecimal(8));
    Hours hours3 = createHours(project3, employee1, getOffsetDate(2), actualType, new BigDecimal(8));
    Hours hours4 = createHours(project2, employee2, getOffsetDate(2), actualType, new BigDecimal(8));
    entityManager.persist(manager1);
    entityManager.persist(manager2);
    entityManager.persist(manager3);
    entityManager.persist(manager4);
    entityManager.persist(manager5);
    entityManager.persist(actualType);
    entityManager.persist(employee1);
    entityManager.persist(employee2);
    entityManager.persist(project1);
    entityManager.persist(project2);
    entityManager.persist(project3);
    entityManager.persist(hours1);
    entityManager.persist(hours2);
    entityManager.persist(hours3);
    entityManager.persist(hours4);
    Map<Employee, List<Employee>> actual = hoursRepository.getManagersForApproveByEmployee(Arrays.asList(employee1, employee2), period);
    assertEquals(2, actual.size());
    ListAssert.assertEquals(Arrays.asList(manager1, manager2, manager3, manager4, manager5), actual.get(employee1));
    ListAssert.assertEquals(Arrays.asList(manager2, manager3), actual.get(employee2));
}
Also used : Project(com.artezio.arttime.datamodel.Project) Employee(com.artezio.arttime.datamodel.Employee) HourType(com.artezio.arttime.datamodel.HourType) Hours(com.artezio.arttime.datamodel.Hours) Period(com.artezio.arttime.datamodel.Period) Arrays.asList(java.util.Arrays.asList) List(java.util.List) Date(java.util.Date) CalendarUtils.getOffsetDate(com.artezio.arttime.test.utils.CalendarUtils.getOffsetDate) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 50 with Arrays.asList

use of java.util.Arrays.asList in project jnosql-diana-driver by eclipse.

the class OrientDBDocumentCollectionManagerTest method shouldSaveSubDocument2.

@Test
public void shouldSaveSubDocument2() {
    DocumentEntity entity = getEntity();
    entity.add(Document.of("phones", Arrays.asList(Document.of("mobile", "1231231"), Document.of("mobile2", "1231231"))));
    DocumentEntity entitySaved = entityManager.insert(entity);
    Document id = entitySaved.find("name").get();
    DocumentQuery query = select().from(COLLECTION_NAME).where(id.getName()).eq(id.get()).build();
    DocumentEntity entityFound = entityManager.select(query).get(0);
    Document subDocument = entityFound.find("phones").get();
    List<Document> documents = subDocument.get(new TypeReference<List<Document>>() {
    });
    assertThat(documents, containsInAnyOrder(Document.of("mobile", "1231231"), Document.of("mobile2", "1231231")));
}
Also used : DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) DocumentEntity(org.jnosql.diana.api.document.DocumentEntity) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) Document(org.jnosql.diana.api.document.Document) Test(org.junit.jupiter.api.Test)

Aggregations

Arrays.asList (java.util.Arrays.asList)65 List (java.util.List)61 ArrayList (java.util.ArrayList)48 Test (org.junit.Test)32 Arrays (java.util.Arrays)19 Collections.singletonList (java.util.Collections.singletonList)18 Map (java.util.Map)15 Test (org.junit.jupiter.api.Test)15 HashMap (java.util.HashMap)14 Collection (java.util.Collection)12 Collectors (java.util.stream.Collectors)12 Method (java.lang.reflect.Method)9 Optional (java.util.Optional)9 Collections.emptyList (java.util.Collections.emptyList)8 TopicPartition (org.apache.kafka.common.TopicPartition)8 Collections (java.util.Collections)7 Employee (com.artezio.arttime.datamodel.Employee)6 HourType (com.artezio.arttime.datamodel.HourType)6 Hours (com.artezio.arttime.datamodel.Hours)6 Project (com.artezio.arttime.datamodel.Project)6