001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.apache.hadoop.hbase.client.trace.hamcrest; 019 020import static org.hamcrest.Matchers.equalTo; 021 022import io.opentelemetry.api.common.Attributes; 023import io.opentelemetry.sdk.trace.data.EventData; 024import org.hamcrest.FeatureMatcher; 025import org.hamcrest.Matcher; 026 027/** 028 * Helper methods for matching against instances of {@link EventData}. 029 */ 030public final class EventMatchers { 031 032 private EventMatchers() { 033 } 034 035 public static Matcher<EventData> hasAttributes(Matcher<Attributes> matcher) { 036 return new FeatureMatcher<EventData, Attributes>(matcher, "EventData having attributes that ", 037 "attributes") { 038 @Override 039 protected Attributes featureValueOf(EventData actual) { 040 return actual.getAttributes(); 041 } 042 }; 043 } 044 045 public static Matcher<EventData> hasName(String name) { 046 return hasName(equalTo(name)); 047 } 048 049 public static Matcher<EventData> hasName(Matcher<String> matcher) { 050 return new FeatureMatcher<EventData, String>(matcher, "EventData with a name that ", "name") { 051 @Override 052 protected String featureValueOf(EventData actual) { 053 return actual.getName(); 054 } 055 }; 056 } 057}