From c37792fead43f2464e319b29b09fccb4b29be01d Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Fri, 14 Feb 2014 21:17:30 +0100 Subject: [PATCH] [New] added RuntimeMock.assertServiceResult() --- .../li/strolch/testbase/runtime/RuntimeMock.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java b/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java index 09a902388..f5518dc72 100644 --- a/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java +++ b/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java @@ -15,6 +15,9 @@ */ package li.strolch.testbase.runtime; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + import java.io.File; import java.text.MessageFormat; @@ -24,11 +27,14 @@ import li.strolch.agent.impl.StrolchRealm; import li.strolch.runtime.configuration.RuntimeConfiguration; import li.strolch.runtime.privilege.StrolchPrivilegeHandler; import li.strolch.service.api.ServiceHandler; +import li.strolch.service.api.ServiceResult; +import li.strolch.service.api.ServiceResultState; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import ch.eitchnet.utils.helper.FileHelper; +import ch.eitchnet.utils.helper.StringHelper; public final class RuntimeMock { @@ -139,4 +145,14 @@ public final class RuntimeMock { logger.info("Failed to destroy container: " + e.getMessage()); //$NON-NLS-1$ } } + + public void assertServiceResult(ServiceResultState expectedState, Class expectedResultType, ServiceResult result) { + assertEquals("Expected service result of type " + expectedResultType + " but was " + result.getClass(), + expectedResultType, result.getClass()); + + if (!expectedState.equals(result.getState())) { + fail("Expected service result state " + expectedState + " but was " + result.getState() + ": Reason: " + + StringHelper.formatException(result.getThrowable())); + } + } }