From 88a2a8c3954ae751f8b7063db675d9d53583010f Mon Sep 17 00:00:00 2001 From: pwener Date: Mon, 8 May 2017 17:34:19 -0300 Subject: [PATCH] Mock objects working with Result --- .../projecturutau/vraptor/test/MockFlash.java | 13 ++++++++++++- .../projecturutau/vraptor/test/MockRedirector.java | 11 ++++++++++- .../projecturutau/vraptor/test/MockScreened.java | 11 +++++++++-- 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/main/java/io/github/projecturutau/vraptor/test/MockFlash.java b/src/main/java/io/github/projecturutau/vraptor/test/MockFlash.java index 47ea85c..663dc04 100644 --- a/src/main/java/io/github/projecturutau/vraptor/test/MockFlash.java +++ b/src/main/java/io/github/projecturutau/vraptor/test/MockFlash.java @@ -2,15 +2,26 @@ import javax.enterprise.inject.Vetoed; +import br.com.caelum.vraptor.util.test.MockResult; import io.github.projecturutau.vraptor.handler.FlashMessage; import io.github.projecturutau.vraptor.handler.Screened; @Vetoed public class MockFlash implements FlashMessage { + private final MockResult mockResult; + + public MockFlash() { + this(null); + } + + public MockFlash(MockResult mockResult) { + this.mockResult = mockResult; + } + @Override public Screened use(String category) { - return new MockScreened(); + return new MockScreened(mockResult, category); } @Override diff --git a/src/main/java/io/github/projecturutau/vraptor/test/MockRedirector.java b/src/main/java/io/github/projecturutau/vraptor/test/MockRedirector.java index 9397ac9..f284246 100644 --- a/src/main/java/io/github/projecturutau/vraptor/test/MockRedirector.java +++ b/src/main/java/io/github/projecturutau/vraptor/test/MockRedirector.java @@ -7,8 +7,17 @@ @Vetoed public class MockRedirector implements Redirector { - private MockResult mockResult = new MockResult(); + private final MockResult mockResult; + public MockRedirector(MockResult mockResult, String key, String message) { + this.mockResult = mockResult; + mockResult.include(key, message); + } + + /* + * Whatever with this effect + */ + @Override public Controller redirectTo(Class controller) { return mockResult.redirectTo(controller); diff --git a/src/main/java/io/github/projecturutau/vraptor/test/MockScreened.java b/src/main/java/io/github/projecturutau/vraptor/test/MockScreened.java index e2ea4a3..9a5c127 100644 --- a/src/main/java/io/github/projecturutau/vraptor/test/MockScreened.java +++ b/src/main/java/io/github/projecturutau/vraptor/test/MockScreened.java @@ -2,15 +2,22 @@ import javax.enterprise.inject.Vetoed; +import br.com.caelum.vraptor.util.test.MockResult; import io.github.projecturutau.vraptor.handler.Redirector; import io.github.projecturutau.vraptor.handler.Screened; @Vetoed public class MockScreened implements Screened { + private final MockResult mockResult; + private final String key; + + public MockScreened(MockResult mockResult, String key) { + this.mockResult = mockResult; + this.key = key; + } @Override public Redirector toShow(String message) { - return new MockRedirector(); + return new MockRedirector(mockResult, key, message); } - }