-
Notifications
You must be signed in to change notification settings - Fork 332
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closes caelum/vraptor#581. Only instantiate objects with same type #355
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,10 +28,12 @@ | |
package br.com.caelum.vraptor.http.iogi; | ||
|
||
import static br.com.caelum.vraptor.VRaptorMatchers.hasMessage; | ||
import static java.util.Collections.singletonMap; | ||
import static org.hamcrest.Matchers.allOf; | ||
import static org.hamcrest.Matchers.hasItem; | ||
import static org.hamcrest.Matchers.hasSize; | ||
import static org.hamcrest.Matchers.is; | ||
import static org.hamcrest.Matchers.not; | ||
import static org.hamcrest.Matchers.notNullValue; | ||
import static org.hamcrest.Matchers.nullValue; | ||
import static org.hamcrest.Matchers.sameInstance; | ||
|
@@ -43,18 +45,22 @@ | |
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
import org.junit.Test; | ||
|
||
import br.com.caelum.iogi.parameters.Parameter; | ||
import br.com.caelum.iogi.parameters.Parameters; | ||
import br.com.caelum.iogi.reflection.Target; | ||
import br.com.caelum.vraptor.Result; | ||
import br.com.caelum.vraptor.controller.ControllerMethod; | ||
import br.com.caelum.vraptor.controller.DefaultControllerMethod; | ||
import br.com.caelum.vraptor.http.ParametersProvider; | ||
import br.com.caelum.vraptor.http.ParametersProviderTest; | ||
import br.com.caelum.vraptor.validator.Message; | ||
|
||
public class IogiParametersProviderTest extends ParametersProviderTest { | ||
|
||
|
@@ -166,11 +172,29 @@ public void isCapableOfDealingWithSetsOfObjects() throws Exception { | |
assertThat(abc.iterator().next().getX(), is(1l)); | ||
} | ||
|
||
@Test | ||
public void shouldInjectOnlyAttributesWithSameType() throws Exception { | ||
Result result = mock(Result.class); | ||
when(request.getAttribute("result")).thenReturn(result); | ||
when(request.getParameterMap()).thenReturn(singletonMap("result", new String[] { "buggy" })); | ||
|
||
ControllerMethod method = DefaultControllerMethod.instanceFor(OtherResource.class, | ||
OtherResource.class.getDeclaredMethod("logic", String.class)); | ||
|
||
List<Message> errors = new ArrayList<Message>(); | ||
Object[] out = provider.getParametersFor(method, errors); | ||
|
||
assertThat(out[0], is(not((Object) result))); | ||
assertThat(out[0], is((Object) "buggy")); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the casting is necessary? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, because There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, my mistake =) |
||
} | ||
|
||
//---------- | ||
|
||
class OtherResource { | ||
void logic(NeedsMyResource param) { | ||
} | ||
void logic(String result) { | ||
} | ||
} | ||
|
||
static class NeedsMyResource { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've changed the test because I think that we need to check if IOGI got the right parameter too. @lucascs right?