java.util.IllegalFormatFlagsException: Flags = '' - PullRequest
0 голосов
/ 31 декабря 2018

Для сравнения я использую совпадения Hamcrest 2 list<String>

List<String> oldProductNames = (List<String>) ConfigurationManager.getBundle()
            .getProperty("productName");

Reporter.log("Unsorted Product Name : " + oldProductNames);
Collections.sort(oldProductNames);
Reporter.log("Sorted Product Name : " + oldProductNames);

List<String> sortedList = getAllProductNamesFromListing("excludeOOS");
Reporter.log("Sorted By Web Site : " + sortedList);

assertThat(oldProductNames, contains(sortedList.toArray()));

Вывод выглядит следующим образом:

Несортированное название продукта: [nehatestbundlenew2, nehatestbundlenew, beurre de cacahuètes 100% naturel, гриль beurre d'amandes 1 кг, гриль beurre de noix de cajou 1 кг, орехи о сыворотке ™, beurre de noisettes 1 кг, beurre de cacahuètes aux 4 graines, грибы beurre de noisettes грили с шоколадным соусом, beurre de pistache grill1 кг, гриль beurre d'amandes au chocolat noir, beurre d'amandes - noisettes - cajou, beurre de cacahuète à la noix de coco]


Сортированное название продукта: [beurre d'amandes - noisettes - cajou, грили beurre d'amandes 1 кг, грили beurre d'amandes с шоколадом нуар, beacre de cacahuète по-французски, beurre de cacahuètes 100% натуральный, beurre de cacahuètes bede noisettes 1 кг, гриль beurre de noisettes гриль с шоколадом нуар, beurre de noix de cajou грили 1 кг, гриль beurre de pistachees 1 кг, nehatestbundlenew, nehatestbundlenew2, орехи о молочной сыворотке ™]


Сортировано по веб-сайту: [beurre d'amandes - noisettes - cajou, beurre d'amandes grillées 1 кг, beurre d'amandes grillées au chocolat noir, beacre de cacahuète по-французски, beurre de cacahuètes 100% натуральный, beurre de cacahuètes aux 4 зерна, beurre de noisettes 1 кг, beurre de noisettes grillées aure choé noé de be be chocolatгриль де кейджу 1 кг, филе фисташкового мяса 1 кг, самое дорогое, свежее, орехи о сыворотке ™]

но ниже ошибка для assertThat(oldProductNames, contains(sortedList.toArray()));

java.util.IllegalFormatFlagsException: Flags = ''

1 Ответ

0 голосов
/ 31 декабря 2018

При использовании assertThat(oldProductNames, contains(sortedList.toArray()));
Вы следуете этому шаблону assertThat(actual, contains(expected));

oldProductNames содержит % знаков, и при передаче его в метод assertThat вы фактически передаете спецификатор форматаin.

В результате этого java.util.IllegalFormatFlagsException сразу же space выбирается после указанного спецификатора формата в качестве ведущего пробела, вызывающего это исключение.

...