Skip to content

Commit

Permalink
Added NoopConverter
Browse files Browse the repository at this point in the history
  • Loading branch information
gastaldi committed Jan 25, 2013
1 parent d394211 commit edec2d3
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public <S, T> Converter<S, T> getConverter(Class<S> source, Class<T> target)
ConverterGenerator generator = generatorInstance.get();
if (generator.handles(source, target))
{
result = (Converter<S, T>) generator.generateConverter(source,target);
result = (Converter<S, T>) generator.generateConverter(source, target);
break;
}
}
Expand All @@ -45,6 +45,13 @@ public <S, T> Converter<S, T> getConverter(Class<S> source, Class<T> target)
result = (Converter<S, T>) new ToStringConverter<S>((Class<S>) source.getClass());
}
if (result == null)
{
if (target.isAssignableFrom(source))
{
result = (Converter<S, T>) new NoopConverter<S>(source);
}
}
if (result == null)
{
try
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright 2013 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.convert.impl;

import javax.enterprise.inject.Vetoed;

import org.jboss.forge.convert.BaseConverter;

@Vetoed
public class NoopConverter<S> extends BaseConverter<S, S>
{
public NoopConverter(Class<S> type)
{
super(type, type);
}

@Override
public S convert(S source)
{
return source;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ public static ForgeArchive getDeployment()
@Inject
private Converter<Integer, String> intToString;

@Inject
private Converter<Boolean, Boolean> noopConverter;

@Test
public void testNotNull() throws Exception
{
Expand All @@ -70,4 +73,13 @@ public void testSimpleConversion2() throws Exception
Assert.assertEquals(expected, intToString.convert(input));
}

@Test
public void testNoopConversion()
{
Boolean input = Boolean.TRUE;
Boolean expected = input;
Assert.assertSame(expected, noopConverter.convert(input));

}

}

0 comments on commit edec2d3

Please sign in to comment.