Java 类org.mockito.internal.matchers.Equals 实例源码

项目:NGB-master    文件:ToolsControllerTest.java   
@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
public void specifiedSortedFileShouldBeCreated() throws Exception {
    File tempDirectory = getTempDirectory();

    File toBeSorted = context.getResource("classpath:templates/" + UNSORTED_BED_NAME).getFile();
    File copiedToBeSorted = new File(tempDirectory, UNSORTED_BED_NAME);
    Files.copy(toBeSorted.toPath(), copiedToBeSorted.toPath());

    File sortedPath = new File(tempDirectory, SPECIFIED_BED_NAME);

    FeatureFileSortRequest request = new FeatureFileSortRequest();
    request.setOriginalFilePath(copiedToBeSorted.getAbsolutePath());
    request.setSortedFilePath(sortedPath.getAbsolutePath());

    assertSortRequest(request, new Equals(sortedPath.getAbsolutePath()));
}
项目:NGB    文件:ToolsControllerTest.java   
@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
public void specifiedSortedFileShouldBeCreated() throws Exception {
    File tempDirectory = getTempDirectory();

    File toBeSorted = context.getResource("classpath:templates/" + UNSORTED_BED_NAME).getFile();
    File copiedToBeSorted = new File(tempDirectory, UNSORTED_BED_NAME);
    Files.copy(toBeSorted.toPath(), copiedToBeSorted.toPath());

    File sortedPath = new File(tempDirectory, SPECIFIED_BED_NAME);

    FeatureFileSortRequest request = new FeatureFileSortRequest();
    request.setOriginalFilePath(copiedToBeSorted.getAbsolutePath());
    request.setSortedFilePath(sortedPath.getAbsolutePath());

    assertSortRequest(request, new Equals(sortedPath.getAbsolutePath()));
}
项目:astor    文件:ArgumentMatchingToolTest.java   
@Test
public void shouldNotFindSuspiciousMatchersWhenTypesAreTheSame() {
    //given
    Equals matcherWithBadDescription = new Equals(20) {
        public void describeTo(Description desc) {
            //let's pretend we have the same description as the toString() of the argument
            desc.appendText("10");
        }
    };
    Integer argument = 10;

    //when
    Integer[] suspicious = tool.getSuspiciouslyNotMatchingArgsIndexes((List) Arrays.asList(matcherWithBadDescription), new Object[] {argument});

    //then
    assertEquals(0, suspicious.length);
}
项目:astor    文件:ArgumentMatchingToolTest.java   
@Test
public void shouldNotFindSuspiciousMatchersWhenTypesAreTheSame() {
    //given
    Equals matcherWithBadDescription = new Equals(20) {
        public void describeTo(Description desc) {
            //let's pretend we have the same description as the toString() of the argument
            desc.appendText("10");
        }
    };
    Integer argument = 10;

    //when
    Integer[] suspicious = tool.getSuspiciouslyNotMatchingArgsIndexes((List) Arrays.asList(matcherWithBadDescription), new Object[] {argument});

    //then
    assertEquals(0, suspicious.length);
}
项目:astor    文件:Invocation.java   
protected List<Matcher> argumentsToMatchers() {
    List<Matcher> matchers = new ArrayList<Matcher>(arguments.length);
    for (Object arg : arguments) {
        if (arg != null && arg.getClass().isArray()) {
            matchers.add(new ArrayEquals(arg));
        } else {
            matchers.add(new Equals(arg));
        }
    }
    return matchers;
}
项目:astor    文件:InvocationMatcherTest.java   
@Test
public void shouldToStringWithMatchers() throws Exception {
    Matcher m = NotNull.NOT_NULL;
    InvocationMatcher notNull = new InvocationMatcher(new InvocationBuilder().toInvocation(), asList(m));
    Matcher mTwo = new Equals('x');
    InvocationMatcher equals = new InvocationMatcher(new InvocationBuilder().toInvocation(), asList(mTwo));

    assertContains("simpleMethod(notNull())", notNull.toString());
    assertContains("simpleMethod('x')", equals.toString());
}
项目:astor    文件:InvocationMatcherTest.java   
@Test
public void shouldCaptureArgumentsFromInvocation() throws Exception {
    //given
    Invocation invocation = new InvocationBuilder().args("1", 100).toInvocation();
    CapturingMatcher capturingMatcher = new CapturingMatcher();
    InvocationMatcher invocationMatcher = new InvocationMatcher(invocation, (List) asList(new Equals("1"), capturingMatcher));

    //when
    invocationMatcher.captureArgumentsFrom(invocation);

    //then
    assertEquals(1, capturingMatcher.getAllValues().size());
    assertEquals(100, capturingMatcher.getLastValue());
}
项目:astor    文件:InvocationTest.java   
@Test
public void shouldTransformArgumentsToMatchers() throws Exception {
    Invocation i = new InvocationBuilder().args("foo", new String[] {"bar"}).toInvocation();
    List matchers = i.argumentsToMatchers();

    assertEquals(2, matchers.size());
    assertEquals(Equals.class, matchers.get(0).getClass());
    assertEquals(ArrayEquals.class, matchers.get(1).getClass());
}
项目:astor    文件:ArgumentMatchingToolTest.java   
@Test
public void shouldNotFindAnySuspiciousMatchersWhenNumberOfArgumentsDoesntMatch() {
    //given
    List<Matcher> matchers = (List) Arrays.asList(new Equals(1));

    //when
    Integer[] suspicious = tool.getSuspiciouslyNotMatchingArgsIndexes(matchers, new Object[] {10, 20});

    //then
    assertEquals(0, suspicious.length);
}
项目:astor    文件:ArgumentMatchingToolTest.java   
@Test
public void shouldNotFindAnySuspiciousMatchersWhenArgumentsMatch() {
    //given
    List<Matcher> matchers = (List) Arrays.asList(new Equals(10), new Equals(20));

    //when
    Integer[] suspicious = tool.getSuspiciouslyNotMatchingArgsIndexes(matchers, new Object[] {10, 20});

    //then
    assertEquals(0, suspicious.length);
}
项目:astor    文件:ArgumentMatchingToolTest.java   
@Test
public void shouldFindSuspiciousMatchers() {
    //given
    Equals matcherInt20 = new Equals(20);
    Long longPretendingAnInt = new Long(20);

    //when
    List<Matcher> matchers = (List) Arrays.asList(new Equals(10), matcherInt20);
    Integer[] suspicious = tool.getSuspiciouslyNotMatchingArgsIndexes(matchers, new Object[] {10, longPretendingAnInt});

    //then
    assertEquals(1, suspicious.length);
    assertEquals(new Integer(1), suspicious[0]);
}
项目:astor    文件:ArgumentMatchingToolTest.java   
@Test
public void shouldWorkFineWhenGivenArgIsNull() {
    //when
    Integer[] suspicious = tool.getSuspiciouslyNotMatchingArgsIndexes((List) Arrays.asList(new Equals(20)), new Object[] {null});

    //then
    assertEquals(0, suspicious.length);
}
项目:astor    文件:ArgumentsProcessor.java   
public static List<Matcher> argumentsToMatchers(Object[] arguments) {
    List<Matcher> matchers = new ArrayList<Matcher>(arguments.length);
    for (Object arg : arguments) {
        if (arg != null && arg.getClass().isArray()) {
            matchers.add(new ArrayEquals(arg));
        } else {
            matchers.add(new Equals(arg));
        }
    }
    return matchers;
}
项目:astor    文件:InvocationImplTest.java   
@Test
public void shouldTransformArgumentsToMatchers() throws Exception {
    Invocation i = new InvocationBuilder().args("foo", new String[]{"bar"}).toInvocation();
    List matchers = ArgumentsProcessor.argumentsToMatchers(i.getArguments());

    assertEquals(2, matchers.size());
    assertEquals(Equals.class, matchers.get(0).getClass());
    assertEquals(ArrayEquals.class, matchers.get(1).getClass());
}
项目:astor    文件:ArgumentMatchingToolTest.java   
@Test
public void shouldNotFindAnySuspiciousMatchersWhenNumberOfArgumentsDoesntMatch() {
    //given
    List<Matcher> matchers = (List) Arrays.asList(new Equals(1));

    //when
    Integer[] suspicious = tool.getSuspiciouslyNotMatchingArgsIndexes(matchers, new Object[] {10, 20});

    //then
    assertEquals(0, suspicious.length);
}
项目:astor    文件:ArgumentMatchingToolTest.java   
@Test
public void shouldNotFindAnySuspiciousMatchersWhenArgumentsMatch() {
    //given
    List<Matcher> matchers = (List) Arrays.asList(new Equals(10), new Equals(20));

    //when
    Integer[] suspicious = tool.getSuspiciouslyNotMatchingArgsIndexes(matchers, new Object[] {10, 20});

    //then
    assertEquals(0, suspicious.length);
}
项目:astor    文件:ArgumentMatchingToolTest.java   
@Test
public void shouldFindSuspiciousMatchers() {
    //given
    Equals matcherInt20 = new Equals(20);
    Long longPretendingAnInt = new Long(20);

    //when
    List<Matcher> matchers = (List) Arrays.asList(new Equals(10), matcherInt20);
    Integer[] suspicious = tool.getSuspiciouslyNotMatchingArgsIndexes(matchers, new Object[] {10, longPretendingAnInt});

    //then
    assertEquals(1, suspicious.length);
    assertEquals(new Integer(1), suspicious[0]);
}
项目:astor    文件:ArgumentMatchingToolTest.java   
@Test
public void shouldWorkFineWhenGivenArgIsNull() {
    //when
    Integer[] suspicious = tool.getSuspiciouslyNotMatchingArgsIndexes((List) Arrays.asList(new Equals(20)), new Object[] {null});

    //then
    assertEquals(0, suspicious.length);
}
项目:vertx-memcache    文件:MemcacheClientTest.java   
DeliveryOptionsTimeoutFeatureMatcher(final Long expectedTimeout) {
    super(new Equals(expectedTimeout), "Timeout", "timeout");
}
项目:cougar    文件:InProcessExecutableTest.java   
@Test
    public void subCall()
    {
        Tracer tracer = mock(Tracer.class);
        InProcessExecutable victim = new InProcessExecutable(tracer);

        ExecutionContext ctx = mock(ExecutionContext.class);
        OperationKey expectedOp = new OperationKey(new ServiceVersion(1,0),"Wibble","wobble");
        OperationKey op = new OperationKey(expectedOp, "_IN_PROCESS");
        Object[] args = new Object[1];
        ExecutionObserver obs = mock(ExecutionObserver.class);
        ExecutionVenue venue = mock(ExecutionVenue.class);
        TimeConstraints constraints = mock(TimeConstraints.class);

        RequestUUID parentUuid = new RequestUUIDImpl();
        when(ctx.getRequestUUID()).thenReturn(parentUuid);
        when(ctx.isTransportSecure()).thenReturn(false);
        IdentityChain mockIdentityChain = new IdentityChainImpl();
        when(ctx.getIdentity()).thenReturn(mockIdentityChain);
        GeoLocationDetails mockLocation = mock(GeoLocationDetails.class);
        when(ctx.getLocation()).thenReturn(mockLocation);
        when(ctx.getReceivedTime()).thenReturn(new Date(0L));
        when(ctx.getRequestTime()).thenReturn(new Date(0L));
        when(ctx.getTransportSecurityStrengthFactor()).thenReturn(0);


        victim.execute(ctx, op, args, obs, venue, constraints);

        ArgumentCaptor<ExecutionContext> arg1 = ArgumentCaptor.forClass(ExecutionContext.class);
        ArgumentCaptor<OperationKey> arg2 = ArgumentCaptor.forClass(OperationKey.class);
        ArgumentCaptor<Object[]> arg3 = ArgumentCaptor.forClass(Object[].class);
        ArgumentCaptor<ExecutionObserver> arg4 = ArgumentCaptor.forClass(ExecutionObserver.class);
        ArgumentCaptor<TimeConstraints> arg5 = ArgumentCaptor.forClass(TimeConstraints.class);

        // moved from this as it was failing and v hard to work out which bit was failing
//        verify(venue, times(1)).execute(argThat(isSubContextOf(ctx)),eq(new OperationKey(op, null)),same(args),
//                argThat(isTracingEndObserver(obs, parentUuid, op, tracer)),same(constraints));

        verify(venue, times(1)).execute(arg1.capture(), arg2.capture(), arg3.capture(), arg4.capture(), arg5.capture());

        assertThat(arg1.getValue(), isSubContextOf(ctx));
        assertThat(arg2.getValue(), new Equals(expectedOp));
        assertThat(arg3.getValue(), new Same(args));
        assertThat(arg4.getValue(), isTracingEndObserver(obs, parentUuid, expectedOp, tracer));
        assertThat(arg5.getValue(), new Same(constraints));
    }