hamcrest

Android Studio - Program type already present: org.hamcrest.CoreMatchers

天大地大妈咪最大 提交于 2019-12-03 12:48:23
I have no idea why this error exists: Program type already present: org.hamcrest.CoreMatchers Message{kind=ERROR, text=Program type already present: org.hamcrest.CoreMatchers, sources=[Unknown source file], tool name=Optional.of(D8)} My code in in the scope if dependency of build.gradle (Module: app) is: dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'com.android.support:appcompat-v7:26.1.0' implementation 'com.android.support.constraint:constraint-layout:1.0.2' testImplementation ('junit:junit:4.12'){ exclude group: 'org.hamcrest', module: 'hamcrest

Mockito, JUnit, Hamcrest, Versioning

巧了我就是萌 提交于 2019-12-03 10:49:23
By default, the required version of Hamcrest for: JUnit 4.11 Hamcrest 1.3 Mockito-core 1.9.5 Hamcrest 1.1 There were not insiginifcant API changes between Hamcrest 1.1 and 1.3. Currently my test cases attempt to run JUnit 4.11 with Hamcrest 1.1, but I'm reasonably sure that this is a bad idea. For similar reasons, I suspect that trying to use Mockito-core 1.9.5 with Hamcrest 1.3 is also a bad idea. What to do? Use Hamcrest 1.1 with the latest JUnit and Mockito Use Hamcrest 1.3 with the latest JUnit and Mockito Attempt to patch Mockito-core 1.9.5 to use Hamcrest 1.3 Time I don't really have at

Mockito and Hamcrest: how to verify invocation of Collection argument?

旧街凉风 提交于 2019-12-03 10:23:22
I'm running into a generics problem with Mockito and Hamcrest. Please assume the following interface: public interface Service { void perform(Collection<String> elements); } And the following test snippet: Service service = mock(Service.class); // ... perform business logic verify(service).perform(Matchers.argThat(contains("a", "b"))); So I want to verify that my business logic actually called the service with a collection that contains "a" and "b" in that order. However, the return type of contains(...) is Matcher<Iterable<? extends E>> , so Matchers.argThat(...) returns Iterable<String> in

Generics hell: hamcrest matcher as a method parameter

僤鯓⒐⒋嵵緔 提交于 2019-12-03 10:13:21
So, let's have a list of strings and a function that takes a Hamcrest matcher and returns a result of the matches() method of the provided matcher: public boolean matchIt(final Matcher<? super List<String>> matcher) { final List<String> lst = obtainListFromSomewhere(); return matcher.matches(lst); } So far so good. Now I can easily call: matchIt(empty()); matchIt(anything()); matchIt(hasItem("item")); matchIt(everyItem(equalToIgnoringCase("item"))); ...since all of these factory static methods produce a matcher that fits the method signature Matcher<? super List<String>> . However, I believe a

Java 8 - retry a method until a condition is fulfilled (in intervals)

ε祈祈猫儿з 提交于 2019-12-03 07:08:12
问题 I want to create a class that can run a method until a condition about the return value is fulfilled. It should look something like this methodPoller.poll(pollDurationSec, pollIntervalMillis) .method(dog.bark()) .until(dog -> dog.bark().equals("Woof")) .execute(); My method poller look somewhat like this () // following GuiSim answer public class MethodPoller { Duration pollDurationSec; int pollIntervalMillis; public MethodPoller() { } public MethodPoller poll(Duration pollDurationSec, int

Mixing Hamcrest and TestNG

若如初见. 提交于 2019-12-03 03:10:16
问题 Has anyone integrated Hamcrest with TestNG so that its matchers can easily be used in TestNG assertions? 回答1: In short, to answer your question: You don't need to integrate TestNG with Hamcrest. Just call org.hamcrest.MatcherAssert.assertThat(...) directly which throws java.lang.AssertionError . Background I found your question via Google, wondering exactly the same issue. After further Googling, I didn't find any satisfying answers, so I read the source code for JUnit's integration with

Difference between hamcrest-library Matchers and hamcrest-core CoreMatchers

∥☆過路亽.° 提交于 2019-12-03 01:58:46
It looks like the hamcrest org.hamcrest.Matchers class is very similar to org.hamcrest.CoreMatchers (though it looks like Matchers has more). Why would I choose to use CoreMatchers (other than it looks like the class is slightly smaller), and why are these two classes so similar? The Hamcrest matchers are split into several modules. The "core" includes the most basic matchers and abstract classes required for building other matchers. org.hamcrest.CoreMatchers includes the factory methods for just these matchers. The other matchers are in the "library" module grouped by the types of objects

Java 8 - retry a method until a condition is fulfilled (in intervals)

て烟熏妆下的殇ゞ 提交于 2019-12-02 20:47:14
I want to create a class that can run a method until a condition about the return value is fulfilled. It should look something like this methodPoller.poll(pollDurationSec, pollIntervalMillis) .method(dog.bark()) .until(dog -> dog.bark().equals("Woof")) .execute(); My method poller look somewhat like this () // following GuiSim answer public class MethodPoller { Duration pollDurationSec; int pollIntervalMillis; public MethodPoller() { } public MethodPoller poll(Duration pollDurationSec, int pollIntervalMillis) { this.pollDurationSec = pollDurationSec; this.pollIntervalMillis =

How to assertThat something is null with Hamcrest?

北城以北 提交于 2019-12-02 18:56:05
How would I assertThat something is null ? for example assertThat(attr.getValue(), is("")); But I get an error saying that I cannot have null in is(null) . Rohit Jain You can use IsNull.nullValue() method: import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.nullValue; assertThat(attr.getValue(), is(nullValue())); Chetya why not use assertNull(object) / assertNotNull(object) ? If you want to hamcrest , you can do import static org.hamcrest.Matchers.nullValue; assertThat(attr.getValue(), is(nullValue())); In Junit you can do import static junit.framework.Assert.assertNull

Mixing Hamcrest and TestNG

不问归期 提交于 2019-12-02 16:39:42
Has anyone integrated Hamcrest with TestNG so that its matchers can easily be used in TestNG assertions? In short, to answer your question: You don't need to integrate TestNG with Hamcrest. Just call org.hamcrest.MatcherAssert.assertThat(...) directly which throws java.lang.AssertionError . Background I found your question via Google, wondering exactly the same issue. After further Googling, I didn't find any satisfying answers, so I read the source code for JUnit's integration with Hamcrest. With JUnit, Hamcrest integration is normally used by calling: org.junit.Assert.assertThat( T actual,