Mockito isA(Class clazz) How to resolve type safety?

Mockito/Hamcrest and generic classes Yes, this is a general problem with Mockito/Hamcrest. Generally using isA() with generic classes produces a warning. There are predifined Mockito matchers for the most common generic classes: anyList(), anyMap(), anySet() and anyCollection(). Suggestions: anyIterable() in Mockito 2.1.0 Mockito 2.1.0 added a new anyIterable() method for matching Iterables: when(client.runTask(anyString(), anyString(), anyIterable()).thenReturn(…) … Read more

PowerMock & Java 11

After one year of no releases, things are really moving in PowerMock. PowerMock 2.0.0-RC1 was released. And with PowerMockito 2.0.0-RC1 + @PowerMockIgnore({“com.sun.org.apache.xerces.*”, “javax.xml.*”, “org.xml.*”, “org.w3c.*”}) The tests work under Java 11.

Hamcrest – what version to use? 1.3 or 2

EDIT: After several years the answer is to use the latest Hamcrest 2 version (2.2 from 17th October 2019). For additional details also refer to @dschulten’s answer. Following is my original answer which I leave as context to understand the problem and confusion around Hamcrest versions 1.3 and 2.0.0.0 back in the day. Based on … Read more

How to use Hamcrest to inspect Map items

Youu could just use contains or containsInAnyOrder. True, you’ll have to list all items in the List that way, but it works cleaner than hasItem: @SuppressWarnings(“unchecked”) @Test public void mapTest() { Map<String, List<MyItem>> map = new HashMap<String, List<MyItem>>(); map.put(“one”, asList(new MyItem(“1”), new MyItem(“one”))); assertThat(map, hasEntry(is(“one”), containsInAnyOrder(hasProperty(“name”, is(“one”)), hasProperty(“name”, is(“1”))))); }

EasyMock void method

You’re close. You just need to call the method on your mock before calling expectLastCall() So you expectation would look like this: userService.addUser(newUser1); EasyMock.expectLastCall(); EasyMock.replay(dbMapper); userService.addUser(newUser1); This works because the mock object is in Record mode before the call to replay(), so any calls to it will perform default behaviour (return null/do nothing) and will … Read more

Spring jUnit Testing properties file

Firstly, application.properties in the @PropertySource should read application-test.properties if that’s what the file is named (matching these things up matters): @PropertySource(“classpath:application-test.properties”) That file should be under your /src/test/resources classpath (at the root). I don’t understand why you’d specify a dependency hard coded to a file called application-test.properties. Is that component only to be used in … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)