Search in sources :

Example 76 with Description

use of org.hamcrest.Description in project platform_frameworks_base by android.

the class MockUtils method checkUserRestrictions.

public static Bundle checkUserRestrictions(String... keys) {
    final Bundle expected = DpmTestUtils.newRestrictions(Preconditions.checkNotNull(keys));
    final Matcher<Bundle> m = new BaseMatcher<Bundle>() {

        @Override
        public boolean matches(Object item) {
            if (item == null)
                return false;
            return UserRestrictionsUtils.areEqual((Bundle) item, expected);
        }

        @Override
        public void describeTo(Description description) {
            description.appendText("User restrictions=" + getRestrictionsAsString(expected));
        }
    };
    return MockitoHamcrest.argThat(m);
}
Also used : Description(org.hamcrest.Description) BaseMatcher(org.hamcrest.BaseMatcher) Bundle(android.os.Bundle)

Example 77 with Description

use of org.hamcrest.Description in project flink by apache.

the class CheckpointStateRestoreTest method testSetState.

/**
	 * Tests that on restore the task state is reset for each stateful task.
	 */
@Test
public void testSetState() {
    try {
        final ChainedStateHandle<StreamStateHandle> serializedState = CheckpointCoordinatorTest.generateChainedStateHandle(new SerializableObject());
        KeyGroupRange keyGroupRange = KeyGroupRange.of(0, 0);
        List<SerializableObject> testStates = Collections.singletonList(new SerializableObject());
        final KeyGroupsStateHandle serializedKeyGroupStates = CheckpointCoordinatorTest.generateKeyGroupState(keyGroupRange, testStates);
        final JobID jid = new JobID();
        final JobVertexID statefulId = new JobVertexID();
        final JobVertexID statelessId = new JobVertexID();
        Execution statefulExec1 = mockExecution();
        Execution statefulExec2 = mockExecution();
        Execution statefulExec3 = mockExecution();
        Execution statelessExec1 = mockExecution();
        Execution statelessExec2 = mockExecution();
        ExecutionVertex stateful1 = mockExecutionVertex(statefulExec1, statefulId, 0, 3);
        ExecutionVertex stateful2 = mockExecutionVertex(statefulExec2, statefulId, 1, 3);
        ExecutionVertex stateful3 = mockExecutionVertex(statefulExec3, statefulId, 2, 3);
        ExecutionVertex stateless1 = mockExecutionVertex(statelessExec1, statelessId, 0, 2);
        ExecutionVertex stateless2 = mockExecutionVertex(statelessExec2, statelessId, 1, 2);
        ExecutionJobVertex stateful = mockExecutionJobVertex(statefulId, new ExecutionVertex[] { stateful1, stateful2, stateful3 });
        ExecutionJobVertex stateless = mockExecutionJobVertex(statelessId, new ExecutionVertex[] { stateless1, stateless2 });
        Map<JobVertexID, ExecutionJobVertex> map = new HashMap<JobVertexID, ExecutionJobVertex>();
        map.put(statefulId, stateful);
        map.put(statelessId, stateless);
        CheckpointCoordinator coord = new CheckpointCoordinator(jid, 200000L, 200000L, 0, Integer.MAX_VALUE, ExternalizedCheckpointSettings.none(), new ExecutionVertex[] { stateful1, stateful2, stateful3, stateless1, stateless2 }, new ExecutionVertex[] { stateful1, stateful2, stateful3, stateless1, stateless2 }, new ExecutionVertex[0], new StandaloneCheckpointIDCounter(), new StandaloneCompletedCheckpointStore(1), null, Executors.directExecutor());
        // create ourselves a checkpoint with state
        final long timestamp = 34623786L;
        coord.triggerCheckpoint(timestamp, false);
        PendingCheckpoint pending = coord.getPendingCheckpoints().values().iterator().next();
        final long checkpointId = pending.getCheckpointId();
        SubtaskState checkpointStateHandles = new SubtaskState(serializedState, null, null, serializedKeyGroupStates, null);
        coord.receiveAcknowledgeMessage(new AcknowledgeCheckpoint(jid, statefulExec1.getAttemptId(), checkpointId, new CheckpointMetrics(), checkpointStateHandles));
        coord.receiveAcknowledgeMessage(new AcknowledgeCheckpoint(jid, statefulExec2.getAttemptId(), checkpointId, new CheckpointMetrics(), checkpointStateHandles));
        coord.receiveAcknowledgeMessage(new AcknowledgeCheckpoint(jid, statefulExec3.getAttemptId(), checkpointId, new CheckpointMetrics(), checkpointStateHandles));
        coord.receiveAcknowledgeMessage(new AcknowledgeCheckpoint(jid, statelessExec1.getAttemptId(), checkpointId));
        coord.receiveAcknowledgeMessage(new AcknowledgeCheckpoint(jid, statelessExec2.getAttemptId(), checkpointId));
        assertEquals(1, coord.getNumberOfRetainedSuccessfulCheckpoints());
        assertEquals(0, coord.getNumberOfPendingCheckpoints());
        // let the coordinator inject the state
        coord.restoreLatestCheckpointedState(map, true, false);
        // verify that each stateful vertex got the state
        final TaskStateHandles taskStateHandles = new TaskStateHandles(serializedState, Collections.<Collection<OperatorStateHandle>>singletonList(null), Collections.<Collection<OperatorStateHandle>>singletonList(null), Collections.singletonList(serializedKeyGroupStates), null);
        BaseMatcher<TaskStateHandles> matcher = new BaseMatcher<TaskStateHandles>() {

            @Override
            public boolean matches(Object o) {
                if (o instanceof TaskStateHandles) {
                    return o.equals(taskStateHandles);
                }
                return false;
            }

            @Override
            public void describeTo(Description description) {
                description.appendValue(taskStateHandles);
            }
        };
        verify(statefulExec1, times(1)).setInitialState(Mockito.argThat(matcher));
        verify(statefulExec2, times(1)).setInitialState(Mockito.argThat(matcher));
        verify(statefulExec3, times(1)).setInitialState(Mockito.argThat(matcher));
        verify(statelessExec1, times(0)).setInitialState(Mockito.<TaskStateHandles>any());
        verify(statelessExec2, times(0)).setInitialState(Mockito.<TaskStateHandles>any());
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : Description(org.hamcrest.Description) HashMap(java.util.HashMap) JobVertexID(org.apache.flink.runtime.jobgraph.JobVertexID) KeyGroupRange(org.apache.flink.runtime.state.KeyGroupRange) KeyGroupsStateHandle(org.apache.flink.runtime.state.KeyGroupsStateHandle) ExecutionVertex(org.apache.flink.runtime.executiongraph.ExecutionVertex) SerializableObject(org.apache.flink.runtime.util.SerializableObject) StreamStateHandle(org.apache.flink.runtime.state.StreamStateHandle) Execution(org.apache.flink.runtime.executiongraph.Execution) ExecutionJobVertex(org.apache.flink.runtime.executiongraph.ExecutionJobVertex) TaskStateHandles(org.apache.flink.runtime.state.TaskStateHandles) AcknowledgeCheckpoint(org.apache.flink.runtime.messages.checkpoint.AcknowledgeCheckpoint) BaseMatcher(org.hamcrest.BaseMatcher) SerializableObject(org.apache.flink.runtime.util.SerializableObject) OperatorStateHandle(org.apache.flink.runtime.state.OperatorStateHandle) JobID(org.apache.flink.api.common.JobID) Test(org.junit.Test)

Example 78 with Description

use of org.hamcrest.Description in project freud by LMAX-Exchange.

the class ClassByteCodeMethodMatchers method hasMethodInvocation.

public static FreudExtendedMatcher<ClassByteCodeMethod> hasMethodInvocation(final Class expectedOwner, final String expectedMethodName, final Class... expectedParamsDeclared) {
    return new FreudExtendedMatcher<ClassByteCodeMethod>() {

        private String expectedOwnerName;

        private String[] expectedParamNames;

        {
            expectedOwnerName = typeEncoding(expectedOwner);
            expectedParamNames = (expectedParamsDeclared.length == 0) ? EMPTY_ARGS : new String[expectedParamsDeclared.length];
            for (int i = 0, size = expectedParamsDeclared.length; i < size; i++) {
                expectedParamNames[i] = typeEncoding(expectedParamsDeclared[i]);
            }
        }

        @Override
        protected boolean matchesSafely(final ClassByteCodeMethod item) {
            final boolean[] found = new boolean[] { false };
            found[0] = false;
            item.findInstruction(new AbstractInstructionVisitor() {

                @Override
                public void methodInvocation(final Instruction instruction, final String owner, final String methodName, final String... args) {
                    if (!found[0] && expectedOwnerName.equals(owner) && expectedMethodName.equals(methodName) && Arrays.equals(expectedParamNames, args)) {
                        found[0] = true;
                    }
                }
            });
            return found[0];
        }

        @Override
        public void describeTo(final Description description) {
            description.appendText("hasMethodInvocation(" + expectedOwner.getName() + ", " + expectedMethodName + ", " + Arrays.toString(expectedParamNames) + ")");
        }
    };
}
Also used : Description(org.hamcrest.Description) ClassByteCodeMethod(org.freud.analysed.classbytecode.method.ClassByteCodeMethod) Instruction(org.freud.analysed.classbytecode.method.instruction.Instruction) FreudExtendedMatcher(org.freud.java.matcher.FreudExtendedMatcher) AbstractInstructionVisitor(org.freud.analysed.classbytecode.method.instruction.AbstractInstructionVisitor)

Example 79 with Description

use of org.hamcrest.Description in project freud by LMAX-Exchange.

the class CodeBlockMatchers method hasMethodCall.

public static FreudExtendedMatcher<CodeBlock> hasMethodCall(final String methodCall) {
    return new FreudExtendedMatcher<CodeBlock>() {

        private final String methodName;

        private final String[] instanceReferences;

        {
            String[] values = methodCall.split("\\.");
            instanceReferences = new String[values.length - 1];
            System.arraycopy(values, 0, instanceReferences, 0, instanceReferences.length);
            methodName = values[values.length - 1];
        }

        @Override
        protected boolean matchesSafely(final CodeBlock toBeAnalysed) {
            List<MethodCall> methodCallList = toBeAnalysed.getMethodCallListByMethodName(methodName);
            if (methodCallList != null) {
                for (MethodCall methodCall : methodCallList) {
                    if (Arrays.equals(instanceReferences, methodCall.getInstanceReferences())) {
                        return true;
                    }
                }
            }
            return false;
        }

        @Override
        public void describeTo(final Description description) {
            description.appendText("HasMethodCall(" + methodCall + ")");
        }
    };
}
Also used : Description(org.hamcrest.Description) CodeBlock(org.freud.analysed.javasource.CodeBlock) FreudExtendedMatcher(org.freud.java.matcher.FreudExtendedMatcher) MethodCall(org.freud.analysed.javasource.MethodCall)

Example 80 with Description

use of org.hamcrest.Description in project sonarqube by SonarSource.

the class ReportSubmitterTest method submit_a_report_on_existing_project.

@Test
public void submit_a_report_on_existing_project() {
    ComponentDto project = db.components().insertProject(db.getDefaultOrganization());
    userSession.logIn().addProjectUuidPermissions(SCAN_EXECUTION, project.uuid());
    mockSuccessfulPrepareSubmitCall();
    underTest.submit(defaultOrganizationKey, project.getKey(), null, project.name(), IOUtils.toInputStream("{binary}"));
    verifyReportIsPersisted(TASK_UUID);
    verifyZeroInteractions(permissionTemplateService);
    verifyZeroInteractions(favoriteUpdater);
    verify(queue).submit(argThat(new TypeSafeMatcher<CeTaskSubmit>() {

        @Override
        protected boolean matchesSafely(CeTaskSubmit submit) {
            return submit.getType().equals(CeTaskTypes.REPORT) && submit.getComponentUuid().equals(project.uuid()) && submit.getUuid().equals(TASK_UUID);
        }

        @Override
        public void describeTo(Description description) {
        }
    }));
}
Also used : TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.hamcrest.Description) ComponentDto(org.sonar.db.component.ComponentDto) CeTaskSubmit(org.sonar.ce.queue.CeTaskSubmit) Test(org.junit.Test)

Aggregations

Description (org.hamcrest.Description)117 Test (org.junit.Test)37 TypeSafeMatcher (org.hamcrest.TypeSafeMatcher)35 StringDescription (org.hamcrest.StringDescription)26 BaseMatcher (org.hamcrest.BaseMatcher)25 View (android.view.View)22 ViewParent (android.view.ViewParent)11 TextView (android.widget.TextView)11 ViewGroup (android.view.ViewGroup)8 Expectations (org.jmock.Expectations)8 URL (java.net.URL)7 Matcher (org.hamcrest.Matcher)7 Invocation (org.jmock.api.Invocation)7 BoundedMatcher (android.support.test.espresso.matcher.BoundedMatcher)6 ImageView (android.widget.ImageView)6 File (java.io.File)6 IOException (java.io.IOException)6 URI (java.net.URI)6 List (java.util.List)6 JsonNode (org.codehaus.jackson.JsonNode)6