下面列出了怎么用org.junit.matchers.JUnitMatchers的API类实例代码及写法,或者点击链接到github查看源代码。
@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."));
}
@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" ) );
}
@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 ) ) );
}
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() {
}
});
}
@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"));
}
}
@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"));
}
}
@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"));
}
}
@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"));
}
}
@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")));
}
@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 ) ) );
}
@Factory
@SuppressWarnings("unused")
public Object instanceMethod(final JUnitMatchers type) throws javax.el.PropertyNotFoundException {
return new org.junit.runner.notification.RunNotifier();
}