类org.junit.matchers.JUnitMatchers源码实例Demo

下面列出了怎么用org.junit.matchers.JUnitMatchers的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: datacollector   文件: TestDriftRuleEL.java
@Test
@SuppressWarnings("deprecation")
public void testDriftNamesIncompatibleTypes() throws Exception {
  ELVars vars = new ELVariables();

  Record record = new RecordImpl("creator", "id", null, null);
  record.set(Field.create(1));

  RecordEL.setRecordInContext(vars, record);

  vars.addContextVariable(DataRuleEvaluator.PIPELINE_CONTEXT, new HashMap<>());
  vars.addContextVariable(DataRuleEvaluator.RULE_ID_CONTEXT, "ID");

  ELEval elEval = new ELEvaluator("", ConcreteELDefinitionExtractor.get(), DriftRuleEL.class, AlertInfoEL.class);

  Assert.assertFalse(elEval.eval(vars, "${drift:names('/', true)}", Boolean.TYPE));
  Assert.assertThat(elEval.eval(vars, "${alert:info()}", String.class), JUnitMatchers.containsString("Field / have unsupported type of INTEGER."));
}
 
源代码2 项目: datacollector   文件: TestDriftRuleEL.java
@Test
@SuppressWarnings("deprecation")
public void testDriftOrderIncompatibleTypes() throws Exception {
  ELVars vars = new ELVariables();

  Record record = new RecordImpl("creator", "id", null, null);
  record.set(Field.create(1));

  RecordEL.setRecordInContext(vars, record);

  vars.addContextVariable(DataRuleEvaluator.PIPELINE_CONTEXT, new HashMap<>());
  vars.addContextVariable(DataRuleEvaluator.RULE_ID_CONTEXT, "ID");

  ELEval elEval = new ELEvaluator("", ConcreteELDefinitionExtractor.get(), DriftRuleEL.class, AlertInfoEL.class);

  Assert.assertFalse(elEval.eval(vars, "${drift:order('/', true)}", Boolean.TYPE));
  Assert.assertThat(elEval.eval(vars, "${alert:info()}", String.class), JUnitMatchers.containsString("Field / have unsupported type of INTEGER."));
}
 
@Test
public void shouldSelect2hostsFromNonLocalRacks() throws UnknownHostException
{
    Multimap<String, InetAddress> endpoints = ImmutableMultimap.<String, InetAddress> builder()
            .put(LOCAL, InetAddress.getByName("0"))
            .put(LOCAL, InetAddress.getByName("00"))
            .put("1", InetAddress.getByName("1"))
            .put("1", InetAddress.getByName("11"))
            .put("2", InetAddress.getByName("2"))
            .put("2", InetAddress.getByName("22"))
            .build();
    Collection<InetAddress> result = new TestEndpointFilter(LOCAL, endpoints).filter();
    assertThat(result.size(), is(2));
    assertThat(result, JUnitMatchers.hasItem(InetAddress.getByName("11")));
    assertThat(result, JUnitMatchers.hasItem(InetAddress.getByName("22")));
}
 
protected void doTest_OnePrivate_TwoShared() throws Exception {
  T meta = createMeta();
  DatabaseMeta privateMeta = createDatabase( "privateMeta" );
  meta.addDatabase( privateMeta );

  String xml = toXml( meta );

  DatabaseMeta meta1 = createDatabase( "meta1" );
  meta1.setShared( true );
  DatabaseMeta meta2 = createDatabase( "meta2" );
  meta2.setShared( true );

  SharedObjects fakeSharedObjects = createFakeSharedObjects( meta1, meta2 );

  T loaded = fromXml( xml, fakeSharedObjects );

  List<String> loadedDbs = Arrays.asList( loaded.getDatabaseNames() );
  assertEquals( 3, loadedDbs.size() );
  assertThat( loadedDbs, JUnitMatchers.hasItems( "meta1", "meta2", "privateMeta" ) );

  Set<String> privateDatabases = loaded.getPrivateDatabases();
  assertNotNull( privateDatabases );
  assertEquals( 1, privateDatabases.size() );
  assertTrue( privateDatabases.contains( "privateMeta" ) );
}
 
源代码5 项目: pentaho-kettle   文件: MappingUnitTest.java
@SuppressWarnings( "unchecked" )
@Test
public void pickupTargetStepsFor_OutputIsNotDefined() throws Exception {
  StepMeta singleMeta = new StepMeta( "single", null );
  StepMeta copiedMeta = new StepMeta( "copied", null );
  Mockito.when( mockHelper.transMeta.findNextSteps( mockHelper.stepMeta ) ).thenReturn( Arrays.asList( singleMeta, copiedMeta ) );

  StepInterface single = Mockito.mock( StepInterface.class );
  Mockito.when( mockHelper.trans.findStepInterfaces( "single" ) ).thenReturn( Collections.singletonList( single ) );

  StepInterface copy1 = Mockito.mock( StepInterface.class );
  StepInterface copy2 = Mockito.mock( StepInterface.class );
  Mockito.when( mockHelper.trans.findStepInterfaces( "copied" ) ).thenReturn( Arrays.asList( copy1, copy2 ) );

  MappingIODefinition definition = new MappingIODefinition( null, null );
  StepInterface[] targetSteps = mapping.pickupTargetStepsFor( definition );

  assertThat( Arrays.asList( targetSteps ), JUnitMatchers.hasItems( is( single ), is( copy1 ), is( copy2 ) ) );
}
 
源代码6 项目: java-specialagent   文件: FingerprintMain.java
public static void main(final String[] args) {
  final FpTestClass1 fp1 = new FpTestClass1();
  final FpTestClass2 fp2 = new FpTestClass2();
  fp2.instanceMethod(new JUnitMatchers());
  fp2.schedule(new Runnable() {
    @Override
    public void run() {
    }
  });
}
 
源代码7 项目: dubbox   文件: RouteRuleTest.java
@org.junit.Test
public void testParse_EmptyThen() {
    String expr = "service=com.alibaba.MemberService,AuthService&consumer.host=127.0.0.1&consumer.version != 1.0.0";
    try{
        RouteRule.parse(expr, "");
        Assert.fail();
    }catch(ParseException expected){
        assertThat(expected.getMessage(), JUnitMatchers.containsString("Illegal route rule without then express"));
    }
}
 
源代码8 项目: dubbox-hystrix   文件: RouteRuleTest.java
@org.junit.Test
public void testParse_EmptyThen() {
    String expr = "service=com.alibaba.MemberService,AuthService&consumer.host=127.0.0.1&consumer.version != 1.0.0";
    try{
        RouteRule.parse(expr, "");
        Assert.fail();
    }catch(ParseException expected){
        assertThat(expected.getMessage(), JUnitMatchers.containsString("Illegal route rule without then express"));
    }
}
 
源代码9 项目: dubbo3   文件: RouteRuleTest.java
@org.junit.Test
public void testParse_EmptyThen() {
    String expr = "service=com.alibaba.MemberService,AuthService&consumer.host=127.0.0.1&consumer.version != 1.0.0";
    try{
        RouteRule.parse(expr, "");
        Assert.fail();
    }catch(ParseException expected){
        assertThat(expected.getMessage(), JUnitMatchers.containsString("Illegal route rule without then express"));
    }
}
 
源代码10 项目: dubbox   文件: RouteRuleTest.java
@org.junit.Test
public void testParse_EmptyThen() {
    String expr = "service=com.alibaba.MemberService,AuthService&consumer.host=127.0.0.1&consumer.version != 1.0.0";
    try{
        RouteRule.parse(expr, "");
        Assert.fail();
    }catch(ParseException expected){
        assertThat(expected.getMessage(), JUnitMatchers.containsString("Illegal route rule without then express"));
    }
}
 
源代码11 项目: dubbox   文件: RouteRuleTest.java
@org.junit.Test
public void testParse_EmptyThen() {
    String expr = "service=com.alibaba.MemberService,AuthService&consumer.host=127.0.0.1&consumer.version != 1.0.0";
    try{
        RouteRule.parse(expr, "");
        Assert.fail();
    }catch(ParseException expected){
        assertThat(expected.getMessage(), JUnitMatchers.containsString("Illegal route rule without then express"));
    }
}
 
@Test
public void testSortableProperties() {
    ListContainer<Person> listContainer = new ListContainer<>(Service.getListOfPersons(100));
    listContainer.setContainerPropertyIds("id", "firstName", "lastName", "age", "groups[0].name", "generated");

    Object[] expectedSortableProperties = new Object[] {"id", "firstName", "lastName", "age", "groups[0].name"};
    Collection<Object> actualSortableProperties = (Collection<Object>) listContainer.getSortableContainerPropertyIds();
    Assert.assertThat(actualSortableProperties, JUnitMatchers.hasItems(expectedSortableProperties));
}
 
@Test
public void shouldSelectHostFromLocal() throws UnknownHostException
{
    Multimap<String, InetAddress> endpoints = ImmutableMultimap.<String, InetAddress> builder()
            .put(LOCAL, InetAddress.getByName("0"))
            .put(LOCAL, InetAddress.getByName("00"))
            .put("1", InetAddress.getByName("1"))
            .build();
    Collection<InetAddress> result = new TestEndpointFilter(LOCAL, endpoints).filter();
    assertThat(result.size(), is(2));
    assertThat(result, JUnitMatchers.hasItem(InetAddress.getByName("1")));
    assertThat(result, JUnitMatchers.hasItem(InetAddress.getByName("0")));
}
 
@Test
public void shouldReturnAsIsIfNoEnoughEndpoints() throws UnknownHostException
{
    Multimap<String, InetAddress> endpoints = ImmutableMultimap.<String, InetAddress> builder()
            .put(LOCAL, InetAddress.getByName("0"))
            .build();
    Collection<InetAddress> result = new TestEndpointFilter(LOCAL, endpoints).filter();
    assertThat(result.size(), is(1));
    assertThat(result, JUnitMatchers.hasItem(InetAddress.getByName("0")));
}
 
@Test
public void shouldSelectTwoFirstHostsFromSingleOtherRack() throws UnknownHostException
{
    Multimap<String, InetAddress> endpoints = ImmutableMultimap.<String, InetAddress> builder()
            .put(LOCAL, InetAddress.getByName("0"))
            .put(LOCAL, InetAddress.getByName("00"))
            .put("1", InetAddress.getByName("1"))
            .put("1", InetAddress.getByName("11"))
            .put("1", InetAddress.getByName("111"))
            .build();
    Collection<InetAddress> result = new TestEndpointFilter(LOCAL, endpoints).filter();
    assertThat(result.size(), is(2));
    assertThat(result, JUnitMatchers.hasItem(InetAddress.getByName("1")));
    assertThat(result, JUnitMatchers.hasItem(InetAddress.getByName("11")));
}
 
源代码16 项目: pentaho-kettle   文件: MappingUnitTest.java
@SuppressWarnings( "unchecked" )
@Test
public void pickupTargetStepsFor_OutputIsDefined() throws Exception {
  StepInterface copy1 = Mockito.mock( StepInterface.class );
  StepInterface copy2 = Mockito.mock( StepInterface.class );
  Mockito.when( mockHelper.trans.findStepInterfaces( "copied" ) ).thenReturn( Arrays.asList( copy1, copy2 ) );

  MappingIODefinition definition = new MappingIODefinition( null, "copied" );
  StepInterface[] targetSteps = mapping.pickupTargetStepsFor( definition );

  assertThat( Arrays.asList( targetSteps ), JUnitMatchers.hasItems( is( copy1 ), is( copy2 ) ) );
}
 
源代码17 项目: java-specialagent   文件: FpTestClass2.java
@Factory
@SuppressWarnings("unused")
 public Object instanceMethod(final JUnitMatchers type) throws javax.el.PropertyNotFoundException {
  return new org.junit.runner.notification.RunNotifier();
}
 
 类所在包
 同包方法