matcher

Hamcrest Matchers - Assert Type of List

点点圈 提交于 2019-12-10 14:39:30
问题 The Problem I'm currently trying to use Hamcrest Matchers to assert that the list type being returned is of a specific type. For example, let's say I have the following List that is being returned by my service call: List<SomePOJO> myList; I want to assert that the list being returned is parametrized of type SomePOJO and not TheOtherPOJO . However, it appears that Hamcrest Matchers does not have this sort of functionality. What I Have Tried After some research, I have seen the following

Regex Java word context

♀尐吖头ヾ 提交于 2019-12-10 11:56:12
问题 what I want to achieve is that I want to obtain the context of an acronym. Can you help me pls with the regular expression? I am looping over the text (String) and looking for dots, after match I am trying to get the context of the particular found acronym, so that I can do some other processing after that, but I cant get the context. I need to take at least 5 words before and 5 words after the acronym. //Pattern to match each word ending with dot Pattern pattern = Pattern.compile("(\\w+)\\b(

How to show custom failure message in Specs2 (Scala)?

混江龙づ霸主 提交于 2019-12-10 02:52:06
问题 For example, for code like this: myNum must beEqualTo("SOME INTERESTING TEXT") The message will be like the following: java.lang.Exception: ArrayBuffer() doesn't have size 1 but size 0 Is there an elegant way to get customised message displayed here? 回答1: First you can name value you're testing. myNum aka "meaningful name" must_== expectedValue You can also overwrite the full message. (myNum must_== expectedValue).setMessage("Full failure message") 来源: https://stackoverflow.com/questions

Mockito: Match any String except one [duplicate]

爱⌒轻易说出口 提交于 2019-12-10 01:57:02
问题 This question already has answers here : How to write a matcher that is not equal to something (4 answers) Closed 4 years ago . How can I write a matcher using Mockito that matches any string except a specific one? I have tried using some hamcrest matchers to negate and combine other matchers, but the hamcrest matchers all return values of type Matcher<T> which dont work very well with Mockito matchers. 回答1: The solution I used: argThat(not("ExceptionString")) Where argThat is a Mockito

GoogleMock: how to expect precisely one call with a certain argument, and see diagnostic on failure?

五迷三道 提交于 2019-12-08 06:11:17
问题 Maybe a finesse question, my problem is that if I write: EXPECT_CALL(mock, handleMessage(_)).Times(0); // expectation #1 EXPECT_CALL(mock, handleMessage(Pointee(IsLike(aSpecificMessage)))); // expectation #2 ... and method handleMessage is called once, but with a different argument (not aSpecificMessage ), then the failure looks like: Mock function called more times than expected - returning default value. Function call: handleMessage(0x8b5378) Returns: false Expected: to be never called

java.util.regex.Matcher confused group

依然范特西╮ 提交于 2019-12-08 04:37:30
问题 I'm having trouble getting the right group of a regex match. My code boils down to following: Pattern fileNamePattern = Pattern.compile("\\w+_\\w+_\\w+_(\\w+)_(\\d*_\\d*)\\.xml"); Matcher fileNameMatcher = fileNamePattern.matcher("test_test_test_test_20110101_0000.xml"); System.out.println(fileNameMatcher.groupCount()); if (fileNameMatcher.matches()) { for (int i = 0; i < fileNameMatcher.groupCount(); ++i) { System.out.println(fileNameMatcher.group(i)); } } I expect the output to be: 2 test

How to use Android REGEX with Pattern and Matcher Classes?

自闭症网瘾萝莉.ら 提交于 2019-12-07 06:58:15
问题 I have the following code: String example = "<!--§FILES_SECTION§\n" + "Example line one\n" + "Example line two\n" + "§FILES_SECTION§-->"; String myPattern = ".*?FILES_SECTION.*?\n(.*?)\n.*?FILES_SECTION.*?"; Pattern p = Pattern.compile(myPattern); Matcher m = p.matcher(example); if ( m.matches() ) Log.d("Matcher", "PATTERN MATCHES!"); else Log.d("MATCHER", "PATTERN DOES NOT MATCH!"); Why does it always return "PATTERN DOES NOT MATCH?" 回答1: By default, the . does not match line breaks. You

Mockito matcher to match a method with generics and a supplier

时光毁灭记忆、已成空白 提交于 2019-12-07 04:29:20
问题 I'm using Java 1.8.0_131, Mockito 2.8.47 and PowerMock 1.7.0. My question is not related to PowerMock, it is released to a Mockito.when(…) matcher. I need a solution to mock this method which is called by my class under test: public static <T extends Serializable> PersistenceController<T> createController( final Class<? extends Serializable> clazz, final Supplier<T> constructor) { … } The method is called from the class under test like this: PersistenceController<EventRepository>

GoogleMock: how to expect precisely one call with a certain argument, and see diagnostic on failure?

纵饮孤独 提交于 2019-12-06 20:45:29
Maybe a finesse question, my problem is that if I write: EXPECT_CALL(mock, handleMessage(_)).Times(0); // expectation #1 EXPECT_CALL(mock, handleMessage(Pointee(IsLike(aSpecificMessage)))); // expectation #2 ... and method handleMessage is called once, but with a different argument (not aSpecificMessage ), then the failure looks like: Mock function called more times than expected - returning default value. Function call: handleMessage(0x8b5378) Returns: false Expected: to be never called Actual: called once - over-saturated and active Google Mock doesn't print the diagnostic on why the

EasyMock : java.lang.IllegalStateException: 1 matchers expected, 2 recorded

南笙酒味 提交于 2019-12-06 17:27:54
问题 I am having a problem with EasyMock 2.5.2 and JUnit 4.8.2 (running through Eclipse). I have read all the similar posts here but have not found an answer. I have a class containing two tests which test the same method. I am using matchers. Each test passes when run alone. The first test always passes - this is true if I switch the order of the tests in the file. Here is a simplified version of the test code: private Xthing mockXthing; private MainThing mainThing; @Before public void setUp() {