Skip to content

Commit

Permalink
ManyValued inputs setValue is now passed by value instead of reference
Browse files Browse the repository at this point in the history
  • Loading branch information
gastaldi committed Apr 16, 2013
1 parent 4d5a649 commit f6448be
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,17 +104,19 @@ private static void setManyInputValue(final ConverterFactory converterFactory,
final Iterable<Object> convertedValues;
if (value != null)
{
List<Object> convertedValuesList = new ArrayList<Object>();
if (value instanceof Iterable)
{
// TODO: Should convert each value ?
convertedValues = (Iterable<Object>) value;
for (Object itValue : (Iterable) value)
{
convertedValuesList.add(convertToUIInputValue(converterFactory, input, itValue));
}
}
else
{
List<Object> convertedValuesList = new ArrayList<Object>();
convertedValuesList.add(convertToUIInputValue(converterFactory, input, value));
convertedValues = convertedValuesList;
}
convertedValues = convertedValuesList;
}
else
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* Copyright 2012 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Eclipse Public License version 1.0, available at
* http://www.eclipse.org/legal/epl-v10.html
*/

package org.jboss.forge.ui.impl;

import java.util.Arrays;
import java.util.Iterator;

import javax.inject.Inject;

import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.forge.arquillian.Addon;
import org.jboss.forge.arquillian.Dependencies;
import org.jboss.forge.arquillian.archive.ForgeArchive;
import org.jboss.forge.container.addons.AddonId;
import org.jboss.forge.container.addons.AddonRegistry;
import org.jboss.forge.container.repositories.AddonDependencyEntry;
import org.jboss.forge.convert.ConverterFactory;
import org.jboss.forge.ui.input.InputComponent;
import org.jboss.forge.ui.input.UIInputMany;
import org.jboss.forge.ui.input.UISelectMany;
import org.jboss.forge.ui.util.InputComponents;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;

@RunWith(Arquillian.class)
public class ManyValuesInjectionTest
{
@Deployment
@Dependencies({ @Addon(name = "org.jboss.forge:ui", version = "2.0.0-SNAPSHOT"),
@Addon(name = "org.jboss.forge:convert", version = "2.0.0-SNAPSHOT") })
public static ForgeArchive getDeployment()
{
ForgeArchive archive = ShrinkWrap
.create(ForgeArchive.class)
.addBeansXML()
.addClasses(Career.class)
.addAsAddonDependencies(
AddonDependencyEntry.create(AddonId.from("org.jboss.forge:convert", "2.0.0-SNAPSHOT")),
AddonDependencyEntry.create(AddonId.from("org.jboss.forge:ui", "2.0.0-SNAPSHOT")));

return archive;
}

@Inject
UIInputMany<Career> inputMany;

@Inject
UISelectMany<Career> selectMany;

@Inject
AddonRegistry addonRegistry;

@Test
public void testInjectionNotNull()
{
Assert.assertNotNull(inputMany);
Assert.assertNotNull(selectMany);
}

@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void testIterableConversion()
{
Iterable<String> stringIterable = Arrays.asList("TECHNOLOGY", "MEDICINE");
InputComponents.setValueFor(addonRegistry.getExportedInstance(ConverterFactory.class).get(), (InputComponent) inputMany, stringIterable);
Iterable<Career> value = inputMany.getValue();
Assert.assertNotNull(value);
Iterator<Career> iterator = value.iterator();
Assert.assertTrue(iterator.hasNext());
Assert.assertEquals(Career.TECHNOLOGY, iterator.next());
Assert.assertTrue(iterator.hasNext());
Assert.assertEquals(Career.MEDICINE, iterator.next());
Assert.assertFalse(iterator.hasNext());
}
}

0 comments on commit f6448be

Please sign in to comment.