Questions tagged [matcher]

1

votes
1

answer
2.2k

Views

NullPointerException when working with ArgumentMatcher

I've written the following JUnit test, which uses ArgumentMatchers. MyClass classUnderTest = new MyClass(); class AnyBooleanMatcher extends ArgumentMatcher { public boolean matches(Object argument) { return ((Boolean) argument).equals(Boolean.TRUE); } } class MyObjectMatcher extends ArgumentMatcher...
0

votes
0

answer
6

Views

Is there a way to use a matcher like 'Verify' in rspec?

So far I'm using 'expect' in my test framework which will stop the execution when it meets a fail condition. I want something like, the execution should happen even if it meets the fail condition. I could see that there is a matcher called 'Verify' in rspec where I need to inherit 'Test::Unit::TestC...
esakiraja
0

votes
0

answer
26

Views

How to identify data that doesn't match pattern

So I'm using the matcher class and using it to identify tokens that i've defined in an enum. public static enum TokenType { // Definitions of accepted tokens IF("if"), WHILE("while"), PRINT("print"), TYPE("int|string|boolean"), BOOLOP("==|!="), BOOLVAL("false|true"), INTOP("[+]"), CHAR("[a-z]"), DI...
rhowell
1

votes
3

answer
38

Views

Regex matching with pattern and matches

I am reading input from file it contains set of lines as below : BDI100 172.20.1.5 YES TFTP up up BDI500 172.20.1.50 YES TFTP up up BDI600 172.20.1.58 YES TFTP up up I have to...
Ranganatha D
1

votes
1

answer
62

Views

Shoulda and RSpec's before

I try to set a instance variable in a subject before testing validity of model fields. I need to set this variable, because validation is conditional (it is used only for some type of users). So I have something like this: context "as a user" do before(:each) do subject = Organization.new subject.ed...
ciembor
1

votes
1

answer
449

Views

`::` head and tail deconstruction of a java collection in scala

I am trying to write a "deconstructor" for java collections in scala. With most scala collections, I can use the :: case class to deconstruct the collection in head/tail: scala> val (a :: b) = Seq(1,2) a: Int = 1 b: List[Int] = List(2) scala> val (a :: b :: Nil) = Seq(1,2) a: Int = 1 b: Int = 2 And...
Mortimer
1

votes
1

answer
103

Views

Simple Java regular expression matching fails

Before y'all jump on me for posting something similar to previous questions asked, yes, there seem to be a number of regex related questions but nothing which seems to help me, or at least that I can see. I am trying to parse strings in JAVA using PATTERN and MATCHER and am really having no joy. My...
Malcolm
1

votes
1

answer
284

Views

Mockito 1.9: format the expected value (like “actual formatter” in custom ArgumentMatcher)

In Mockito 1.9.5 I'd like to format the actual value when verifying the (in order) call arguments of a method. Mockito provides a overridable describeTo method within ArcgumentMatchers that enables me to format the expected value. When mocking JRE classes like DatagramPacket using PowerMockito's whe...
try-catch-finally
1

votes
1

answer
9.8k

Views

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

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 differe...
haelix
1

votes
2

answer
44

Views

How to stub a method when instance of specific object specific fields passed?

I want to return 4 when instance of Person class by [name = "Mohammad", age = 26] where called. I want to return 5 when instance of Person class by [name = "Ali", age = 20] where called. So I have these classes: public class Person { private String name; private int age; My DAO class: public class D...
Milad Khajavi
1

votes
2

answer
1.8k

Views

Java matcher.matches() returning false when it should be true

So I'm having an issue, I need to check for simple beginning and ending HTML tags in a string. The beginning tag I haven't had any problems with it is when I am trying to find the ending tag that I have issues. private Pattern pattern; private Matcher matcher; private Pattern endPattern; private Mat...
Devvy
1

votes
1

answer
2k

Views

Hamcrest Matchers contains with List of matchers

I am trying to use org.hamcrest.Matchers.contains(java.util.List
Illyes Istvan
1

votes
3

answer
92

Views

Java regex using Pattern and Matcher

I am trying to use matcher as an expression to find time stamps in my list of strings. Ex (" [00:00:00.000] ") There are white spaces before and after the time stamp I checked my regex online and it say it is correct but will not work with my java. It just returns false. String word = " [00:00:00.00...
EsotericRider
2

votes
1

answer
1.4k

Views

Mockito matcher that compares items in Set, not the Set reference itself

when(validator.isValid(Sets.newHashSet("valid"))).thenReturn(true); When validator.isValid(set) is invoked it returns false. It is because the validator implementation creates a new set that is different that the passed one (reference is different) - the items in both sets are same. I need to return...
Felix
5

votes
1

answer
3k

Views

Mock a method with an object parameter with Mockito

In my unit test i want to mock the interaction with elasticsearch by doing the following when(cityDefinitionRepository.findCitiesNearby(geoPoint, SOURCE, 2)).thenReturn(cityDefinitionsArrival); when(cityDefinitionRepository.findCitiesNearby(geoPoint2, SOURCE, 2)).thenReturn(cityDefinitionsDeparture)...
Glenn Van Schil
2

votes
2

answer
1.2k

Views

java.util.regex.Matcher.replaceAll replacing without a match?

According to the javadoc: Replaces every subsequence of the input sequence that matches the pattern with the given replacement string. This seems to indicate that this call will not replace, unless a match is made. And yet: public class MisMatch { public static void main(String args[]){ Pattern dou...
Kylar
1

votes
3

answer
1.4k

Views

ambiguous references when mixing NUnit and NMock2 matchers

We're using NUnit (2.5.9) and NMock2 for unit testing and mocking. Both, however, have a matcher syntax that closely corresponds. When I do using NUnit.Framework; using NMock2; And later on the following NMock2 code: Expect.Once.On(database).Method("Create"). With(Has.Property("id", Is.EqualTo("0123...
skrebbel
2

votes
1

answer
212

Views

Converting from Java 7 to 6, Matcher.group

I'm converting a Java 7 application to a Java 6 application. I'm stuck on the matcher.group property, since I don't really understand what it does. I have the following code: public static final String PropertyRegexPrefixGroup = "prefix"; public static final String PropertyRegexPostfixGroup = "post...
Joetjah
1

votes
1

answer
3.6k

Views

Scala Spec2 Mockito: matchers for non-primitive arguments: any, isA

I am writing a mock object like below: import org.specs2.mock._ import com...MonetaryValue import com...Voucher import org.mockito.internal.matchers._ /** * The fake voucher used as a mock object to test other components */ case class VoucherMock() extends Mockito { val voucher: Voucher = mock[Vouch...
Đỗ Ngọc Hoan
17

votes
5

answer
27k

Views

Jasmine toEqual for complex objects (mixed with functions)

Currently, I have a function that sometimes return an object with some functions inside. When using expect(...).toEqual({...}) it doesn't seem to match those complex objects. Objects having functions or the File class (from input type file), it just can't. How to overcome this?
pocesar
18

votes
1

answer
13.3k

Views

Java Pattern Matcher: create new or reset?

Assume a Regular Expression, which, via a Java Matcher object, is matched against a large number of strings: String expression = ...; // The Regular Expression Pattern pattern = Pattern.compile(expression); String[] ALL_INPUT = ...; // The large number of strings to be matched Matcher matcher; // De...
PNS
2

votes
1

answer
40

Views

java regex matcher.replaceAll with groups

I'm trying to replace one syntax with another and i'm doing this through regex expressions where I would like to replace with one pattern with another. Pattern pattern = Pattern.compile("length\\((?[a-zA-Z]+)\\)", Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(statement); if (matcher.f...
MaximV
1

votes
3

answer
365

Views

Regex pattern for string not bounded by character

I need java pattern for string not bounded by a character. I have a string (as mentioned below), with some curly brackets bounded by single quotes and other curly brackets that are not. I want to replace the curly brackets that are not bounded by single quotes, with another string. Original string:...
Jyahoo Test
18

votes
6

answer
66.1k

Views

How to extract parameters from a given url

In Java I have: String params = "depCity=PAR&roomType=D&depCity=NYC"; I want to get values of depCity parameters (PAR,NYC). So I created regex: String regex = "depCity=([^&]+)"; Pattern p = Pattern.compile(regex); Matcher m = p.matcher(params); m.find() is returning false. m.groups() is returning Il...
gospodin
2

votes
1

answer
620

Views

Hamcrest - Matchers.hasProperty: how to check if a List of objects contains an object with a concrete value

I have the following problem with Hamcrest: I have a List of Employee List employees = hamcrest.getEmployees(); where: public class Employee { private String name; private int age; private double salary; public Employee(String name, int age, double salary) { super(); this.name = name; this.age = age...
Matley
3

votes
1

answer
13.6k

Views

ABAP regex: string contains only letters

I have an input field which should accept only letters (doesn't matter lower or uppercase). I could write this simply by using co ca (contains only/any) operator. But it's time consuming. if p_input3 ca '*/ + - ? ! % ( ) = 0123456789'. MESSAGE e000 WITH 'Only letters are allowed. No numbers or speci...
kk-dev11
19

votes
7

answer
10.6k

Views

Rspec view testing with capybara and rails3

I really like the way RSpec is able to separate controller and view tests but have some problems with getting capybara matchers to work in a view test. What i basically try to achieve is sth like this: describe "some page" do it "should render with lots of stuff" do assign .. render rendered.should...
dahpgjgamgan
1

votes
2

answer
182

Views

mockito when with third party class

I need to use a third party class in Mockito.when as parameter. The class does not have equals implementation and hence Mockito.when always returns null except the case where any() is used. The below always returns null: when(obj.process(new ThirdParytClass())).thenReturn(someObj); however, this wo...
Prakash
1

votes
2

answer
46

Views

How to match any digits in front of a certain character?

I'd like to match all digits that are in front of the character K and extract that value. In the example CARRY18K it would match the 18. Probably I can only achive this with regex, but how? Is \d+K the right expression here?
membersound
1

votes
1

answer
51

Views

matcher association list lisp

Hi everyone I am new to programming and I have to work with association list like this ((course (john .math) (jim .english) (carl .biology) ) (year (john .2) (jim. 1) (carl .3)) (age (john .22) (jim .20) (carl .27)) ) I am supposed to use the matcher to work like that with a function lookup (looku...
user3005313
6

votes
1

answer
2.6k

Views

Mockito acts strangely when I assign multiple custom matchers to a single method

I'm wanting to use two custom matchers for a single method. Basically, if I pass the method VALUE_A, I want it to return RESULT_A, and if I pass it VALUE_B, I want it to return RESULT_B. So here's a code excerpt : class IsNonEmpty extends ArgumentMatcher { public boolean matches(Object get) { //Fo...
sangfroid
5

votes
3

answer
2.9k

Views

Java recursive(?) repeated(?) deep(?) pattern matching

I'm trying to get ALL the substrings in the input string that match the given pattern. For example, Given string: aaxxbbaxb Pattern: a[a-z]{0,3}b (What I actually want to express is: all the patterns that starts with a and ends with b, but can have up to 2 alphabets in between them) Exact results th...
cnc4ever
1

votes
2

answer
180

Views

Java's pattern matcher says no match found but matches are print to the console

I've written a matcher to match from the following text. xyz... Oiuye Oture, Option EUR 0.20 Foriegn EUR 0.30 The Pattern I want to use is:- Pattern p = Pattern.compile("\\\\\\(.*?)\\");Matcher m_Fee_1 = p_Fee_1.matcher(row_xml); m_Fee_1.find(); String Contract_Fee_Temp = m_Fee_1....
raka
6

votes
2

answer
5.8k

Views

Matching multiple properties in one Matcher

I need to write Matcher which will check multiple properties. For single property i've used: import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasProperty; import org.hamcrest.Matcher; import org.hamcrest.Matchers; Matcher matcherName = Matchers. hasProperty("propertyN...
Szympek
5

votes
2

answer
8.1k

Views

Mocha/Chai testing expected vs actual arrays of objects

What's the best way to assert that the expected results matches the actual results when both are arrays of objects? My immediate thought was to use Array prototype filter and check that the intersection is the same size as expected, i.e.: describe('select',function(){ it("should return selected col...
Pauli Price
6

votes
4

answer
1.7k

Views

Java Split not working as expected

I am trying to use a simple split to break up the following string: 00-00000 My expression is: ^([0-9][0-9])(-)([0-9])([0-9])([0-9])([0-9])([0-9]) And my usage is: String s = "00-00000"; String pattern = "^([0-9][0-9])(-)([0-9])([0-9])([0-9])([0-9])([0-9])"; String[] parts = s.split(pattern); If I p...
LDAdams
11

votes
3

answer
12.9k

Views

Java support for “(?<name>pattern)” in patterns [duplicate]

This question already has an answer here: Regex Named Groups in Java 6 answers I was wondering if Java had an equivalent to C#’s named pattern matching. For example, in C# I can do something like this: var pattern = @";(?\d{6});(?\d{6});"; var regex = new Regex(pattern , RegexOptions.None); var...
aelstonjones
2

votes
2

answer
81

Views

Java regular expression find substring

I'm trying to find a specific word into a string in Java. I developed a function aims to return the found string. THis is what I wrotte for now: public static String getValueByregexExpr (String str, String regexExpr) { Pattern regex = Pattern.compile (regexExpr, Pattern.DOTALL); Matcher matcher1 = r...
loic
1

votes
1

answer
638

Views

Spec2: Getting second parameter argument passed into the mocked method invocation

I have a mocked service which takes 3 parameters. How do I access second argument? mockedService.invoke(arg1, arg2, arg3) answers { (params, mock) => { //Do something with params.arg2 to the value that is returned from the invocation } } In the documentation, they states "the array of the method par...
duser
3

votes
3

answer
572

Views

Assert List<List<String>> contains List<String> with no order

I have a List with sample data like: ("T1#R1", "T1#R1", "T1#R3", "T1#R4") ("T1#R1", "T1#R1", "T1#R3", "T1#R5") ("T1#R1", "T1#R1", "T1#R6", "T1#R4") ("T1#R1", "T1#R1", "T1#R6", "T1#R5") And I need to assert, that a List is present in the above sample, but without taking order into consideration. For...
Manuel S.

View additional questions