How to use hasItem method of org.hamcrest.core.IsCollectionContaining class

Best junit code snippet using org.hamcrest.core.IsCollectionContaining.hasItem

Source:BooleanToCheckBoxOptionIT.java Github

copy

Full Screen

...33 putDataAsSourceForMailMerge(data).34 produceDocument(resultFile);35 36 assertTrue(result.isSuccess());37 assertThat(result.getFiles(), org.hamcrest.core.IsCollectionContaining.hasItem(resultFile));38 }39 40 @Test41 public void default_True_mergeFieldValue_notDisplayedAsCheckBox() {42 File resultFile = makeFile("test/documentTemplate/checkBox/default_true_not_displayed_as_checkbox.pdf");43 44 Person data = makePerson();45 data.acceptToBeContacted(true);46 47 FileOperationMessage result = documentTemplate.48 putDataAsSourceForMailMerge(data).49 produceDocument(resultFile);50 51 assertTrue(result.isSuccess());52 assertThat(result.getFiles(), org.hamcrest.core.IsCollectionContaining.hasItem(resultFile));53 }54 55 @Test56 public void false_mergeFieldValue_displayed_as_unselectedCheckBox_output_pdf() {57 File resultFile = makeFile("test/documentTemplate/checkBox/false_displayed_as_unselected_checkbox.pdf");58 59 Person data = makePerson();60 data.acceptToBeContacted(false);61 62 FileOperationMessage result = documentTemplate.63 putDataAsSourceForMailMerge(data).64 withDocumentCreationOptions(DocumentCreationOptions.getInstance().displayBooleanValuesAsCheckBox(true)).65 produceDocument(resultFile);66 67 assertTrue(result.isSuccess());68 assertThat(result.getFiles(), org.hamcrest.core.IsCollectionContaining.hasItem(resultFile));69 }70 71 @Test72 public void true_mergeFieldValue_displayed_as_selectedCheckBox_output_pdf() {73 File resultFile = makeFile("test/documentTemplate/checkBox/true_displayed_as_selected_checkbox.pdf");74 75 Person data = makePerson();76 data.acceptToBeContacted(true);77 78 FileOperationMessage result = documentTemplate.79 putDataAsSourceForMailMerge(data).80 withDocumentCreationOptions(DocumentCreationOptions.getInstance().displayBooleanValuesAsCheckBox(true)).81 produceDocument(resultFile);82 83 assertTrue(result.isSuccess());84 assertThat(result.getFiles(), org.hamcrest.core.IsCollectionContaining.hasItem(resultFile));85 }86 87 @Test88 public void false_mergeFieldValue_displayed_as_unselectedCheckBox_output_doc() {89 File resultFile = makeFile("test/documentTemplate/checkBox/false_displayed_as_unselected_checkbox.doc");90 91 Person data = makePerson();92 data.acceptToBeContacted(false);93 94 FileOperationMessage result = documentTemplate.95 putDataAsSourceForMailMerge(data).96 withDocumentCreationOptions(DocumentCreationOptions.getInstance().displayBooleanValuesAsCheckBox(true)).97 produceDocument(resultFile);98 99 assertTrue(result.isSuccess());100 assertThat(result.getFiles(), org.hamcrest.core.IsCollectionContaining.hasItem(resultFile));101 }102 103 @Test104 public void true_mergeFieldValue_displayed_as_selectedCheckBox_output_doc() {105 File resultFile = makeFile("test/documentTemplate/checkBox/true_displayed_as_selected_checkbox.doc");106 107 Person data = makePerson();108 data.acceptToBeContacted(true);109 110 FileOperationMessage result = documentTemplate.111 putDataAsSourceForMailMerge(data).112 withDocumentCreationOptions(DocumentCreationOptions.getInstance().displayBooleanValuesAsCheckBox(true)).113 produceDocument(resultFile);114 115 assertTrue(result.isSuccess());116 assertThat(result.getFiles(), org.hamcrest.core.IsCollectionContaining.hasItem(resultFile));117 }118 119 @Test120 public void false_mergeFieldValue_displayed_as_unselectedCheckBox_output_docx() {121 File resultFile = makeFile("test/documentTemplate/checkBox/false_displayed_as_unselected_checkbox.docx");122 123 Person data = makePerson();124 data.acceptToBeContacted(false);125 126 FileOperationMessage result = documentTemplate.127 putDataAsSourceForMailMerge(data).128 withDocumentCreationOptions(DocumentCreationOptions.getInstance().displayBooleanValuesAsCheckBox(true)).129 produceDocument(resultFile);130 131 assertTrue(result.isSuccess());132 assertThat(result.getFiles(), org.hamcrest.core.IsCollectionContaining.hasItem(resultFile));133 }134 135 @Test136 public void true_mergeFieldValue_displayed_as_selectedCheckBox_output_docx() {137 File resultFile = makeFile("test/documentTemplate/checkBox/true_displayed_as_selected_checkbox.docx");138 139 Person data = makePerson();140 data.acceptToBeContacted(true);141 142 FileOperationMessage result = documentTemplate.143 putDataAsSourceForMailMerge(data).144 withDocumentCreationOptions(DocumentCreationOptions.getInstance().displayBooleanValuesAsCheckBox(true)).145 produceDocument(resultFile);146 147 assertTrue(result.isSuccess());148 assertThat(result.getFiles(), org.hamcrest.core.IsCollectionContaining.hasItem(resultFile));149 }150 151 @Test152 public void false_mergeFieldValue_displayed_as_unselectedCheckBox_output_odt() {153 File resultFile = makeFile("test/documentTemplate/checkBox/false_displayed_as_unselected_checkbox.odt");154 155 Person data = makePerson();156 data.acceptToBeContacted(false);157 158 FileOperationMessage result = documentTemplate.159 putDataAsSourceForMailMerge(data).160 withDocumentCreationOptions(DocumentCreationOptions.getInstance().displayBooleanValuesAsCheckBox(true)).161 produceDocument(resultFile);162 163 assertTrue(result.isSuccess());164 assertThat(result.getFiles(), org.hamcrest.core.IsCollectionContaining.hasItem(resultFile));165 }166 167 @Test168 public void true_mergeFieldValue_displayed_as_selectedCheckBox_output_odt() {169 File resultFile = makeFile("test/documentTemplate/checkBox/true_displayed_as_selected_checkbox.odt");170 171 Person data = makePerson();172 data.acceptToBeContacted(true);173 174 FileOperationMessage result = documentTemplate.175 putDataAsSourceForMailMerge(data).176 withDocumentCreationOptions(DocumentCreationOptions.getInstance().displayBooleanValuesAsCheckBox(true)).177 produceDocument(resultFile);178 179 assertTrue(result.isSuccess());180 assertThat(result.getFiles(), org.hamcrest.core.IsCollectionContaining.hasItem(resultFile));181 }182 183 @Test184 public void false_mergeFieldValue_not_displayed_as_checkbox_in_txt() {185 File resultFile = makeFile("test/documentTemplate/checkBox/false_not_displayed_as_unselected_checkbox.txt");186 187 Person data = makePerson();188 data.acceptToBeContacted(false);189 190 FileOperationMessage result = documentTemplate.191 putDataAsSourceForMailMerge(data).192 withDocumentCreationOptions(DocumentCreationOptions.getInstance().displayBooleanValuesAsCheckBox(true)).193 produceDocument(resultFile);194 195 assertTrue(result.isSuccess());196 assertThat(result.getFiles(), org.hamcrest.core.IsCollectionContaining.hasItem(resultFile));197 }198 199 @Test200 public void true_mergeFieldValue_not_displayed_as_checkbox_in_txt() {201 File resultFile = makeFile("test/documentTemplate/checkBox/true_not_displayed_as_selected_checkbox.txt");202 203 Person data = makePerson();204 data.acceptToBeContacted(true);205 206 FileOperationMessage result = documentTemplate.207 putDataAsSourceForMailMerge(data).208 withDocumentCreationOptions(DocumentCreationOptions.getInstance().displayBooleanValuesAsCheckBox(true)).209 produceDocument(resultFile);210 211 assertTrue(result.isSuccess());212 assertThat(result.getFiles(), org.hamcrest.core.IsCollectionContaining.hasItem(resultFile));213 }214 215 @Test216 public void false_mergeFieldValue_displayed_as_unselectedCheckBox_output_html() {217 File resultFile = makeFile("test/documentTemplate/checkBox/false_displayed_as_unselected_checkbox.html");218 219 Person data = makePerson();220 data.acceptToBeContacted(false);221 222 FileOperationMessage result = documentTemplate.223 putDataAsSourceForMailMerge(data).224 withDocumentCreationOptions(DocumentCreationOptions.getInstance().displayBooleanValuesAsCheckBox(true)).225 produceDocument(resultFile);226 227 assertTrue(result.isSuccess());228 assertThat(result.getFiles(), org.hamcrest.core.IsCollectionContaining.hasItem(resultFile));229 }230 231 @Test232 public void true_mergeFieldValue_displayed_as_selectedCheckBox_output_html() {233 File resultFile = makeFile("test/documentTemplate/checkBox/true_displayed_as_selected_checkbox.html");234 235 Person data = makePerson();236 data.acceptToBeContacted(true);237 238 FileOperationMessage result = documentTemplate.239 putDataAsSourceForMailMerge(data).240 withDocumentCreationOptions(DocumentCreationOptions.getInstance().displayBooleanValuesAsCheckBox(true)).241 produceDocument(resultFile);242 243 assertTrue(result.isSuccess());244 assertThat(result.getFiles(), org.hamcrest.core.IsCollectionContaining.hasItem(resultFile));245 }246}...

Full Screen

Full Screen

Source:RemovingWhiteSpaceInPdfEditableFieldsIT.java Github

copy

Full Screen

...30 31 FileOperationMessage result = documentTemplate.produceDocument(resultFile);32 33 assertTrue(result.isSuccess());34 assertThat(result.getFiles(), org.hamcrest.core.IsCollectionContaining.hasItem(resultFile));35 }36 37 @Test38 public void removeWhiteSpaceInPdfEditableFields() {39 documentTemplate.withDocumentCreationOptions(40 DocumentCreationOptions.getInstance()41 .keepFormFieldsEditableInPdf(true)42 .removeWhiteSpaceInPdfEditableFields(true)43 );44 45 File resultFile = makeFile("test/documentTemplate/removingWhiteSpaceInPdfEditableFieldsIT/remove_fieldSpaces.pdf");46 47 FileOperationMessage result = documentTemplate.produceDocument(resultFile);48 49 assertTrue(result.isSuccess());50 assertThat(result.getFiles(), org.hamcrest.core.IsCollectionContaining.hasItem(resultFile));51 }52 53 @Test54 public void removeWhiteSpaceInPdfEditableFields_has_no_effect_if_fieldsNotEditable() {55 documentTemplate.withDocumentCreationOptions(56 DocumentCreationOptions.getInstance()57 .keepFormFieldsEditableInPdf(false)58 .removeWhiteSpaceInPdfEditableFields(true)59 );60 61 File resultFile = makeFile("test/documentTemplate/removingWhiteSpaceInPdfEditableFieldsIT/fieldsNotEditables.pdf");62 63 FileOperationMessage result = documentTemplate.produceDocument(resultFile);64 65 assertTrue(result.isSuccess());66 assertThat(result.getFiles(), org.hamcrest.core.IsCollectionContaining.hasItem(resultFile));67 }68 69 @Test70 public void removeWhiteSpaceInPdfEditableFields_has_no_effect_if_output_is_doc() {71 documentTemplate.withDocumentCreationOptions(72 DocumentCreationOptions.getInstance()73 .keepFormFieldsEditableInPdf(true)74 .removeWhiteSpaceInPdfEditableFields(true)75 );76 77 File resultFile = makeFile("test/documentTemplate/removingWhiteSpaceInPdfEditableFieldsIT/aDoc.doc");78 79 FileOperationMessage result = documentTemplate.produceDocument(resultFile);80 81 assertTrue(result.isSuccess());82 assertThat(result.getFiles(), org.hamcrest.core.IsCollectionContaining.hasItem(resultFile));83 }84 85 @Test86 public void removeWhiteSpaceInPdfEditableFields_has_no_effect_if_output_is_docx() {87 documentTemplate.withDocumentCreationOptions(88 DocumentCreationOptions.getInstance()89 .keepFormFieldsEditableInPdf(true)90 .removeWhiteSpaceInPdfEditableFields(true)91 );92 93 File resultFile = makeFile("test/documentTemplate/removingWhiteSpaceInPdfEditableFieldsIT/aDocx.docx");94 95 FileOperationMessage result = documentTemplate.produceDocument(resultFile);96 97 assertTrue(result.isSuccess());98 assertThat(result.getFiles(), org.hamcrest.core.IsCollectionContaining.hasItem(resultFile));99 }100 101 @Test102 public void removeWhiteSpaceInPdfEditableFields_has_no_effect_if_output_is_odt() {103 documentTemplate.withDocumentCreationOptions(104 DocumentCreationOptions.getInstance()105 .keepFormFieldsEditableInPdf(true)106 .removeWhiteSpaceInPdfEditableFields(true)107 );108 109 File resultFile = makeFile("test/documentTemplate/removingWhiteSpaceInPdfEditableFieldsIT/anOdt.odt");110 111 FileOperationMessage result = documentTemplate.produceDocument(resultFile);112 113 assertTrue(result.isSuccess());114 assertThat(result.getFiles(), org.hamcrest.core.IsCollectionContaining.hasItem(resultFile));115 }116 117 @Test118 public void removeWhiteSpaceInPdfEditableFields_has_no_effect_if_output_is_html() {119 documentTemplate.withDocumentCreationOptions(120 DocumentCreationOptions.getInstance()121 .keepFormFieldsEditableInPdf(true)122 .removeWhiteSpaceInPdfEditableFields(true)123 );124 125 File resultFile = makeFile("test/documentTemplate/removingWhiteSpaceInPdfEditableFieldsIT/anHtml.html");126 127 FileOperationMessage result = documentTemplate.produceDocument(resultFile);128 129 assertTrue(result.isSuccess());130 assertThat(result.getFiles(), org.hamcrest.core.IsCollectionContaining.hasItem(resultFile));131 }132 133 @Test134 public void removeWhiteSpaceInPdfEditableFields_has_no_effect_if_output_is_txt() {135 documentTemplate.withDocumentCreationOptions(136 DocumentCreationOptions.getInstance()137 .keepFormFieldsEditableInPdf(true)138 .removeWhiteSpaceInPdfEditableFields(true)139 );140 141 File resultFile = makeFile("test/documentTemplate/removingWhiteSpaceInPdfEditableFieldsIT/aTxt.txt");142 143 FileOperationMessage result = documentTemplate.produceDocument(resultFile);144 145 assertTrue(result.isSuccess());146 assertThat(result.getFiles(), org.hamcrest.core.IsCollectionContaining.hasItem(resultFile));147 }148}...

Full Screen

Full Screen

Source:CoreMatchers.java Github

copy

Full Screen

...60 }61 public static Matcher<Object> anything(String description) {62 return IsAnything.anything(description);63 }64 public static <T> Matcher<Iterable<? super T>> hasItem(Matcher<? super T> itemMatcher) {65 return IsCollectionContaining.hasItem((Matcher) itemMatcher);66 }67 public static <T> Matcher<Iterable<? super T>> hasItem(T item) {68 return IsCollectionContaining.hasItem((Object) item);69 }70 @SafeVarargs71 public static <T> Matcher<Iterable<T>> hasItems(Matcher<? super T>... itemMatchers) {72 return IsCollectionContaining.hasItems((Matcher[]) itemMatchers);73 }74 @SafeVarargs75 public static <T> Matcher<Iterable<T>> hasItems(T... items) {76 return IsCollectionContaining.hasItems((Object[]) items);77 }78 public static <T> Matcher<T> equalTo(T operand) {79 return IsEqual.equalTo(operand);80 }81 public static Matcher<Object> equalToObject(Object operand) {82 return IsEqual.equalToObject(operand);83 }84 public static <T> Matcher<T> any(Class<T> type) {85 return IsInstanceOf.any(type);86 }87 public static <T> Matcher<T> instanceOf(Class<?> type) {88 return IsInstanceOf.instanceOf(type);89 }90 public static <T> Matcher<T> not(Matcher<T> matcher) {...

Full Screen

Full Screen

Source:RemoveBlankPagesIT.java Github

copy

Full Screen

...29 putDataAsSourceForMailMerge(makePerson()).30 produceDocument(resultFile);31 32 assertTrue(result.isSuccess());33 assertThat(result.getFiles(), org.hamcrest.core.IsCollectionContaining.hasItem(resultFile));34 }35 36 @Test37 public void default_not_remove_blank_pages_docx() {38 File resultFile = makeFile("test/documentTemplate/blankPages/default_not_remove_blank_pages.docx");39 40 FileOperationMessage result = documentTemplate.41 putDataAsSourceForMailMerge(makePerson()).42 produceDocument(resultFile);43 44 assertTrue(result.isSuccess());45 assertThat(result.getFiles(), org.hamcrest.core.IsCollectionContaining.hasItem(resultFile));46 }47 48 @Test49 public void default_not_remove_blank_pages_doc() {50 File resultFile = makeFile("test/documentTemplate/blankPages/default_not_remove_blank_pages.doc");51 52 FileOperationMessage result = documentTemplate.53 putDataAsSourceForMailMerge(makePerson()).54 produceDocument(resultFile);55 56 assertTrue(result.isSuccess());57 assertThat(result.getFiles(), org.hamcrest.core.IsCollectionContaining.hasItem(resultFile));58 }59 60 @Test61 public void default_not_remove_blank_pages_odt() {62 File resultFile = makeFile("test/documentTemplate/blankPages/default_not_remove_blank_pages.odt");63 64 FileOperationMessage result = documentTemplate.65 putDataAsSourceForMailMerge(makePerson()).66 produceDocument(resultFile);67 68 assertTrue(result.isSuccess());69 assertThat(result.getFiles(), org.hamcrest.core.IsCollectionContaining.hasItem(resultFile));70 }71 72 @Test73 public void remove_blank_pages_pdf() {74 File resultFile = makeFile("test/documentTemplate/blankPages/remove_blank_pages.pdf");75 76 DocumentCreationOptions documentCreationOptions = DocumentCreationOptions.getInstance().removeBlankPages(true);77 78 FileOperationMessage result = documentTemplate.79 withDocumentCreationOptions(documentCreationOptions).80 putDataAsSourceForMailMerge(makePerson()).81 produceDocument(resultFile);82 83 assertTrue(result.isSuccess());84 assertThat(result.getFiles(), org.hamcrest.core.IsCollectionContaining.hasItem(resultFile));85 }86 87 @Test88 public void remove_blank_pages_docx() {89 File resultFile = makeFile("test/documentTemplate/blankPages/remove_blank_pages.docx");90 91 DocumentCreationOptions documentCreationOptions = DocumentCreationOptions.getInstance().removeBlankPages(true);92 93 FileOperationMessage result = documentTemplate.94 withDocumentCreationOptions(documentCreationOptions).95 putDataAsSourceForMailMerge(makePerson()).96 produceDocument(resultFile);97 98 assertTrue(result.isSuccess());99 assertThat(result.getFiles(), org.hamcrest.core.IsCollectionContaining.hasItem(resultFile));100 }101 102 @Test103 public void remove_blank_pages_doc() {104 File resultFile = makeFile("test/documentTemplate/blankPages/remove_blank_pages.doc");105 106 DocumentCreationOptions documentCreationOptions = DocumentCreationOptions.getInstance().removeBlankPages(true);107 108 FileOperationMessage result = documentTemplate.109 withDocumentCreationOptions(documentCreationOptions).110 putDataAsSourceForMailMerge(makePerson()).111 produceDocument(resultFile);112 113 assertTrue(result.isSuccess());114 assertThat(result.getFiles(), org.hamcrest.core.IsCollectionContaining.hasItem(resultFile));115 }116 117 @Test118 public void remove_blank_pages_odt() {119 File resultFile = makeFile("test/documentTemplate/blankPages/remove_blank_pages.odt");120 121 DocumentCreationOptions documentCreationOptions = DocumentCreationOptions.getInstance().removeBlankPages(true);122 123 FileOperationMessage result = documentTemplate.124 withDocumentCreationOptions(documentCreationOptions).125 putDataAsSourceForMailMerge(makePerson()).126 produceDocument(resultFile);127 128 assertTrue(result.isSuccess());129 assertThat(result.getFiles(), org.hamcrest.core.IsCollectionContaining.hasItem(resultFile));130 }131}...

Full Screen

Full Screen

Source:IsCollectionContainingTest.java Github

copy

Full Screen

...7import java.util.HashSet;8import java.util.Set;9import static java.util.Arrays.asList;10import static org.hamcrest.AbstractMatcherTest.*;11import static org.hamcrest.core.IsCollectionContaining.hasItem;12import static org.hamcrest.core.IsCollectionContaining.hasItems;13import static org.hamcrest.core.IsEqual.equalTo;14public final class IsCollectionContainingTest {15 16 @Test public void17 copesWithNullsAndUnknownTypes() {18 Matcher<?> matcher = hasItem(equalTo("irrelevant"));19 20 assertNullSafe(matcher);21 assertUnknownTypeSafe(matcher);22 }23 @Test public void24 matchesACollectionThatContainsAnElementForTheGivenMatcher() {25 final Matcher<Iterable<? super String>> itemMatcher = hasItem(equalTo("a"));26 assertMatches("list containing 'a'", itemMatcher, asList("a", "b", "c"));27 }28 @Test public void29 doesNotMatchCollectionWithoutAnElementForGivenMatcher() {30 final Matcher<Iterable<? super String>> matcher = hasItem(mismatchable("a"));31 32 assertMismatchDescription("mismatches were: [mismatched: b, mismatched: c]", matcher, asList("b", "c"));33 assertMismatchDescription("was empty", matcher, new ArrayList<String>());34 }35 @Test public void36 doesNotMatchNull() {37 assertDoesNotMatch("doesn't match null", hasItem(equalTo("a")), null);38 }39 @Test public void40 hasAReadableDescription() {41 assertDescription("a collection containing mismatchable: a", hasItem(mismatchable("a")));42 }43 44 @Test public void45 canMatchItemWhenCollectionHoldsSuperclass() { // Issue 2446 final Set<Number> s = new HashSet<Number>();47 s.add(2);48 assertMatches(new IsCollectionContaining<Number>(new IsEqual<Number>(2)), s);49 assertMatches(IsCollectionContaining.hasItem(2), s);50 }51 @SuppressWarnings("unchecked")52 @Test public void53 matchesMultipleItemsInCollection() {54 final Matcher<Iterable<String>> matcher1 = hasItems(equalTo("a"), equalTo("b"), equalTo("c"));55 assertMatches("list containing all items", matcher1, asList("a", "b", "c"));56 57 final Matcher<Iterable<String>> matcher2 = hasItems("a", "b", "c");58 assertMatches("list containing all items (without matchers)", matcher2, asList("a", "b", "c"));59 60 final Matcher<Iterable<String>> matcher3 = hasItems(equalTo("a"), equalTo("b"), equalTo("c"));61 assertMatches("list containing all items in any order", matcher3, asList("c", "b", "a"));62 63 final Matcher<Iterable<String>> matcher4 = hasItems(equalTo("a"), equalTo("b"), equalTo("c"));64 assertMatches("list containing all items plus others", matcher4, asList("e", "c", "b", "a", "d"));65 66 final Matcher<Iterable<String>> matcher5 = hasItems(equalTo("a"), equalTo("b"), equalTo("c"));67 assertDoesNotMatch("not match list unless it contains all items", matcher5, asList("e", "c", "b", "d")); // 'a' missing68 }69 70 @Test public void71 reportsMismatchWithAReadableDescriptionForMultipleItems() {72 final Matcher<Iterable<Integer>> matcher = hasItems(3, 4);73 74 assertMismatchDescription("a collection containing <4> mismatches were: [was <1>, was <2>, was <3>]",75 matcher, asList(1, 2, 3));76 }77 private static Matcher<? super String> mismatchable(final String string) {78 return new TypeSafeDiagnosingMatcher<String>() {79 @Override80 protected boolean matchesSafely(String item, Description mismatchDescription) {81 if (string.equals(item)) 82 return true;83 mismatchDescription.appendText("mismatched: " + item);84 return false;85 }86 @Override...

Full Screen

Full Screen

Source:DocumentTemplateFormatsGenerationIT.java Github

copy

Full Screen

...30 31 FileOperationMessage result = documentTemplate.produceDocument(resultFile);32 assertNotNull(result);33 assertTrue(result.isSuccess());34 assertThat(result.getFiles(), org.hamcrest.core.IsCollectionContaining.hasItem(resultFile));35 }36 37 @Test38 public void produceDocument_doc() throws URISyntaxException {39 documentTemplate.setOutputFormat("doc");40 File resultFile = makeFile("test/documentTemplate/formats/simple_mail_merge_test.doc");41 42 FileOperationMessage result = documentTemplate.produceDocument(resultFile);43 assertNotNull(result);44 assertTrue(result.isSuccess());45 assertThat(result.getFiles(), org.hamcrest.core.IsCollectionContaining.hasItem(resultFile));46 }47 48 @Test49 public void produceDocument_docx() throws URISyntaxException {50 documentTemplate.setOutputFormat("docx");51 File resultFile = makeFile("test/documentTemplate/formats/simple_mail_merge_test.docx");52 53 FileOperationMessage result = documentTemplate.produceDocument(resultFile);54 assertNotNull(result);55 assertTrue(result.isSuccess());56 assertThat(result.getFiles(), org.hamcrest.core.IsCollectionContaining.hasItem(resultFile));57 }58 59 @Test60 public void produceDocument_odt() throws URISyntaxException {61 documentTemplate.setOutputFormat("odt");62 File resultFile = makeFile("test/documentTemplate/formats/simple_mail_merge_test.odt");63 64 FileOperationMessage result = documentTemplate.produceDocument(resultFile);65 assertNotNull(result);66 assertTrue(result.isSuccess());67 assertThat(result.getFiles(), org.hamcrest.core.IsCollectionContaining.hasItem(resultFile));68 }69 70 @Test71 public void produceDocument_txt() throws URISyntaxException {72 documentTemplate.setOutputFormat("txt");73 File resultFile = makeFile("test/documentTemplate/formats/simple_mail_merge_test.txt");74 75 FileOperationMessage result = documentTemplate.produceDocument(resultFile);76 assertNotNull(result);77 assertTrue(result.isSuccess());78 assertThat(result.getFiles(), org.hamcrest.core.IsCollectionContaining.hasItem(resultFile));79 }80 81 @Test82 public void produceDocument_pdf() throws URISyntaxException {83 documentTemplate.setOutputFormat("pdf");84 File resultFile = makeFile("test/documentTemplate/formats/simple_mail_merge_test.pdf");85 86 FileOperationMessage result = documentTemplate.produceDocument(resultFile);87 assertNotNull(result);88 assertTrue(result.isSuccess());89 assertThat(result.getFiles(), org.hamcrest.core.IsCollectionContaining.hasItem(resultFile));90 }91}...

Full Screen

Full Screen

Source:IsCollectionContaining.java Github

copy

Full Screen

...32 .appendText("a collection containing ")33 .appendDescriptionOf(elementMatcher);34 }35 @Factory36 public static <T> Matcher<Iterable<? super T>> hasItem(Matcher<? super T> elementMatcher) {37 return new IsCollectionContaining<T>(elementMatcher);38 }39 @Factory40 public static <T> Matcher<Iterable<? super T>> hasItem(T element) {41 // Doesn't forward to hasItem() method so compiler can sort out generics.42 return new IsCollectionContaining<T>(equalTo(element));43 }44 @Factory45 public static <T> Matcher<Iterable<T>> hasItems(Matcher<? super T>... elementMatchers) {46 List<Matcher<? super Iterable<T>>> all = new ArrayList<Matcher<? super Iterable<T>>>(elementMatchers.length);47 48 for (Matcher<? super T> elementMatcher : elementMatchers) {49 // Doesn't forward to hasItem() method so compiler can sort out generics.50 all.add(new IsCollectionContaining<T>(elementMatcher));51 }52 53 return allOf(all);54 }55 56 @Factory57 public static <T> Matcher<Iterable<T>> hasItems(T... elements) {58 List<Matcher<? super Iterable<T>>> all = new ArrayList<Matcher<? super Iterable<T>>>(elements.length);59 for (T element : elements) {60 all.add(hasItem(element));61 }62 63 return allOf(all);64 }65}...

Full Screen

Full Screen

hasItem

Using AI Code Generation

copy

Full Screen

1import static org.hamcrest.MatcherAssert.assertThat2import static org.hamcrest.Matchers.hasItem3import static org.hamcrest.Matchers.hasItems4assertThat list, hasItem(3)5assertThat list, hasItems(3, 5)6import static org.hamcrest.MatcherAssert.assertThat7import static org.hamcrest.Matchers.contains8import static org.hamcrest.Matchers.containsInAnyOrder9assertThat list, contains(1, 2, 3, 4, 5)10assertThat list, containsInAnyOrder(5, 4, 3, 2, 1)11import static org.hamcrest.MatcherAssert.assertThat12import static org.hamcrest.Matchers.containsInAnyOrder13assertThat list, containsInAnyOrder(5, 4, 3, 2, 1)14import static org.hamcrest.MatcherAssert.assertThat15import static org.hamcrest.Matchers.containsInRelativeOrder16assertThat list, containsInRelativeOrder(1, 2, 3, 4, 5)17import static org.hamcrest.MatcherAssert.assertThat18import static org.hamcrest.Matchers.containsInRelativeOrder19assertThat list, containsInRelativeOrder(1, 2, 3,

Full Screen

Full Screen

hasItem

Using AI Code Generation

copy

Full Screen

1import static org.hamcrest.MatcherAssert.assertThat2import static org.hamcrest.Matchers.hasItem3import static org.hamcrest.Matchers.hasItems4assertThat list, hasItems(1, 2, 3, 4, 5)5assertThat list, hasItem(1)6import static org.hamcrest.MatcherAssert.assertThat7import static org.hamcrest.Matchers.containsInAnyOrder8assertThat list, containsInAnyOrder(5, 4, 3, 2, 1)9assertThat list, containsInAnyOrder(1, 2, 3, 4, 5)10import static org.hamcrest.MatcherAssert.assertThat11import static org.hamcrest.Matchers.containsInRelativeOrder12assertThat list, containsInRelativeOrder(1, 2, 3, 4, 5)13assertThat list, containsInRelativeOrder(1, 2, 3)14import static org.hamcrest.MatcherAssert.assertThat15import static org.hamcrest.Matchers.containsInRelativeOrder16assertThat list, containsInRelativeOrder(1, 2, 3, 4, 5)17assertThat list, containsInRelativeOrder(1, 2, 3)18import static org.hamcrest.MatcherAssert.assertThat19import static org.hamcrest.Matchers.containsInRelativeOrder20assertThat list, containsInRelativeOrder(1, 2, 3, 4, 5)21assertThat list, containsInRelativeOrder(1, 2, 3)22import static org.hamcrest.MatcherAssert.assertThat23import static org

Full Screen

Full Screen

hasItem

Using AI Code Generation

copy

Full Screen

1import static org.hamcrest.MatcherAssert.assertThat2import static org.hamcrest.Matchers.hasItem3import static org.hamcrest.Matchers.hasItems4assertThat list, hasItem(3)5assertThat list, hasItems(3,5)6assertThat list, hasItem(6)7assertThat list, hasItems(3,6)

Full Screen

Full Screen

hasItem

Using AI Code Generation

copy

Full Screen

1assertThat(list, hasItem("b"));2assertThat(list, hasItems("b", "c"));3assertThat(list, hasItems("b", "c", "d"));4assertThat(list, contains("a", "b", "c"));5assertThat(list, contains("a", "b", "c", "d"));6assertThat(list, contains("a", "b", "c", "d", "e"));7assertThat(list, containsInAnyOrder("a", "b", "c"));8assertThat(list, containsInAnyOrder("a", "b", "c", "d"));9assertThat(list, containsInAnyOrder("a", "b", "c", "d", "e"));10assertThat(list, containsInRelativeOrder("a", "b", "c"));11assertThat(list, containsInRelativeOrder("a", "b", "c", "d"));12assertThat(list, containsInRelativeOrder("a", "b", "c", "d", "e"));13assertThat(list, hasItemInArray("b"));14assertThat(list, hasItemsInArray("b", "c"));15assertThat(list, hasItemsInArray("b", "c", "d"));16assertThat(list, hasItem(equalTo("b")));17assertThat(list, hasItems(equalTo("b"), equalTo("c")));18assertThat(list, hasItems(equalTo("b"), equalTo("c"), equalTo("d")));19assertThat(list, hasItem(is("b")));20assertThat(list, hasItems(is("b"), is("c")));21assertThat(list, hasItems(is("b"), is("c"), is("d")));22assertThat(list, hasItem(Matchers.equalTo("b")));23assertThat(list, hasItems(Matchers.equalTo("b"), Matchers.equalTo("c")));24assertThat(list, hasItems(Matchers.equalTo("b"), Matchers.equalTo("c"), Matchers.equalTo("d")));25assertThat(list, hasItem(Matchers.is("b")));26assertThat(list, hasItems(Matchers.is("b"), Matchers.is("c")));27assertThat(list, hasItems(Matchers.is("b"), Matchers.is("c"), Matchers.is("d")));28assertThat(list, hasItem(Matchers.<String>equalTo("b")));29assertThat(list, hasItems(Matchers.<String>equalTo("b"), Matchers.<String>equalTo("c")));

Full Screen

Full Screen

hasItem

Using AI Code Generation

copy

Full Screen

1import static org.hamcrest.MatcherAssert.assertThat;2import static org.hamcrest.Matchers.hasItem;3import java.util.Arrays;4import java.util.List;5public class HasItemExample {6 public static void main(String[] args) {7 List<String> list = Arrays.asList("one", "two", "three", "four");8 assertThat(list, hasItem("one"));9 }10}

Full Screen

Full Screen

hasItem

Using AI Code Generation

copy

Full Screen

1import org.hamcrest.core.IsCollectionContaining2assert list.hasItem("two")3assert !list.hasItem("four")4import org.hamcrest.core.IsCollectionContaining5assert list.hasItem("two")6assert !list.hasItem("four")

Full Screen

Full Screen

hasItem

Using AI Code Generation

copy

Full Screen

1import org.hamcrest.CoreMatchers2import org.hamcrest.CoreMatchers.containsString3import groovy.json.JsonOutput4import static org.hamcrest.MatcherAssert.assertThat5import static org.hamcrest.Matchers.*6def json = JsonOutput.toJson([7def jsonSlurper = new JsonSlurper()8def jsonParsed = jsonSlurper.parseText(json)9assertThat jsonParsed.name, is("John Smith")10assertThat jsonParsed.age, is(25)11assertThat jsonParsed.address.street, containsString("123")12assertThat jsonParsed.phoneNumbers[0].type, is("home")13assertThat jsonParsed.phoneNumbers[1].type, is("fax")14assertThat jsonParsed.phoneNumbers, hasItem(allOf(hasEntry("type", "home"), hasEntry("number", "123-456-7890")))15assertThat jsonParsed.phoneNumbers, hasItem(allOf(hasEntry("type", "fax"), hasEntry("number", "123-456-7891")))16assertThat jsonParsed.phoneNumbers, hasItem(hasEntry("type", "home"))17assertThat jsonParsed.phoneNumbers, hasItem(hasEntry("type", "fax"))18assertThat jsonParsed.phoneNumbers, hasItem(hasEntry("number", "123-456-7890"))19assertThat jsonParsed.phoneNumbers, hasItem(hasEntry("number", "123-456-7891"))20assertThat jsonParsed.phoneNumbers, hasItem(hasEntry("type", "home"))21assertThat jsonParsed.phoneNumbers, hasItem(hasEntry("number", "123-456-7890"))22assertThat jsonParsed.phoneNumbers, hasItem(hasEntry("type", "fax"))23assertThat jsonParsed.phoneNumbers, hasItem(hasEntry("number", "123-456-7891

Full Screen

Full Screen

JUnit Tutorial:

LambdaTest also has a detailed JUnit tutorial explaining its features, importance, advanced use cases, best practices, and more to help you get started with running your automation testing scripts.

JUnit Tutorial Chapters:

Here are the detailed JUnit testing chapters to help you get started:

  • Importance of Unit testing - Learn why Unit testing is essential during the development phase to identify bugs and errors.
  • Top Java Unit testing frameworks - Here are the upcoming JUnit automation testing frameworks that you can use in 2023 to boost your unit testing.
  • What is the JUnit framework
  • Why is JUnit testing important - Learn the importance and numerous benefits of using the JUnit testing framework.
  • Features of JUnit - Learn about the numerous features of JUnit and why developers prefer it.
  • JUnit 5 vs. JUnit 4: Differences - Here is a complete comparison between JUnit 5 and JUnit 4 testing frameworks.
  • Setting up the JUnit environment - Learn how to set up your JUnit testing environment.
  • Getting started with JUnit testing - After successfully setting up your JUnit environment, this chapter will help you get started with JUnit testing in no time.
  • Parallel testing with JUnit - Parallel Testing can be used to reduce test execution time and improve test efficiency. Learn how to perform parallel testing with JUnit.
  • Annotations in JUnit - When writing automation scripts with JUnit, we can use JUnit annotations to specify the type of methods in our test code. This helps us identify those methods when we run JUnit tests using Selenium WebDriver. Learn in detail what annotations are in JUnit.
  • Assertions in JUnit - Assertions are used to validate or test that the result of an action/functionality is the same as expected. Learn in detail what assertions are and how to use them while performing JUnit testing.
  • Parameterization in JUnit - Parameterized Test enables you to run the same automated test scripts with different variables. By collecting data on each method's test parameters, you can minimize time spent on writing tests. Learn how to use parameterization in JUnit.
  • Nested Tests In JUnit 5 - A nested class is a non-static class contained within another class in a hierarchical structure. It can share the state and setup of the outer class. Learn about nested annotations in JUnit 5 with examples.
  • Best practices for JUnit testing - Learn about the best practices, such as always testing key methods and classes, integrating JUnit tests with your build, and more to get the best possible results.
  • Advanced Use Cases for JUnit testing - Take a deep dive into the advanced use cases, such as how to run JUnit tests in Jupiter, how to use JUnit 5 Mockito for Unit testing, and more for JUnit testing.

JUnit Certification:

You can also check out our JUnit certification if you wish to take your career in Selenium automation testing with JUnit to the next level.

Run junit automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in IsCollectionContaining

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful