AssertJ + verify items returned in subList contains string as will be present in any of the list items - assertj

I have requirement, say in my response I get the results in list as "brisbane, australia", "sydney, australia" and "melbourne, australia". Now I need to test that, the results contains "sydney" in any of the three results.
softAssertions.assertThat(resultArrayList.subList(0, 3))
.extracting("title")
.as("Title match")
.containsAny(expectedTitle);
Kindly suggest.

This can be done with allSatisfy.
softAssertions.assertThat(resultArrayList.subList(0, 3))
.extracting("title")
.as("Title match")
// assuming titles are String, use contains String assertion
.allSatisfy(cities -> cities.contains("sydney"));

Related

How I can read List from last item to the first Item

I need to flip list to be able to read that list from last item to first
ex : list[a,b,c,d]
I want to get that list as [d,c,b,a];
anyone have Idea how to do that ?
You can use reversed.
An example,
List<String> list = ["a", "b", "c"];
list = list.reversed.toList();
print(list); // Result [c, b, a]
Document of reversed
/**
* Returns an [Iterable] of the objects in this list in reverse order.
*/
Iterable<E> get reversed;

Search Array with depending order

I got a question regarding filtering an array.
Let's assume I got an array of country names:
let countries = [Albania, Bahrain, Barbados, Denmark, France, Zimbabwe]
now I want to filter this array to check if it contains a certain String let say "ba".
I can do this easily with
countries = countries.filter{ $0.contains("ba")}
which returns
Albania, Bahrain, Barbados, Zimbabwe
But I actually want the order of letters to matter. Therefore, the result "Albania" and "Zimbabwe" should not appear and only "Bahrain" and "Barbados" as their name starts with an Ba.
Is there any way to do this to avoid a huge for loop going through all entites checking individually for each character?
Use .hasPrefix instead of .contains, like this:
print(countries.filter{ $0.hasPrefix("Ba") })
Note that this is case sensitive. BTW, in your example, the problem was not missing order of letters but the fact that .contains respects case as do most methods in swift.
You can take care of the case and the filtering in one step:
let countries = ["Albania", "Bahrain", "Barbados", "Denmark", "France", "Zimbabwe"]
let filtered = countries.filter { $0.lowercased().hasPrefix("ba") } // -> ["Bahrain", "Barbados"]
This lowercases the country names before applying the filter's test, but doesn't change the original array, so the results have the same case.
This is important because you might incorrectly want to do this in two steps for readability:
countries
.map { $0.lowercased()}
.filter { $0.hasPrefix("ba")}
But this returns ["bahrain", "barbados"] because the filter is being applied to the now lowercased array.

I would like to store the values in array list after iterating the select options , is it possible in Watir

I am trying to store the values of select list in an array variable
a = b.options.each {|option| puts option.attribute_value "value" }
Output :
IN PROGRESS
UPCOMING
FINAL
POSTPONED
CANCELLED
a.to_i
Is it possible to store all values which getting from attribute and store in An array
The element collections in Watir include the Enumerable module, which gives a lot of useful methods for iterating. In particular, it includes a map method that will perform a block on each element and collect the result in an array.
To store the value of all options, you can simply do:
total_list_values = #browser.options.map(&:value)
#=> ["IN PROGRESS", "UPCOMING", "FINAL", "POSTPONED", "CANCELLED"]
I coded it like this and its worked, posted if anyone wanted this
total_list_values = Array.new
body = #browser.options
body.options.each do |option|
total_list_values << option.value
end

Querying a list item through UniqueId

I'm trying to get a list item through its Unique Id through REST API end point for list items.
URL
https://{site-collection}/{personal-site}/_api/Web/Lists(guid'id')/items?$filter=UniqueId eq 'uniqueid'
But it isn't returning the item, instead it returns an empty list;
Result
{
"d": {
"results": []
}
}
When I make a similar query using ItemId or GUID, it works fine but for UniqueId I'm getting an empty list. Is this even possible? If not then why have a UniqueId, can't GUID/ItemId suffice? One possible explanation could be that it is the UniqueId that is referenced in other lists not GUID or ItemID.
So why can't I filter an item with UniqueId?
If anyone else comes stumbling upon this thread, then the answer is
_api/Web/Lists('GUID')/GetItemByUniqueId('GUID')
:)

How to get records with specific IDs?

I can easily get record with specific ID. If I need something specific then I can use CKQueryOperation.
I need to provide it with proper predicate, but I can't specify IDs as parameter of predicate, because it doesn't support CKRecordValue protocol. Another idea is to use CKReference, but how to write proper predicate then?
If I try to use array of Strings and evaluate agains recordID.recordName key path:
var references:[String] = IDs.map{$0.recordName}
var predicate = NSPredicate(format: "ANY recordID.recordName IN %#", references)
I get following error:
<CKError 0x17005f3b0: "Invalid Arguments" (12/1009); "Invalid predicate: recordKey (recordID.recordName) contains invalid characters">
Predicate format output:
predicate ANY recordID.recordName IN {"AFF487BE-4A7E-4F76-8185-79FA2E1EFC33", "D4D83B37-97DE-4BF2-9E43-4C5522E36DF1", "0126008A-0B42-4F95-AB31-BB13B6215475", "6DE83AD9-F307-467D-A5EF-AD2B97B8E7F7", "F701ADBF-9BE7-4F42-8CA9-44D2D0E629F8", "38C4FB60-8A65-43F9-8E1E-4C48D5B60DCD"}
Any help is appreciated.
You can use a CKFetchRecordsOperation to fetch records whose RecordIDs you already know:
let fetchRecordsOperation = CKFetchRecordsOperation(recordIDs: recordIDs)
fetchRecordsOperation.desiredKeys = desiredKeys
Init the operation with an array of the CKRecordIDs you'd like to retrieve and it will return each individual record result in the perRecordCompletionBlock and all records fetched in fetchRecordsCompletionBlock.
You can retrieve the complete records by default or just a subset of their values by setting an array of NSStrings to the desiredKeys property with the names of the fields you'd like to retrieve.