HttpClient.HttpRequest requestContainingFunctionId(String functionId) { ArgumentMatcher<HttpClient.HttpRequest> argumentMatcher = httpRequest -> { if(httpRequest.method != "POST") { System.err.println("Expecting a POST request, got " + httpRequest.method); return false; } try { APIModel.CreateGraphRequest createGraphRequest = objectMapper.readValue(new String(httpRequest.bodyBytes), APIModel.CreateGraphRequest.class); if ((createGraphRequest.functionId != null) && (createGraphRequest.functionId.equals(functionId))) { return true; } System.err.println("Request body doesn't contain an CreateGraphRequest with matching functionId field"); return false; } catch (IOException e) { System.err.println("Request body doesn't contain an CreateGraphRequest"); return false; } }; ThreadSafeMockingProgress.mockingProgress().getArgumentMatcherStorage().reportMatcher(argumentMatcher); return null; }
HttpClient.HttpRequest requestContainingAddStageRequest(String blobId, List<String> dependencies) { ArgumentMatcher<HttpClient.HttpRequest> argumentMatcher = httpRequest -> { if(httpRequest.method != "POST") { System.err.println("Expecting a POST request, got " + httpRequest.method); return false; } try { APIModel.AddStageRequest addStageRequest = objectMapper.readValue(new String(httpRequest.bodyBytes), APIModel.AddStageRequest.class); if ( (addStageRequest.closure != null) && (addStageRequest.closure.blobId.equals(blobId)) && (addStageRequest.deps.equals(dependencies))) { return true; } System.err.println("Request body doesn't contain an AddStageRequest with closure with matching blobId field"); return false; } catch (IOException e) { System.err.println("Request body doesn't contain an AddStageRequest"); return false; } }; ThreadSafeMockingProgress.mockingProgress().getArgumentMatcherStorage().reportMatcher(argumentMatcher); return null; }
HttpClient.HttpRequest requestContainingAddInvokeFunctionStageRequest(String functionId, APIModel.HTTPMethod httpMethod) { ArgumentMatcher<HttpClient.HttpRequest> argumentMatcher = httpRequest -> { if(httpRequest.method != "POST") { System.err.println("Expecting a POST request, got " + httpRequest.method); return false; } try { APIModel.AddInvokeFunctionStageRequest addInvokeFunctionStageRequest = objectMapper.readValue(new String(httpRequest.bodyBytes), APIModel.AddInvokeFunctionStageRequest.class); if ((addInvokeFunctionStageRequest.functionId != null) && (addInvokeFunctionStageRequest.functionId.equals(functionId)) && (addInvokeFunctionStageRequest.arg.method.equals(httpMethod))) { return true; } else { System.err.println("Request body doesn't contain a matching AddInvokeFunctionStageRequest"); } return false; } catch (IOException e) { System.err.println("Request body doesn't contain an AddInvokeFunctionStageRequest"); return false; } }; ThreadSafeMockingProgress.mockingProgress().getArgumentMatcherStorage().reportMatcher(argumentMatcher); return null; }
/** * @see org.junit.rules.MethodRule#apply(org.junit.runners.model.Statement, org.junit.runners.model.FrameworkMethod, java.lang.Object) */ @Override public Statement apply(final Statement base, final FrameworkMethod method, final Object target) { return new Statement() { @Override public void evaluate() throws Throwable { final List<Module> moduleWithTarget = new ArrayList<>(Arrays.asList(modules)); if (target instanceof Module) { moduleWithTarget.add((Module) target); } Guice.createInjector(moduleWithTarget).injectMembers(target); try { base.evaluate(); } finally { new ThreadSafeMockingProgress().reset(); } } }; }
HttpClient.HttpRequest requestForAwaitStageResult() { ArgumentMatcher<HttpClient.HttpRequest> argumentMatcher = httpRequest -> { if(httpRequest.method != "GET") { System.err.println("Expecting a GET request, got " + httpRequest.method); return false; } return true; }; ThreadSafeMockingProgress.mockingProgress().getArgumentMatcherStorage().reportMatcher(argumentMatcher); return null; }
private VerificationMode getVerificationMode() { try { MockingProgress progress = (MockingProgress) Whitebox.invokeMethod(ThreadSafeMockingProgress.class, "threadSafely"); return getVerificationModeFromMockProgress(progress); } catch (Exception e) { throw new RuntimeException(e); } }
@SuppressWarnings("unchecked") private VerificationMode getVerificationModeFromMockProgress(MockingProgress mockingProgress) { if (mockingProgress == null) { return null; } if (mockingProgress instanceof ThreadSafeMockingProgress) { ThreadLocal<MockingProgress> threadLocal = Whitebox.getInternalState(mockingProgress, ThreadLocal.class); return getVerificationModeFromMockProgress(threadLocal.get()); } else { Localized<VerificationMode> verificationMode = Whitebox.getInternalState(mockingProgress, Localized.class); return verificationMode == null ? null : verificationMode.getObject(); } }
@Test public void shouldRemoveStubbableFromProgressAfterStubbing() { List mock = Mockito.mock(List.class); Mockito.when(mock.add("test")).thenReturn(true); //TODO Consider to move to separate test assertNull(new ThreadSafeMockingProgress().pullOngoingStubbing()); }
public MocksCollector() { createdMocks = new LinkedList<Object>(); final MockingProgress progress = new ThreadSafeMockingProgress(); progress.setListener(new CollectCreatedMocks(createdMocks)); }
void clearMockProgress() { clearThreadLocalIn(ThreadSafeMockingProgress.class); }
public MocksCollector() { createdMocks = new LinkedList<>(); final MockingProgress progress = new ThreadSafeMockingProgress(); progress.setListener(new CollectCreatedMocks(createdMocks)); }
public MockHandler(MockSettingsImpl mockSettings) { this.mockSettings = mockSettings; this.mockingProgress = new ThreadSafeMockingProgress(); this.matchersBinder = new MatchersBinder(); this.invocationContainerImpl = new InvocationContainerImpl(mockingProgress); }
public WarningsCollector() { createdMocks = new LinkedList(); MockingProgress progress = new ThreadSafeMockingProgress(); progress.setListener(new CollectCreatedMocks(createdMocks)); }
public MockHandlerImpl(MockCreationSettings mockSettings) { this.mockSettings = mockSettings; this.mockingProgress = new ThreadSafeMockingProgress(); this.matchersBinder = new MatchersBinder(); this.invocationContainerImpl = new InvocationContainerImpl(mockingProgress, mockSettings); }