matcher

Scala Spec2 Mockito: Argument matchers with complex types

余生长醉 提交于 2019-12-06 15:14:21
I'm trying to write a mock for a web service with Mockito. The mock should simulate a POST request using the play WS library. /** * Mock for the Web Service */ case class WSMock() extends Mockito { val wsRequestHolder: play.api.libs.ws.WS.WSRequestHolder = mock[play.api.libs.ws.WS.WSRequestHolder] val wsResponse: play.api.libs.ws.Response = mock[play.api.libs.ws.Response] wsResponse.status returns 200 wsResponse.body returns "BODY RESP FROM WS" val futureResponse = scala.concurrent.Future { wsResponse } wsRequestHolder.post(any[Map[String,Seq[String]]]) returns futureResponse } When running

How to Access Points location on OpenCV Matcher?

帅比萌擦擦* 提交于 2019-12-06 06:08:58
问题 I am using this FLANN matcher algorithm to match interest points in 2 pictures the code is displayed below). There is a moment when the code finds a list of matched points: std::vector<DMatch> good_matches; I would like to get the points localization (x,y) in both pictures. To create a displacement map. How could I access these points localization? Cheers, #include <stdio.h> #include <iostream> #include "opencv2/core/core.hpp" #include "opencv2/nonfree/features2d.hpp" #include "opencv2

How to terminate Matcher.find(), when its running too long?

青春壹個敷衍的年華 提交于 2019-12-05 22:47:12
问题 Wondering about techniques for terminating long running regular expression matches (java matcher.find() method). Maybe subclassing Matcher and adding some logic to terminate after x number of iterations? Basically I'm generating regular expressions using a genetic algorithm, so I don't have a lot of control over them. Then I test each one against some text to see if they match a certain target area of the text. So since I'm sort of randomly generating these regular expressions, I get some

How to use Android REGEX with Pattern and Matcher Classes?

…衆ロ難τιáo~ 提交于 2019-12-05 12:17:47
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?" By default, the . does not match line breaks. You would need to add a regex option so that it does: Pattern p = Pattern.compile(myPattern,Pattern.DOTALL); m

Is there any way to use Jasmine default matchers within custom matchers?

余生长醉 提交于 2019-12-05 03:23:20
I have a custom matcher in some Jasmine test specs of the form: this.addMatchers({ checkContains: function(elem){ var found = false; $.each( this.actual, function( actualItem ){ // Check if these objects contain the same properties. found = found || actualItem.thing == elem; }); return found; } }); Of course, actualItem.thing == elem doesn't actually compare object contents- I have to use one of the more complex solutions in Object comparison in JavaScript . I can't help but notice, though, that Jasmine already has a nice object equality checker: expect(x).toEqual(y) . Is there any way to use

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

天大地大妈咪最大 提交于 2019-12-05 02:39:33
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? 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/25351312/how-to-show-custom-failure-message-in-specs2-scala

Use variables in pattern matcher

被刻印的时光 ゝ 提交于 2019-12-05 02:09:20
I have the following: if (mobile.matches("[0-9]{6,20}")) { ... } But would like to replace the {6,20} with variable values due to them been dynamic in some cases. I.e. int minValue = 11; int maxValue = 20 if (mobile.matches("[0-9]{minValue,maxValue}")) { ... } How can I include variables in the Reg Exp? Thanks Use Java's simple string concatenation, using the plus sign. if (mobile.matches("[0-9]{" + minValue + "," + maxValue + "}")) { Indeed, as Michael suggested compiling it is better for performance if you use it a lot. Pattern pattern = Pattern.compile("[0-9]{" + minValue + "," + maxValue +

Given mixed accented and normal characters in string not working in java when searching

為{幸葍}努か 提交于 2019-12-05 02:03:48
String text = "Cámélan discovered ônte red aleŕt \n Como se extingue la deuda"; If I give the input Ca, it should highlight from the given string Cá but it's not highlighting. Below is what I tried. Pattern mPattern; String filterTerm; //this is the input which I give from input filter. Say for eg: Ca String regex = createFilterRegex(filterTerm); mPattern = Pattern.compile(regex); private String createFilterRegex(String filterTerm) { filterTerm = Normalizer.normalize(filterTerm, Normalizer.Form.NFD); filterTerm = filterTerm.replaceAll("[\\p{InCombiningDiacriticalMarks}]", ""); return

Mockito: Match any String except one [duplicate]

半世苍凉 提交于 2019-12-05 01:24:42
This question already has an answer here: How to write a matcher that is not equal to something 4 answers 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. The solution I used: argThat(not("ExceptionString")) Where argThat is a Mockito matcher, and not is a Hamcrest Matcher troig Just point that with Mockito you can also use AdditionalMatchers and ArgumentMatchers

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

蓝咒 提交于 2019-12-04 22:57:01
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() { mockXthing = EasyMock.createMock(Xthing.class); mainThing = new MainThing(); mainThing.setxThing