Source:Why doesn't Java offer operator overloading?
QueryUtils.findAllActivatedClients();
Best junit code snippet using org.hamcrest.core.IsEqual
Source:HamcrestCollectionHasItemAssertions.java
...30 @Test31 void test_has_item_equal_to() {32 assertThat(sevenDwarfs, org.hamcrest.Matchers.hasItem(org.hamcrest.Matchers.equalTo("Sleepy")));33 assertThat(sevenDwarfs, org.hamcrest.Matchers.hasItem(org.hamcrest.CoreMatchers.equalTo("Sleepy")));34 assertThat(sevenDwarfs, org.hamcrest.Matchers.hasItem(org.hamcrest.core.IsEqual.equalTo("Sleepy")));35 assertThat(sevenDwarfs, org.hamcrest.CoreMatchers.hasItem(org.hamcrest.Matchers.equalTo("Sleepy")));36 assertThat(sevenDwarfs, org.hamcrest.CoreMatchers.hasItem(org.hamcrest.CoreMatchers.equalTo("Sleepy")));37 assertThat(sevenDwarfs, org.hamcrest.CoreMatchers.hasItem(org.hamcrest.core.IsEqual.equalTo("Sleepy")));38 assertThat(sevenDwarfs, org.hamcrest.core.IsIterableContaining.hasItem(org.hamcrest.Matchers.equalTo("Sleepy")));39 assertThat(sevenDwarfs, org.hamcrest.core.IsIterableContaining.hasItem(org.hamcrest.CoreMatchers.equalTo("Sleepy")));40 assertThat(sevenDwarfs, org.hamcrest.core.IsIterableContaining.hasItem(org.hamcrest.core.IsEqual.equalTo("Sleepy")));41 }42 @Test43 void test_has_item_equal_to_with_reason() {44 assertThat("reason", sevenDwarfs, org.hamcrest.Matchers.hasItem(org.hamcrest.Matchers.equalTo("Sleepy")));45 assertThat("reason", sevenDwarfs, org.hamcrest.Matchers.hasItem(org.hamcrest.CoreMatchers.equalTo("Sleepy")));46 assertThat("reason", sevenDwarfs, org.hamcrest.Matchers.hasItem(org.hamcrest.core.IsEqual.equalTo("Sleepy")));47 assertThat("reason", sevenDwarfs, org.hamcrest.CoreMatchers.hasItem(org.hamcrest.Matchers.equalTo("Sleepy")));48 assertThat("reason", sevenDwarfs, org.hamcrest.CoreMatchers.hasItem(org.hamcrest.CoreMatchers.equalTo("Sleepy")));49 assertThat("reason", sevenDwarfs, org.hamcrest.CoreMatchers.hasItem(org.hamcrest.core.IsEqual.equalTo("Sleepy")));50 assertThat("reason", sevenDwarfs, org.hamcrest.core.IsIterableContaining.hasItem(org.hamcrest.Matchers.equalTo("Sleepy")));51 assertThat("reason", sevenDwarfs, org.hamcrest.core.IsIterableContaining.hasItem(org.hamcrest.CoreMatchers.equalTo("Sleepy")));52 assertThat("reason", sevenDwarfs, org.hamcrest.core.IsIterableContaining.hasItem(org.hamcrest.core.IsEqual.equalTo("Sleepy")));53 }54 @Test55 void test_has_item_is() {56 assertThat(sevenDwarfs, org.hamcrest.Matchers.hasItem(org.hamcrest.Matchers.is("Sleepy")));57 assertThat(sevenDwarfs, org.hamcrest.Matchers.hasItem(org.hamcrest.CoreMatchers.is("Sleepy")));58 assertThat(sevenDwarfs, org.hamcrest.Matchers.hasItem(org.hamcrest.core.Is.is("Sleepy")));59 // ----60 assertThat(sevenDwarfs, org.hamcrest.CoreMatchers.hasItem(org.hamcrest.Matchers.is("Sleepy")));61 assertThat(sevenDwarfs, org.hamcrest.CoreMatchers.hasItem(org.hamcrest.CoreMatchers.is("Sleepy")));62 assertThat(sevenDwarfs, org.hamcrest.CoreMatchers.hasItem(org.hamcrest.core.Is.is("Sleepy")));63 // ----64 assertThat(sevenDwarfs, org.hamcrest.core.IsIterableContaining.hasItem(org.hamcrest.Matchers.is("Sleepy")));65 assertThat(sevenDwarfs, org.hamcrest.core.IsIterableContaining.hasItem(org.hamcrest.CoreMatchers.is("Sleepy")));66 assertThat(sevenDwarfs, org.hamcrest.core.IsIterableContaining.hasItem(org.hamcrest.core.Is.is("Sleepy")));67 }68 @Test69 void test_has_item_is_with_reason() {70 assertThat("reason", sevenDwarfs, org.hamcrest.Matchers.hasItem(org.hamcrest.Matchers.is("Sleepy")));71 assertThat("reason", sevenDwarfs, org.hamcrest.Matchers.hasItem(org.hamcrest.CoreMatchers.is("Sleepy")));72 assertThat("reason", sevenDwarfs, org.hamcrest.Matchers.hasItem(org.hamcrest.core.Is.is("Sleepy")));73 assertThat("reason", sevenDwarfs, org.hamcrest.CoreMatchers.hasItem(org.hamcrest.Matchers.is("Sleepy")));74 assertThat("reason", sevenDwarfs, org.hamcrest.CoreMatchers.hasItem(org.hamcrest.CoreMatchers.is("Sleepy")));75 assertThat("reason", sevenDwarfs, org.hamcrest.CoreMatchers.hasItem(org.hamcrest.core.Is.is("Sleepy")));76 assertThat("reason", sevenDwarfs, org.hamcrest.core.IsIterableContaining.hasItem(org.hamcrest.Matchers.is("Sleepy")));77 assertThat("reason", sevenDwarfs, org.hamcrest.core.IsIterableContaining.hasItem(org.hamcrest.CoreMatchers.is("Sleepy")));78 assertThat("reason", sevenDwarfs, org.hamcrest.core.IsIterableContaining.hasItem(org.hamcrest.core.Is.is("Sleepy")));79 }80 @Disabled("Too complex to worry about")81 @Test82 void test_has_item_is_equal_to() {83 assertThat(sevenDwarfs, org.hamcrest.Matchers.hasItem(org.hamcrest.Matchers.is(org.hamcrest.Matchers.equalTo("Sleepy"))));84 assertThat(sevenDwarfs, org.hamcrest.Matchers.hasItem(org.hamcrest.CoreMatchers.is(org.hamcrest.Matchers.equalTo("Sleepy"))));85 assertThat(sevenDwarfs, org.hamcrest.Matchers.hasItem(org.hamcrest.core.Is.is(org.hamcrest.Matchers.equalTo("Sleepy"))));86 assertThat(sevenDwarfs, org.hamcrest.Matchers.hasItem(org.hamcrest.Matchers.is(org.hamcrest.CoreMatchers.equalTo("Sleepy"))));87 assertThat(sevenDwarfs, org.hamcrest.Matchers.hasItem(org.hamcrest.CoreMatchers.is(org.hamcrest.CoreMatchers.equalTo("Sleepy"))));88 assertThat(sevenDwarfs, org.hamcrest.Matchers.hasItem(org.hamcrest.core.Is.is(org.hamcrest.CoreMatchers.equalTo("Sleepy"))));89 assertThat(sevenDwarfs, org.hamcrest.Matchers.hasItem(org.hamcrest.Matchers.is(org.hamcrest.core.IsEqual.equalTo("Sleepy"))));90 assertThat(sevenDwarfs, org.hamcrest.Matchers.hasItem(org.hamcrest.CoreMatchers.is(org.hamcrest.core.IsEqual.equalTo("Sleepy"))));91 assertThat(sevenDwarfs, org.hamcrest.Matchers.hasItem(org.hamcrest.core.Is.is(org.hamcrest.core.IsEqual.equalTo("Sleepy"))));92 // ----93 assertThat(sevenDwarfs, org.hamcrest.CoreMatchers.hasItem(org.hamcrest.Matchers.is(org.hamcrest.Matchers.equalTo("Sleepy"))));94 assertThat(sevenDwarfs, org.hamcrest.CoreMatchers.hasItem(org.hamcrest.CoreMatchers.is(org.hamcrest.Matchers.equalTo("Sleepy"))));95 assertThat(sevenDwarfs, org.hamcrest.CoreMatchers.hasItem(org.hamcrest.core.Is.is(org.hamcrest.Matchers.equalTo("Sleepy"))));96 assertThat(sevenDwarfs, org.hamcrest.CoreMatchers.hasItem(org.hamcrest.Matchers.is(org.hamcrest.CoreMatchers.equalTo("Sleepy"))));97 assertThat(sevenDwarfs, org.hamcrest.CoreMatchers.hasItem(org.hamcrest.CoreMatchers.is(org.hamcrest.CoreMatchers.equalTo("Sleepy"))));98 assertThat(sevenDwarfs, org.hamcrest.CoreMatchers.hasItem(org.hamcrest.core.Is.is(org.hamcrest.CoreMatchers.equalTo("Sleepy"))));99 assertThat(sevenDwarfs, org.hamcrest.CoreMatchers.hasItem(org.hamcrest.Matchers.is(org.hamcrest.core.IsEqual.equalTo("Sleepy"))));100 assertThat(sevenDwarfs, org.hamcrest.CoreMatchers.hasItem(org.hamcrest.CoreMatchers.is(org.hamcrest.core.IsEqual.equalTo("Sleepy"))));101 assertThat(sevenDwarfs, org.hamcrest.CoreMatchers.hasItem(org.hamcrest.core.Is.is(org.hamcrest.core.IsEqual.equalTo("Sleepy"))));102 // ----103 assertThat(sevenDwarfs, org.hamcrest.core.IsIterableContaining.hasItem(org.hamcrest.Matchers.is(org.hamcrest.Matchers.equalTo("Sleepy"))));104 assertThat(sevenDwarfs, org.hamcrest.core.IsIterableContaining.hasItem(org.hamcrest.CoreMatchers.is(org.hamcrest.Matchers.equalTo("Sleepy"))));105 assertThat(sevenDwarfs, org.hamcrest.core.IsIterableContaining.hasItem(org.hamcrest.core.Is.is(org.hamcrest.Matchers.equalTo("Sleepy"))));106 assertThat(sevenDwarfs, org.hamcrest.core.IsIterableContaining.hasItem(org.hamcrest.Matchers.is(org.hamcrest.CoreMatchers.equalTo("Sleepy"))));107 assertThat(sevenDwarfs, org.hamcrest.core.IsIterableContaining.hasItem(org.hamcrest.CoreMatchers.is(org.hamcrest.CoreMatchers.equalTo("Sleepy"))));108 assertThat(sevenDwarfs, org.hamcrest.core.IsIterableContaining.hasItem(org.hamcrest.core.Is.is(org.hamcrest.CoreMatchers.equalTo("Sleepy"))));109 assertThat(sevenDwarfs, org.hamcrest.core.IsIterableContaining.hasItem(org.hamcrest.Matchers.is(org.hamcrest.core.IsEqual.equalTo("Sleepy"))));110 assertThat(sevenDwarfs, org.hamcrest.core.IsIterableContaining.hasItem(org.hamcrest.CoreMatchers.is(org.hamcrest.core.IsEqual.equalTo("Sleepy"))));111 assertThat(sevenDwarfs, org.hamcrest.core.IsIterableContaining.hasItem(org.hamcrest.core.Is.is(org.hamcrest.core.IsEqual.equalTo("Sleepy"))));112 }113 @Disabled("Too complex to worry about")114 @Test115 void test_has_item_is_equal_to_with_reason() {116 assertThat("reason", sevenDwarfs, org.hamcrest.Matchers.hasItem(org.hamcrest.Matchers.is(org.hamcrest.Matchers.equalTo("Sleepy"))));117 assertThat("reason", sevenDwarfs, org.hamcrest.Matchers.hasItem(org.hamcrest.CoreMatchers.is(org.hamcrest.Matchers.equalTo("Sleepy"))));118 assertThat("reason", sevenDwarfs, org.hamcrest.Matchers.hasItem(org.hamcrest.core.Is.is(org.hamcrest.Matchers.equalTo("Sleepy"))));119 assertThat("reason", sevenDwarfs, org.hamcrest.Matchers.hasItem(org.hamcrest.Matchers.is(org.hamcrest.CoreMatchers.equalTo("Sleepy"))));120 assertThat("reason", sevenDwarfs, org.hamcrest.Matchers.hasItem(org.hamcrest.CoreMatchers.is(org.hamcrest.CoreMatchers.equalTo("Sleepy"))));121 assertThat("reason", sevenDwarfs, org.hamcrest.Matchers.hasItem(org.hamcrest.core.Is.is(org.hamcrest.CoreMatchers.equalTo("Sleepy"))));122 assertThat("reason", sevenDwarfs, org.hamcrest.Matchers.hasItem(org.hamcrest.Matchers.is(org.hamcrest.core.IsEqual.equalTo("Sleepy"))));123 assertThat("reason", sevenDwarfs, org.hamcrest.Matchers.hasItem(org.hamcrest.CoreMatchers.is(org.hamcrest.core.IsEqual.equalTo("Sleepy"))));124 assertThat("reason", sevenDwarfs, org.hamcrest.Matchers.hasItem(org.hamcrest.core.Is.is(org.hamcrest.core.IsEqual.equalTo("Sleepy"))));125 // ----126 assertThat("reason", sevenDwarfs, org.hamcrest.CoreMatchers.hasItem(org.hamcrest.Matchers.is(org.hamcrest.Matchers.equalTo("Sleepy"))));127 assertThat("reason", sevenDwarfs, org.hamcrest.CoreMatchers.hasItem(org.hamcrest.CoreMatchers.is(org.hamcrest.Matchers.equalTo("Sleepy"))));128 assertThat("reason", sevenDwarfs, org.hamcrest.CoreMatchers.hasItem(org.hamcrest.core.Is.is(org.hamcrest.Matchers.equalTo("Sleepy"))));129 assertThat("reason", sevenDwarfs, org.hamcrest.CoreMatchers.hasItem(org.hamcrest.Matchers.is(org.hamcrest.CoreMatchers.equalTo("Sleepy"))));130 assertThat("reason", sevenDwarfs, org.hamcrest.CoreMatchers.hasItem(org.hamcrest.CoreMatchers.is(org.hamcrest.CoreMatchers.equalTo("Sleepy"))));131 assertThat("reason", sevenDwarfs, org.hamcrest.CoreMatchers.hasItem(org.hamcrest.core.Is.is(org.hamcrest.CoreMatchers.equalTo("Sleepy"))));132 assertThat("reason", sevenDwarfs, org.hamcrest.CoreMatchers.hasItem(org.hamcrest.Matchers.is(org.hamcrest.core.IsEqual.equalTo("Sleepy"))));133 assertThat("reason", sevenDwarfs, org.hamcrest.CoreMatchers.hasItem(org.hamcrest.CoreMatchers.is(org.hamcrest.core.IsEqual.equalTo("Sleepy"))));134 assertThat("reason", sevenDwarfs, org.hamcrest.CoreMatchers.hasItem(org.hamcrest.core.Is.is(org.hamcrest.core.IsEqual.equalTo("Sleepy"))));135 // ----136 assertThat("reason", sevenDwarfs, org.hamcrest.core.IsIterableContaining.hasItem(org.hamcrest.Matchers.is(org.hamcrest.Matchers.equalTo("Sleepy"))));137 assertThat("reason", sevenDwarfs, org.hamcrest.core.IsIterableContaining.hasItem(org.hamcrest.CoreMatchers.is(org.hamcrest.Matchers.equalTo("Sleepy"))));138 assertThat("reason", sevenDwarfs, org.hamcrest.core.IsIterableContaining.hasItem(org.hamcrest.core.Is.is(org.hamcrest.Matchers.equalTo("Sleepy"))));139 assertThat("reason", sevenDwarfs, org.hamcrest.core.IsIterableContaining.hasItem(org.hamcrest.Matchers.is(org.hamcrest.CoreMatchers.equalTo("Sleepy"))));140 assertThat("reason", sevenDwarfs, org.hamcrest.core.IsIterableContaining.hasItem(org.hamcrest.CoreMatchers.is(org.hamcrest.CoreMatchers.equalTo("Sleepy"))));141 assertThat("reason", sevenDwarfs, org.hamcrest.core.IsIterableContaining.hasItem(org.hamcrest.core.Is.is(org.hamcrest.CoreMatchers.equalTo("Sleepy"))));142 assertThat("reason", sevenDwarfs, org.hamcrest.core.IsIterableContaining.hasItem(org.hamcrest.Matchers.is(org.hamcrest.core.IsEqual.equalTo("Sleepy"))));143 assertThat("reason", sevenDwarfs, org.hamcrest.core.IsIterableContaining.hasItem(org.hamcrest.CoreMatchers.is(org.hamcrest.core.IsEqual.equalTo("Sleepy"))));144 assertThat("reason", sevenDwarfs, org.hamcrest.core.IsIterableContaining.hasItem(org.hamcrest.core.Is.is(org.hamcrest.core.IsEqual.equalTo("Sleepy"))));145 }146 }147 @Nested148 class HasItems {149 // should convert to assertThat(sevenDwarfs).contains("Bashful", "Happy")150 @Test151 void test_has_items() {152 assertThat(sevenDwarfs, org.hamcrest.Matchers.hasItems("Bashful", "Happy"));153 assertThat(sevenDwarfs, org.hamcrest.CoreMatchers.hasItems("Bashful", "Happy"));154 assertThat(sevenDwarfs, org.hamcrest.core.IsIterableContaining.hasItems("Bashful", "Happy"));155 }156 @Test157 void test_has_items_with_reason() {158 assertThat("reason", sevenDwarfs, org.hamcrest.Matchers.hasItems("Bashful", "Happy"));...
Source:RemoteHamcrestCoreMatcher13Test.java
...21import static org.hamcrest.core.Is.is;22import static org.junit.Assert.assertThat;23import androidx.test.espresso.proto.matcher13.HamcrestMatchersv13.AllOfProto;24import androidx.test.espresso.proto.matcher13.HamcrestMatchersv13.AnyOfProto;25import androidx.test.espresso.proto.matcher13.HamcrestMatchersv13.IsEqualProto;26import androidx.test.espresso.proto.matcher13.HamcrestMatchersv13.IsInstanceOfProto;27import androidx.test.espresso.proto.matcher13.HamcrestMatchersv13.IsNotProto;28import androidx.test.espresso.proto.matcher13.HamcrestMatchersv13.IsNullProto;29import androidx.test.espresso.proto.matcher13.HamcrestMatchersv13.IsProto;30import androidx.test.espresso.proto.matcher13.HamcrestMatchersv13.StringContainsProto;31import androidx.test.espresso.remote.GenericRemoteMessage;32import androidx.test.espresso.remote.RemoteDescriptorRegistry;33import androidx.test.ext.junit.runners.AndroidJUnit4;34import androidx.test.filters.SmallTest;35import org.hamcrest.Matcher;36import org.hamcrest.core.AllOf;37import org.hamcrest.core.AnyOf;38import org.hamcrest.core.Is;39import org.hamcrest.core.IsEqual;40import org.hamcrest.core.IsInstanceOf;41import org.hamcrest.core.IsNot;42import org.hamcrest.core.IsNull;43import org.hamcrest.core.StringContains;44import org.junit.Before;45import org.junit.Test;46import org.junit.runner.RunWith;47/**48 * Remote message transformation related test for all matchers under {@link49 * RemoteHamcrestCoreMatchers13}50 */51@RunWith(AndroidJUnit4.class)52@SmallTest53public class RemoteHamcrestCoreMatcher13Test {54 @Before55 public void registerMatcherWithRegistry() {56 RemoteHamcrestCoreMatchers13.init(RemoteDescriptorRegistry.getInstance());57 }58 @Test59 public void isEqual_transformationToProto() {60 IsEqual<Integer> isEqual = new IsEqual<>(5);61 GenericRemoteMessage isEqualRemoteMessage = new GenericRemoteMessage(isEqual);62 IsEqualProto isEqualProto = (IsEqualProto) isEqualRemoteMessage.toProto();63 assertThat(isEqualProto.getExpectedValue(), notNullValue());64 }65 @Test66 @SuppressWarnings({"unchecked"})67 public void isEqual_transformationFromProto() {68 IsEqual<Integer> isEqual = new IsEqual<>(5);69 GenericRemoteMessage isEqualRemoteMessage = new GenericRemoteMessage(isEqual);70 IsEqualProto isEqualProto = (IsEqualProto) isEqualRemoteMessage.toProto();71 IsEqual<Integer> isEqualFromProto =72 (IsEqual<Integer>) GenericRemoteMessage.FROM.fromProto(isEqualProto);73 assertThat(5, isEqualFromProto);74 }75 @Test76 public void is_transformationToProto() {77 IsEqual<Integer> nestedMatcher = new IsEqual<>(5);78 Is<Integer> isMatcher = new Is<>(nestedMatcher);79 GenericRemoteMessage isMatcherRemoteMessage = new GenericRemoteMessage(isMatcher);80 IsProto isMatcherProto = (IsProto) isMatcherRemoteMessage.toProto();81 assertThat(isMatcherProto.getMatcher(), notNullValue());82 }83 @Test84 @SuppressWarnings({"unchecked"})85 public void is_transformationFromProto() {86 IsEqual<Integer> nestedMatcher = new IsEqual<>(5);87 Is<Integer> isMatcher = new Is<>(nestedMatcher);88 GenericRemoteMessage isMatcherRemoteMessage = new GenericRemoteMessage(isMatcher);89 IsProto isMatcherProto = (IsProto) isMatcherRemoteMessage.toProto();90 Is<Integer> isMatcherFromProto =91 (Is<Integer>) GenericRemoteMessage.FROM.fromProto(isMatcherProto);92 assertThat(5, isMatcherFromProto);93 }94 @Test95 public void anyOf_transformationToProto() {96 Matcher<Integer> isEqualInteger = new IsEqual<>(5);97 Matcher<Integer> isEqualInteger2 = new IsEqual<>(3);98 AnyOf<Integer> anyOfMatcher = anyOf(isEqualInteger, isEqualInteger2);99 GenericRemoteMessage anyOfMatcherRemoteMessage = new GenericRemoteMessage(anyOfMatcher);100 AnyOfProto anyOfMatcherMatcherProto = (AnyOfProto) anyOfMatcherRemoteMessage.toProto();101 assertThat(anyOfMatcherMatcherProto.getMatchersCount(), equalTo(2));102 assertThat(anyOfMatcherMatcherProto.getMatchersList(), notNullValue());103 }104 @Test105 @SuppressWarnings({"unchecked"})106 public void anyOf_transformationFromProto() {107 Matcher<Integer> isEqualInteger = new IsEqual<>(5);108 Matcher<Integer> isEqualInteger2 = new IsEqual<>(3);109 AnyOf<Integer> anyOfMatcher = anyOf(isEqualInteger, isEqualInteger2);110 GenericRemoteMessage anyOfMatcherRemoteMessage = new GenericRemoteMessage(anyOfMatcher);111 AnyOfProto anyOfMatcherMatcherProto = (AnyOfProto) anyOfMatcherRemoteMessage.toProto();112 Matcher<Integer> anyOfMatcherFromProto =113 (Matcher<Integer>) GenericRemoteMessage.FROM.fromProto(anyOfMatcherMatcherProto);114 assertThat(5, anyOfMatcherFromProto);115 assertThat(3, anyOfMatcherFromProto);116 }117 @Test118 public void allOf_transformationToProto() {119 Matcher<Integer> isEqualInteger = new IsEqual<>(5);120 Matcher<Integer> isEqualInteger2 = new IsEqual<>(5);121 Matcher<Integer> allOfMatcher = allOf(isEqualInteger, isEqualInteger2);122 GenericRemoteMessage allOfMatcherRemoteMessage = new GenericRemoteMessage(allOfMatcher);123 AllOfProto allOfMatcherMatcherProto = (AllOfProto) allOfMatcherRemoteMessage.toProto();124 assertThat(allOfMatcherMatcherProto.getMatchersCount(), equalTo(2));125 assertThat(allOfMatcherMatcherProto.getMatchersList(), notNullValue());126 }127 @Test128 @SuppressWarnings({"unchecked"})129 public void allOf_transformationFromProto() {130 Matcher<Integer> isEqualInteger = equalTo(5);131 Matcher<Integer> isEqualInteger2 = equalTo(5);132 Matcher<Integer> allOfMatcher = allOf(isEqualInteger, isEqualInteger2);133 GenericRemoteMessage allOfMatcherRemoteMessage = new GenericRemoteMessage(allOfMatcher);134 AllOfProto allOfMatcherMatcherProto = (AllOfProto) allOfMatcherRemoteMessage.toProto();...
Source:CoreMatchers.java
...8import org.hamcrest.core.Every;9import org.hamcrest.core.Is;10import org.hamcrest.core.IsAnything;11import org.hamcrest.core.IsCollectionContaining;12import org.hamcrest.core.IsEqual;13import org.hamcrest.core.IsInstanceOf;14import org.hamcrest.core.IsNot;15import org.hamcrest.core.IsNull;16import org.hamcrest.core.IsSame;17import org.hamcrest.core.StringContains;18import org.hamcrest.core.StringEndsWith;19import org.hamcrest.core.StringStartsWith;20public class CoreMatchers {21 public static <T> Matcher<T> allOf(Iterable<Matcher<? super T>> matchers) {22 return AllOf.allOf((Iterable) matchers);23 }24 @SafeVarargs25 public static <T> Matcher<T> allOf(Matcher<? super T>... matchers) {26 return AllOf.allOf((Matcher[]) matchers);27 }28 public static <T> AnyOf<T> anyOf(Iterable<Matcher<? super T>> matchers) {29 return AnyOf.anyOf((Iterable) matchers);30 }31 @SafeVarargs32 public static <T> AnyOf<T> anyOf(Matcher<? super T>... matchers) {33 return AnyOf.anyOf((Matcher[]) matchers);34 }35 public static <LHS> CombinableBothMatcher<LHS> both(Matcher<? super LHS> matcher) {36 return CombinableMatcher.both(matcher);37 }38 public static <LHS> CombinableEitherMatcher<LHS> either(Matcher<? super LHS> matcher) {39 return CombinableMatcher.either(matcher);40 }41 public static <T> Matcher<T> describedAs(String description, Matcher<T> matcher, Object... values) {42 return DescribedAs.describedAs(description, matcher, values);43 }44 public static <U> Matcher<Iterable<? extends U>> everyItem(Matcher<U> itemMatcher) {45 return Every.everyItem(itemMatcher);46 }47 public static <T> Matcher<T> is(Matcher<T> matcher) {48 return Is.is((Matcher) matcher);49 }50 public static <T> Matcher<T> is(T value) {51 return Is.is((Object) value);52 }53 public static void is(Class<?> cls) {54 }55 public static <T> Matcher<T> isA(Class<T> type) {56 return Is.isA(type);57 }58 public static Matcher<Object> anything() {59 return IsAnything.anything();60 }61 public static Matcher<Object> anything(String description) {62 return IsAnything.anything(description);63 }64 public static <T> Matcher<Iterable<? super T>> hasItem(Matcher<? super T> itemMatcher) {65 return IsCollectionContaining.hasItem((Matcher) itemMatcher);66 }67 public static <T> Matcher<Iterable<? super T>> hasItem(T item) {68 return IsCollectionContaining.hasItem((Object) item);69 }70 @SafeVarargs71 public static <T> Matcher<Iterable<T>> hasItems(Matcher<? super T>... itemMatchers) {72 return IsCollectionContaining.hasItems((Matcher[]) itemMatchers);73 }74 @SafeVarargs75 public static <T> Matcher<Iterable<T>> hasItems(T... items) {76 return IsCollectionContaining.hasItems((Object[]) items);77 }78 public static <T> Matcher<T> equalTo(T operand) {79 return IsEqual.equalTo(operand);80 }81 public static Matcher<Object> equalToObject(Object operand) {82 return IsEqual.equalToObject(operand);83 }84 public static <T> Matcher<T> any(Class<T> type) {85 return IsInstanceOf.any(type);86 }87 public static <T> Matcher<T> instanceOf(Class<?> type) {88 return IsInstanceOf.instanceOf(type);89 }90 public static <T> Matcher<T> not(Matcher<T> matcher) {91 return IsNot.not((Matcher) matcher);92 }93 public static <T> Matcher<T> not(T value) {94 return IsNot.not((Object) value);95 }96 public static Matcher<Object> notNullValue() {...
Source:DefaultModuleIdDerivatorTest.java
...14 * limitations under the License.15 */16package org.sourcepit.b2.model.builder.util;17import static org.junit.Assert.assertThat;18import org.hamcrest.core.IsEqual;19import org.junit.Test;20import org.sourcepit.common.utils.props.LinkedPropertiesMap;21import org.sourcepit.common.utils.props.PropertiesMap;22public class DefaultModuleIdDerivatorTest {23 @Test24 public void test() {25 PropertiesMap properties = new LinkedPropertiesMap();26 properties.put("project.groupId", "commons-io");27 properties.put("project.artifactId", "commons-io");28 DefaultModuleIdDerivator moduleIdDerivator = new DefaultModuleIdDerivator();29 String name = moduleIdDerivator.deriveModuleId(null, properties);30 assertThat(name, IsEqual.equalTo("commons.io"));31 properties.put("project.groupId", "org.junit");32 properties.put("project.artifactId", "junit");33 name = moduleIdDerivator.deriveModuleId(null, properties);34 assertThat(name, IsEqual.equalTo("org.junit"));35 properties.put("project.groupId", "org.osgi");36 properties.put("project.artifactId", "org.osgi.core");37 name = moduleIdDerivator.deriveModuleId(null, properties);38 assertThat(name, IsEqual.equalTo("org.osgi.core"));39 properties.put("project.groupId", "org.aspectj");40 properties.put("project.artifactId", "aspectjrt");41 name = moduleIdDerivator.deriveModuleId(null, properties);42 assertThat(name, IsEqual.equalTo("org.aspectj.rt"));43 properties.put("project.groupId", "org.hamcrest");44 properties.put("project.artifactId", "hamcrest-core");45 name = moduleIdDerivator.deriveModuleId(null, properties);46 assertThat(name, IsEqual.equalTo("org.hamcrest.core"));47 properties.put("project.groupId", "org.hamcrest");48 properties.put("project.artifactId", "hamcrest_core");49 name = moduleIdDerivator.deriveModuleId(null, properties);50 assertThat(name, IsEqual.equalTo("org.hamcrest.core"));51 properties.put("project.groupId", "org.hamcrest");52 properties.put("project.artifactId", "hamcrest.core");53 name = moduleIdDerivator.deriveModuleId(null, properties);54 assertThat(name, IsEqual.equalTo("org.hamcrest.core"));55 properties.put("project.groupId", "org.hamcrest");56 properties.put("project.artifactId", "hamcrest._-core");57 name = moduleIdDerivator.deriveModuleId(null, properties);58 assertThat(name, IsEqual.equalTo("org.hamcrest.core"));59 properties.put("project.groupId", "org.foo");60 properties.put("project.artifactId", "bar");61 name = moduleIdDerivator.deriveModuleId(null, properties);62 assertThat(name, IsEqual.equalTo("org.foo.bar"));63 properties.put("project.groupId", "org.sourcepit.common");64 properties.put("project.artifactId", "common-manifest");65 name = moduleIdDerivator.deriveModuleId(null, properties);66 assertThat(name, IsEqual.equalTo("org.sourcepit.common.manifest"));67 properties.put("project.groupId", "org.sourcepit.tools");68 properties.put("project.artifactId", "osgify-core");69 name = moduleIdDerivator.deriveModuleId(null, properties);70 assertThat(name, IsEqual.equalTo("org.sourcepit.tools.osgify.core"));71 properties.put("project.groupId", "org.sourcepit-tools");72 properties.put("project.artifactId", "osgify_maven-plugin");73 name = moduleIdDerivator.deriveModuleId(null, properties);74 assertThat(name, IsEqual.equalTo("org.sourcepit.tools.osgify.maven.plugin"));75 }76}...
Source:HamcrestEqualsAssertions.java
...6 private final String expected = "hello world";7 @Test8 void test_equalTo() {9 assertThat(actual, org.hamcrest.CoreMatchers.equalTo(expected));10 assertThat(actual, org.hamcrest.core.IsEqual.equalTo(expected));11 assertThat(actual, org.hamcrest.Matchers.equalTo(expected));12 }13 @Test14 void test_equalTo_with_reason() {15 assertThat("reason", actual, org.hamcrest.CoreMatchers.equalTo(expected));16 assertThat("reason", actual, org.hamcrest.core.IsEqual.equalTo(expected));17 assertThat("reason", actual, org.hamcrest.Matchers.equalTo(expected));18 }19 @Test20 void test_is() {21 assertThat(actual, org.hamcrest.CoreMatchers.is(expected));22 assertThat(actual, org.hamcrest.core.Is.is(expected));23 assertThat(actual, org.hamcrest.Matchers.is(expected));24 }25 @Test26 void test_is_with_reason() {27 assertThat("reason", actual, org.hamcrest.CoreMatchers.is(expected));28 assertThat("reason", actual, org.hamcrest.core.Is.is(expected));29 assertThat("reason", actual, org.hamcrest.Matchers.is(expected));30 }31 @Test32 void test_isEqualTo() {33 assertThat(actual, org.hamcrest.CoreMatchers.is(org.hamcrest.CoreMatchers.equalTo(expected)));34 assertThat(actual, org.hamcrest.CoreMatchers.is(org.hamcrest.core.IsEqual.equalTo(expected)));35 assertThat(actual, org.hamcrest.CoreMatchers.is(org.hamcrest.Matchers.equalTo(expected)));36 assertThat(actual, org.hamcrest.core.Is.is(org.hamcrest.CoreMatchers.equalTo(expected)));37 assertThat(actual, org.hamcrest.core.Is.is(org.hamcrest.core.IsEqual.equalTo(expected)));38 assertThat(actual, org.hamcrest.core.Is.is(org.hamcrest.Matchers.equalTo(expected)));39 assertThat(actual, org.hamcrest.Matchers.is(org.hamcrest.CoreMatchers.equalTo(expected)));40 assertThat(actual, org.hamcrest.Matchers.is(org.hamcrest.core.IsEqual.equalTo(expected)));41 assertThat(actual, org.hamcrest.Matchers.is(org.hamcrest.Matchers.equalTo(expected)));42 }43 @Test44 void test_isEqualTo_with_reason() {45 assertThat("reason", actual, org.hamcrest.CoreMatchers.is(org.hamcrest.CoreMatchers.equalTo(expected)));46 assertThat("reason", actual, org.hamcrest.CoreMatchers.is(org.hamcrest.core.IsEqual.equalTo(expected)));47 assertThat("reason", actual, org.hamcrest.CoreMatchers.is(org.hamcrest.Matchers.equalTo(expected)));48 assertThat("reason", actual, org.hamcrest.core.Is.is(org.hamcrest.CoreMatchers.equalTo(expected)));49 assertThat("reason", actual, org.hamcrest.core.Is.is(org.hamcrest.core.IsEqual.equalTo(expected)));50 assertThat("reason", actual, org.hamcrest.core.Is.is(org.hamcrest.Matchers.equalTo(expected)));51 assertThat("reason", actual, org.hamcrest.Matchers.is(org.hamcrest.CoreMatchers.equalTo(expected)));52 assertThat("reason", actual, org.hamcrest.Matchers.is(org.hamcrest.core.IsEqual.equalTo(expected)));53 assertThat("reason", actual, org.hamcrest.Matchers.is(org.hamcrest.Matchers.equalTo(expected)));54 }55}...
Source:MatcherFactory.java
1package com.deere.axiom;2import org.hamcrest.Matcher;3import org.hamcrest.core.IsCollectionContaining;4import org.hamcrest.core.IsEqual;5import org.hamcrest.core.IsInstanceOf;6import org.hamcrest.core.IsNot;7import org.hamcrest.core.IsNull;8import org.hamcrest.core.IsSame;9//import org.mockito.internal.matchers.Contains;10import java.lang.annotation.Annotation;11import java.util.Collection;12//import static com.deere.axiom.IsAnIterableInWhichItemsAppearInOrder.IsAnIterableInWhichItemsAppearInOrderBuilder;13public class MatcherFactory {14 private MatcherFactory() { }15 public static <T> IsEqual<T> isEqualTo(final T obj) {16 return new IsEqual<T>(obj);17 }18 public static IsInstanceOf isInstanceOf(final Class<?> clazz) {19 return new IsInstanceOf(clazz);20 }21 public static <T> IsNull<T> isNull() {22 return new IsNull<T>();23 }24 public static <T> IsNot<T> isNotNull() {25 return new IsNot<T>(new IsNull<T>());26 }27 public static <T> IsSame<T> isSameObjectAs(final T obj) {28 return new IsSame<T>(obj);29 }30 public static <T> IsCollectionContaining<T> isACollectionThatContains(final T value) {31 return new IsCollectionContaining<T>(new IsEqual<T>(value));32 }33 public static <T> IsCollectionContaining<T> isACollectionThatContainsSomethingThat(final Matcher<T> matcher) {34 return new IsCollectionContaining<T>(matcher);35 }36 public static IsEqual<Boolean> isTrue() {37 return new IsEqual<Boolean>(true);38 }39 public static <T> IsNot<T> isNot(final Matcher<T> matcher) {40 return new IsNot<T>(matcher);41 }42 public static IsEqual<Boolean> isFalse() {43 return new IsEqual<Boolean>(false);44 }45 /* public static Contains containsString(final String string) {46 return new Contains(string);47 }*/48 /*public static Matcher<Long> isLessThan(final Long aLong) {49 return new IsLessThan(aLong);50 }*/51 /*public static <T> Matcher<? extends Collection<? extends T>> isCollectionThatContainsType(final Class<T> clazz) {52 return new IsCollectionThatContainsType<T>(clazz);53 }54 public static <T> ContainsInItsModelSomethingThat<T> containsInItsModelSomethingThat(final Matcher<T> matcher) {55 return new ContainsInItsModelSomethingThat<T>(matcher);56 }57 public static <T> Matcher<Collection<? extends T>> isACollectionOfSize(final int size) {...
Source:MessageTest.java
...8import org.benhur.codurance.data.IMessage;9import org.benhur.codurance.data.IUser;10import org.benhur.codurance.data.Message;11import org.benhur.codurance.data.User;12import org.hamcrest.core.IsEqual;13import org.hamcrest.core.IsNot;14import org.hamcrest.core.IsNull;15import org.junit.Test;1617public class MessageTest {1819 @Test20 public void testCreation() {21 IUser sender = new User("user");22 IMessage message = new Message(0l, sender, new Date(), "Hello world !");23 assertThat(message.getId(), IsEqual.equalTo(0l));24 assertThat(message.getSender(), IsEqual.equalTo(sender));25 assertThat(message.getTimestamp(), IsNull.notNullValue());26 assertThat(message.getText(), IsEqual.equalTo("Hello world !"));27 }2829 @Test30 public void testMultiCreation() {31 IUser sender = new User("user");32 IMessage message1 = new Message(0l, sender, new Date(), "Hello world !");33 IMessage message2 = new Message(1l, sender, new Date(), "Hello world !");34 assertThat(message1.getId(), IsNot.not(IsEqual.equalTo(message2.getSender())));35 assertThat(message1.getSender(), IsEqual.equalTo(message2.getSender()));36 assertThat(37 message1.getTimestamp().getTime(), IsEqual.equalTo(message2.getTimestamp().getTime()));38 assertThat(message1.getText(), IsEqual.equalTo(message2.getText()));39 }40}
...
Source:TrueTest.java
1package com.beerbuddy.core.service.impl;2import static org.hamcrest.core.Is.is;3import static org.hamcrest.core.IsEqual.equalTo;4import static org.junit.Assert.assertThat;5import org.hamcrest.core.Is;6import org.hamcrest.core.IsEqual;7import org.junit.Assert;8import org.junit.Test;9public class TrueTest {10 11 @Test12 public void trueIsTrue() {13 Assert.assertTrue(true);14 Assert.assertTrue("true is equal to true...", true);15 16 Assert.assertThat(true, Is.is(IsEqual.equalTo(true)));17 Assert.assertThat("True is true", true, Is.is(IsEqual.equalTo(true)));18 19 assertThat("True is true", true, is(equalTo(true)));20 }21 22}...
IsEqual
Using AI Code Generation
1import static org.hamcrest.CoreMatchers.is;2import static org.hamcrest.MatcherAssert.assertThat;3import static org.hamcrest.core.IsEqual.equalTo;4public class ExampleTest {5 public void testAssertThatBothContainsString() {6 String str1 = "Junit is working fine";7 String str2 = "Junit is working fine";8 assertThat(str1, is(equalTo(str2)));9 }10}11Example 2: Using is() method of org.hamcrest.core package12import static org.hamcrest.CoreMatchers.is;13import static org.hamcrest.MatcherAssert.assertThat;14public class ExampleTest {15 public void testAssertThatBothContainsString() {16 String str1 = "Junit is working fine";17 String str2 = "Junit is working fine";18 assertThat(str1, is(str2));19 }20}21Example 3: Using is() method of org.hamcrest.core package22import static org
IsEqual
Using AI Code Generation
1import static org.hamcrest.CoreMatchers.*;2import static org.junit.Assert.assertThat;3import org.junit.Test;4public class HamcrestTest {5public void testAssertThatBothContainsString() {6String str1 = "Junit is working fine";7String str2 = "Junit is working fine";8assertThat(str1, both(containsString("Junit")).and(containsString("fine")));9assertThat(str2, both(containsString("Junit")).and(containsString("fine")));10}11}12package com.javacodegeeks.junit;13import static org.hamcrest.CoreMatchers.both;14import static org.hamcrest.CoreMatchers.containsString;15import static org.hamcrest.MatcherAssert.assertThat;16import org.junit.jupiter.api.Test;17public class HamcrestTest {18public void testAssertThatBothContainsString() {19String str1 = "Junit is working fine";20String str2 = "Junit is working fine";21assertThat(str1, both(containsString("Junit")).and(containsString("fine")));22assertThat(str2, both(containsString("Junit")).and(containsString("fine")));23}24}25package com.javacodegeeks.junit;26import static org.hamcrest.CoreMatchers.both;27import static org.hamcrest.CoreMatchers.containsString;28import static org.hamcrest.MatcherAssert.assertThat;29import org.junit.jupiter.api.Test;30public class HamcrestTest {31public void testAssertThatBothContainsString() {32String str1 = "Junit is working fine";33String str2 = "Junit is working fine";34assertThat(str1, both(containsString("Junit")).and(containsString("fine")));35assertThat(str2, both(containsString("Junit")).and(containsString("fine")));36}37}38package com.javacodegeeks.junit;39import static org.hamcrest.CoreMatchers.both;40import static org.hamcrest.CoreMatchers.containsString;41import static org.hamcrest.MatcherAssert.assertThat;42import org.junit.jupiter.api.Test;43public class HamcrestTest {44public void testAssertThatBothContainsString() {
IsEqual
Using AI Code Generation
1public void testIsEqual() {2 assertThat("Hello JUnit 5", equalTo("Hello JUnit 5"));3}4public void testIsNull() {5 assertThat(null, nullValue());6}7public void testIsNotNull() {8 assertThat("Hello JUnit 5", notNullValue());9}10public void testIsEmptyString() {11 assertThat("", isEmptyString());12}13public void testIsNotEmptyString() {14 assertThat("Hello JUnit 5", not(isEmptyString()));15}16public void testIsEmptyCollection() {17 assertThat(new ArrayList<>(), empty());18}19public void testIsNotEmptyCollection() {20 List<String> list = new ArrayList<>();21 list.add("Hello JUnit 5");22 assertThat(list, not(empty()));23}24public void testIsEqualIgnoringCase() {25 assertThat("Hello JUnit 5", equalToIgnoringCase("hello junit 5"));26}27public void testIsEqualIgnoringWhiteSpace() {28 assertThat("Hello JUnit 5", equalToIgnoringWhiteSpace(" Hello JUnit 5 "));29}30public void testIsStringContainsInOrder() {31 assertThat("Hello JUnit 5", containsString("Hello"));32 assertThat("Hello JUnit 5", containsString("JUnit"));33 assertThat("Hello JUnit 5", containsString("5"));34}35public void testIsStringContainsInOrderIgnoringCase() {36 assertThat("Hello JUnit 5", containsStringIgnoringCase("hello"));37 assertThat("Hello JUnit 5", containsStringIgnoringCase("JUNIT"));38 assertThat("Hello JUnit 5", containsStringIgnoringCase("5"));39}
IsEqual
Using AI Code Generation
1import org.hamcrest.core.IsEqual;2import org.junit.Test;3import static org.hamcrest.MatcherAssert.assertThat;4import static org.hamcrest.core.IsEqual.equalTo;5public class TestIsEqual {6public void testIsEqual() {7assertThat("failure - strings are not equal", "text", IsEqual.equalTo("text"));8}9}10BUILD SUCCESSFUL (total time: 0 seconds)11import org.hamcrest.core.IsEqual;12import org.junit.Test;13import static org.hamcrest.MatcherAssert.assertThat;14import static org.hamcrest.core.IsEqual.equalTo;15public class TestIsEqual {16public void testIsEqual() {17assertThat("failure - strings are not equal", "text", equalTo("text"));18}19}20BUILD SUCCESSFUL (total time: 0 seconds)
IsEqual
Using AI Code Generation
1import org.hamcrest.core.IsEqual2import org.hamcrest.core.IsNot3import org.hamcrest.core.IsNull4import org.junit.Assert.assertThat5import org.junit.Test6class MyTest {7 fun test() {8 val list = listOf("a", "b", "c")9 assertThat(list, IsNull())10 assertThat(list, IsNot(IsNull()))11 assertThat(list, IsEqual(listOf("a", "b", "c")))12 assertThat(list, IsNot(IsEqual(listOf("a", "b", "c", "d"))))13 }14}15import org.hamcrest.MatcherAssert.assertThat16import org.hamcrest.Matchers.*17import org.junit.Assert.assertTrue18import org.junit.Assert.assertFalse19import org.junit.Test20class MyTest {21 fun test() {22 val list = listOf("a", "b", "c")23 assertTrue(list is List<*>)24 assertFalse(list is List<*?>)25 assertThat(list, nullValue())26 assertThat(list, notNullValue())27 assertThat(list, `is`(listOf("a", "b", "c")))28 assertThat(list, not(`is`(listOf("a", "b", "c", "d"))))29 }30}31import org.hamcrest.core.IsEqual32import org.hamcrest.core.IsNot33import org.hamcrest.core.IsNull34import org.junit.Assert.assertThat35import org.junit.Test36class MyTest {37 fun test() {38 val list = listOf("
IsEqual
Using AI Code Generation
1import static org.hamcrest.CoreMatchers.equalTo;2import static org.hamcrest.MatcherAssert.assertThat;3public class IsEqualTest {4public void isEqualTest() {5assertThat(10, equalTo(10));6}7}
LambdaTest also has a detailed JUnit tutorial explaining its features, importance, advanced use cases, best practices, and more to help you get started with running your automation testing scripts.
Here are the detailed JUnit testing chapters to help you get started:
You can also check out our JUnit certification if you wish to take your career in Selenium automation testing with JUnit to the next level.
Get 100 minutes of automation test minutes FREE!!