How to use containsString method of org.hamcrest.core.StringContains class

Best junit code snippet using org.hamcrest.core.StringContains.containsString

Source:SkipPropsTest.java Github

copy

Full Screen

...65 yaml = new Yaml(new AnnotationAwareRepresenter());66 props.setNotLoadedButDumped("notLoadedButDumped");67 String dumped = yaml.dumpAsMap(props);68 System.out.println(yaml.dumpAsMap(props));69 assertThat(dumped, StringContains.containsString("loadedAndDumped: loadedAndDumped"));70 assertThat(dumped, StringContains.containsString("notLoadedButDumped: notLoadedButDumped"));71 assertThat(dumped, IsNot.not(StringContains.containsString("notDumped")));72 }73 }74 /**75 * Tests {@link YamlProperty#skipAtDump()}.76 * 77 * @throws Exception on exception78 */79 @Test80 public void checkPropertyNotDumped() throws Exception {81 String notDumped = "mustNotBeDumped";82 SkipProps skipProps = new SkipProps();83 skipProps.setSkipDump(notDumped);84 skipProps.setName("name1");85 skipProps.setSkipLoad("skipLoad1");86 Yaml yaml = new Yaml(new AnnotationAwareRepresenter(false));87 String dumped = yaml.dumpAsMap(skipProps);88 System.out.println(dumped);89 assertThat(dumped, IsNot.not(StringContains.containsString(notDumped)));90 assertThat(dumped, StringContains.containsString("name1"));91 assertThat(dumped, StringContains.containsString("skipLoad1"));92 }93 /**94 * Tests {@link YamlProperty#skipAtDump()} overrides {@link YamlProperty#skipAtDumpIf()}.95 * 96 * @throws Exception on exception97 */98 @Test99 public void checkPropertyNotDumpedOverringPredicate() throws Exception {100 String notDumped = "mustNotBeDumped";101 SkipProps skipProps = new SkipProps();102 skipProps.setSkipDump(notDumped);103 skipProps.setName("name1");104 skipProps.setSkipDumpOverridingIf(notDumped);105 Yaml yaml = new Yaml(new AnnotationAwareRepresenter(false));106 String dumped = yaml.dumpAsMap(skipProps);107 System.out.println(dumped);108 assertThat(dumped, IsNot.not(StringContains.containsString(notDumped)));109 assertThat(dumped, StringContains.containsString("name1"));110 }111 /**112 * Verifies that a property is not dumped if its value is <code>null</code> and annotated appropriately.113 * 114 * @throws Exception on any exception115 */116 @Test117 public void checkPropertyNotDumpedIfNull() throws Exception {118 String notDumped = "mustNotBeDumped";119 SkipProps skipProps = new SkipProps();120 skipProps.setSkipDump(notDumped);121 skipProps.setName("name1");122 Yaml yaml = new Yaml(new AnnotationAwareRepresenter(false));123 String dumped = yaml.dumpAsMap(skipProps);124 System.out.println(dumped);125 assertThat(dumped, IsNot.not(StringContains.containsString("skipDumpIfNull")));126 assertThat(dumped, StringContains.containsString("name1"));127 skipProps.setSkipDumpIfNull("MUSTBEDUMPED");128 dumped = yaml.dumpAsMap(skipProps);129 assertThat(dumped, StringContains.containsString("MUSTBEDUMPED"));130 assertThat(dumped, StringContains.containsString("name1"));131 }132 /**133 * Verifies that a property is not dumped if its value is an empty String and annotated appropriately.134 * 135 * @throws Exception on any exception136 */137 @Test138 public void checkPropertyNotDumpedIfEmpty() throws Exception {139 SkipProps skipProps = new SkipProps();140 skipProps.setSkipDumpIfEmpty("");141 skipProps.setName("name1");142 Yaml yaml = new Yaml(new AnnotationAwareRepresenter(false));143 String dumped = yaml.dumpAsMap(skipProps);144 System.out.println(dumped);145 assertThat(dumped, IsNot.not(StringContains.containsString("skipDumpIfEmpty")));146 assertThat(dumped, StringContains.containsString("name1"));147 skipProps.setSkipDumpIfEmpty("MUSTBEDUMPED");148 dumped = yaml.dumpAsMap(skipProps);149 System.out.println(dumped);150 assertThat(dumped, StringContains.containsString("MUSTBEDUMPED"));151 assertThat(dumped, StringContains.containsString("name1"));152 }153 /**154 * Verifies that a property is not dumped if its value is an empty collection and annotated appropriately.155 * 156 * @throws Exception on any exception157 */158 @Test159 public void checkPropertyNotDumpedIfCollectionEmpty() throws Exception {160 String notDumped = "mustNotBeDumped";161 SkipProps skipProps = new SkipProps();162 skipProps.setSkipDump(notDumped);163 skipProps.setName("name1");164 Yaml yaml = new Yaml(new AnnotationAwareRepresenter(false));165 String dumped = yaml.dumpAsMap(skipProps);166 System.out.println(dumped);167 assertThat(dumped, IsNot.not(StringContains.containsString("skipDumpIfEmptyCollection")));168 assertThat(dumped, StringContains.containsString("name1"));169 skipProps.setSkipDumpIfEmptyCollection(Arrays.asList("MUSTBEDUMPED"));170 dumped = yaml.dumpAsMap(skipProps);171 System.out.println(dumped);172 assertThat(dumped, StringContains.containsString("MUSTBEDUMPED"));173 assertThat(dumped, StringContains.containsString("name1"));174 }175 /**176 * Verifies that a property is not dumped if its value is an empty map and annotated appropriately.177 * 178 * @throws Exception on any exception179 */180 @Test181 public void checkPropertyNotDumpedIfMapEmpty() throws Exception {182 String notDumped = "mustNotBeDumped";183 SkipProps skipProps = new SkipProps();184 skipProps.setSkipDump(notDumped);185 skipProps.setName("name1");186 Yaml yaml = new Yaml(new AnnotationAwareRepresenter(false));187 String dumped = yaml.dumpAsMap(skipProps);188 System.out.println(dumped);189 assertThat(dumped, IsNot.not(StringContains.containsString("skipDumpIfEmptyMap")));190 assertThat(dumped, StringContains.containsString("name1"));191 Map<String, Object> map = new HashMap<>();192 map.put("1", "MUSTBEDUMPED");193 skipProps.setSkipDumpIfEmptyMap(map);194 dumped = yaml.dumpAsMap(skipProps);195 System.out.println(dumped);196 assertThat(dumped, StringContains.containsString("MUSTBEDUMPED"));197 assertThat(dumped, StringContains.containsString("1"));198 assertThat(dumped, StringContains.containsString("name1"));199 }200 /**201 * Verifies that a property is dumped if it is not empty and of type other than List, Map or String.202 * 203 * @throws Exception on any exception204 */205 @Test206 public void checkPropertyDumpedIfOtherTypeNotEmpty() throws Exception {207 String notDumped = "mustNotBeDumped";208 SkipProps skipProps = new SkipProps();209 skipProps.setSkipDump(notDumped);210 skipProps.setName("name1");211 Yaml yaml = new Yaml(new AnnotationAwareRepresenter(false));212 String dumped = yaml.dumpAsMap(skipProps);213 System.out.println(dumped);214 assertThat(dumped, StringContains.containsString("name1"));215 assertThat(dumped, StringContains.containsString("skipDumpOtherType"));216 }217 /**218 * Verifies that an exception is thrown if a predicate class cannot be instantiated.219 * 220 * @throws Exception yaml exception221 */222 @Test223 public void checkPropertyDumpedIfBadClass() throws Exception {224 SkipPropsBadClass skipProps = new SkipPropsBadClass();225 Yaml yaml = new Yaml(new AnnotationAwareRepresenter(false));226 assertThrows(YAMLException.class, () -> yaml.dumpAsMap(skipProps));227 }228 // CHECKSTYLE:OFF229 public static class SkipProps {...

Full Screen

Full Screen

Source:CacheConfigurationTest.java Github

copy

Full Screen

...18import java.util.logging.Logger;19import static org.hamcrest.CoreMatchers.equalTo;20import static org.hamcrest.CoreMatchers.is;21import static org.hamcrest.CoreMatchers.nullValue;22import static org.hamcrest.core.StringContains.containsString;23import static org.junit.Assert.assertEquals;24import static org.junit.Assert.assertThat;25import static org.junit.Assert.fail;26import static org.junit.Assume.assumeNotNull;27/**28 * @author Alex Snaps29 */30@Category(CheckShorts.class)31public class CacheConfigurationTest {32 private static CacheManager cacheManager;33 @BeforeClass34 public static void setupClass() {35 Configuration configTestCM = new Configuration().name("configTestCM")36 .diskStore(new DiskStoreConfiguration().path("java.io.tmpdir"));37 cacheManager = CacheManager.newInstance(configTestCM);38 }39 @AfterClass40 public static void tearDownClass() {41 cacheManager.shutdown();42 }43 @Test44 public void testTransactionalMode() {45 CacheConfiguration configuration = new CacheConfiguration();46 assertEquals(CacheConfiguration.TransactionalMode.OFF, configuration.getTransactionalMode());47 try {48 configuration.setTransactionalMode(null);49 fail("expected IllegalArgumentException");50 } catch (IllegalArgumentException e) {51 // expected52 }53 configuration.setTransactionalMode("local");54 assertEquals(CacheConfiguration.TransactionalMode.LOCAL, configuration.getTransactionalMode());55 try {56 configuration.transactionalMode(CacheConfiguration.TransactionalMode.OFF);57 fail("expected InvalidConfigurationException");58 } catch (InvalidConfigurationException e) {59 // expected60 }61 try {62 configuration.setTransactionalMode(null);63 fail("expected IllegalArgumentException");64 } catch (IllegalArgumentException e) {65 // expected66 }67 CacheConfiguration clone = configuration.clone();68 assertEquals(CacheConfiguration.TransactionalMode.LOCAL, clone.getTransactionalMode());69 try {70 clone.transactionalMode(CacheConfiguration.TransactionalMode.XA);71 fail("expected InvalidConfigurationException");72 } catch (InvalidConfigurationException e) {73 // expected74 }75 }76 @Test77 public void testReadPercentageProperly() {78 CacheConfiguration configuration = new CacheConfiguration();79 assertThat(configuration.getMaxBytesLocalOffHeapPercentage(), nullValue());80 configuration.setMaxBytesLocalOffHeap("12%");81 assertThat(configuration.getMaxBytesLocalOffHeapPercentage(), equalTo(12));82 configuration.setMaxBytesLocalOffHeap("99%");83 assertThat(configuration.getMaxBytesLocalOffHeapPercentage(), equalTo(99));84 configuration.setMaxBytesLocalOffHeap("100%");85 assertThat(configuration.getMaxBytesLocalOffHeapPercentage(), equalTo(100));86 configuration.setMaxBytesLocalOffHeap("0%");87 assertThat(configuration.getMaxBytesLocalOffHeapPercentage(), equalTo(0));88 try {89 configuration.setMaxBytesLocalOffHeap("101%");90 fail("This should throw an IllegalArgumentException, 101% is above 100%");91 } catch (IllegalArgumentException e) {92 // Expected93 }94 try {95 configuration.setMaxBytesLocalOffHeap("-10%");96 fail("This should throw an IllegalArgumentException, -10% is below 0%");97 } catch (IllegalArgumentException e) {98 // Expected99 }100 }101 @Test102 public void testCanSetBothMaxWhenCacheNotRunning() {103 CacheConfiguration configuration = new CacheConfiguration();104 configuration.setMaxEntriesLocalHeap(10);105 configuration.maxBytesLocalHeap(10, MemoryUnit.MEGABYTES);106 configuration.setMaxEntriesLocalDisk(10);107 configuration.maxBytesLocalDisk(10, MemoryUnit.MEGABYTES);108 }109 @Test110 public void testMaxMemoryOffHeap() {111 CacheConfiguration configuration = new CacheConfiguration();112 configuration.setMaxMemoryOffHeap("100m");113 assertEquals("100m", configuration.getMaxMemoryOffHeap());114 configuration.setMaxBytesLocalOffHeap("1G");115 assertEquals("1G", configuration.getMaxMemoryOffHeap());116 }117 @Test118 public void testMaxEntriesLocalDiskAndMaxElementsOnDiskAlias() {119 CacheConfiguration configuration = new CacheConfiguration().maxElementsOnDisk(10);120 assertThat(configuration.getMaxEntriesLocalDisk(), is(10L));121 assertThat(configuration.getMaxElementsOnDisk(), is(10));122 configuration.maxEntriesLocalDisk(20);123 assertThat(configuration.getMaxEntriesLocalDisk(), is(20L));124 assertThat(configuration.getMaxElementsOnDisk(), is(20));125 }126 @Test127 public void testCantSetMaxEntriesLocalDiskWhenClustered() {128 CacheConfiguration configuration = new CacheConfiguration("Test", 10)129 .maxEntriesLocalDisk(10).terracotta(new TerracottaConfiguration());130 try {131 configuration.setupFor(cacheManager);132 fail("This should throw InvalidConfigurationException");133 } catch (CacheException e) {134 assertThat(e.getMessage(), containsString("use maxEntriesInCache instead"));135 }136 }137 @Test138 public void testSynchronousWritesPersistenceConfiguration() {139 CacheConfiguration configuration = new CacheConfiguration("Test", 10).persistence(new PersistenceConfiguration()140 .strategy(Strategy.LOCALTEMPSWAP).synchronousWrites(true));141 try {142 cacheManager.addCache(new Cache(configuration));143 fail("Expected InvalidConfigurationException");144 } catch (InvalidConfigurationException e) {145 assertThat(e.getMessage(), containsString("synchronousWrites"));146 } finally {147 cacheManager.removeCache("Test");148 }149 configuration = new CacheConfiguration("Test", 10).persistence(new PersistenceConfiguration()150 .strategy(Strategy.NONE).synchronousWrites(true));151 try {152 cacheManager.addCache(new Cache(configuration));153 fail("Expected InvalidConfigurationException");154 } catch (InvalidConfigurationException e) {155 assertThat(e.getMessage(), containsString("synchronousWrites"));156 } finally {157 cacheManager.removeCache("Test");158 }159 configuration = new CacheConfiguration("Test", 10).persistence(new PersistenceConfiguration()160 .strategy(Strategy.LOCALRESTARTABLE).synchronousWrites(true));161 try {162 cacheManager.addCache(new Cache(configuration));163 fail("Expected CacheException");164 } catch (CacheException e) {165 assertThat(e.getMessage(), containsString("enterprise"));166 } finally {167 cacheManager.removeCache("Test");168 }169 }170 @Test171 public void testPersistenceConfigMixing() {172 CacheConfiguration persistence = new CacheConfiguration().persistence(new PersistenceConfiguration().strategy(Strategy.LOCALTEMPSWAP));173 try {174 persistence.diskPersistent(true);175 Assert.fail();176 } catch (InvalidConfigurationException e) {177 Assert.assertThat(e.getMessage(), StringContains.containsString("<persistence ...> and diskPersistent"));178 }179 try {180 persistence.overflowToDisk(true);181 Assert.fail();182 } catch (InvalidConfigurationException e) {183 Assert.assertThat(e.getMessage(), StringContains.containsString("<persistence ...> and overflowToDisk"));184 }185 CacheConfiguration diskPersistent = new CacheConfiguration().diskPersistent(true);186 try {187 diskPersistent.persistence(new PersistenceConfiguration().strategy(Strategy.LOCALTEMPSWAP));188 Assert.fail();189 } catch (InvalidConfigurationException e) {190 Assert.assertThat(e.getMessage(), StringContains.containsString("<persistence ...> and diskPersistent"));191 }192 CacheConfiguration overflowToDisk = new CacheConfiguration().overflowToDisk(true);193 try {194 overflowToDisk.persistence(new PersistenceConfiguration().strategy(Strategy.LOCALTEMPSWAP));195 Assert.fail();196 } catch (InvalidConfigurationException e) {197 Assert.assertThat(e.getMessage(), StringContains.containsString("<persistence ...> and overflowToDisk"));198 }199 }200 @Test201 public void testNoPersistenceStrategySet() {202 CacheConfiguration config = new CacheConfiguration().name("foo").persistence(new PersistenceConfiguration()).maxBytesLocalHeap(1, MemoryUnit.MEGABYTES);203 try {204 cacheManager.addCache(new Cache(config));205 Assert.fail();206 } catch (InvalidConfigurationException e) {207 Assert.assertThat(e.getMessage(), StringContains.containsString("Persistence configuration found with no strategy set."));208 }209 }210 @Test211 public void testMaxEntriesInCacheNotClustered() {212 CacheConfiguration config = new CacheConfiguration().name("foo").maxEntriesInCache(100).maxBytesLocalHeap(1, MemoryUnit.MEGABYTES);213 try {214 cacheManager.addCache(new Cache(config));215 Assert.fail();216 } catch (InvalidConfigurationException e) {217 Assert.assertThat(e.getMessage(), StringContains.containsString("maxEntriesInCache is not applicable to unclustered caches."));218 }219 }220 @Test221 public void testMaxEntriesInCacheBounds() {222 try {223 new CacheConfiguration().maxEntriesInCache(-1);224 } catch (IllegalArgumentException e) {225 assertThat(e.getMessage(), CoreMatchers.containsString("maxEntriesInCache"));226 }227 }228 @Test229 public void testWarnTieredSizing() {230 final AtomicReference<String> ref = new AtomicReference<String>();231 try {232 Class.forName("org.slf4j.impl.JDK14LoggerFactory");233 } catch (ClassNotFoundException e) {234 fail("Could not load org.slf4j.impl.JDK14LoggerFactory, required for test to work. Is slf4j-jdk14 in test dependencies?");235 }236 LogManager logManager = LogManager.getLogManager();237 Logger logger = logManager.getLogger(CacheConfiguration.class.getName());238 assumeNotNull(logger);239 logger.addHandler(new Handler() {240 @Override241 public void publish(LogRecord record) {242 ref.set(record.getMessage());243 }244 @Override245 public void flush() {246 // ignore247 }248 @Override249 public void close() throws SecurityException {250 // ignore251 }252 });253 CacheConfiguration cacheConfiguration = new CacheConfiguration();254 cacheConfiguration.setName("HeapBiggerThanDisk");255 cacheConfiguration.setOverflowToDisk(true);256 cacheConfiguration.setMaxEntriesLocalHeap(10L);257 cacheConfiguration.setMaxEntriesLocalDisk(5L);258 cacheManager.addCache(new Cache(cacheConfiguration));259 assertThat(ref.get(), CoreMatchers.containsString("Configuration problem for cache HeapBiggerThanDisk:"));260 }261}...

Full Screen

Full Screen

Source:LambdaHandlerInviteCandidateTest.java Github

copy

Full Screen

...89import java.io.IOException;10import java.util.List;1112import static org.hamcrest.CoreMatchers.containsString;13import static org.hamcrest.MatcherAssert.assertThat;14import static org.hamcrest.core.Is.is;15import static org.hamcrest.core.IsEqual.equalTo;16import static org.mockito.ArgumentMatchers.anyString;17import static org.mockito.ArgumentMatchers.eq;18import static org.mockito.Mockito.*;19import static org.mockito.internal.verification.VerificationModeFactory.atLeast;2021/**22 * Created by achang on 10/17/2018.23 */24public class LambdaHandlerInviteCandidateTest {2526 private Invitation buildValidFulltimeInvitation()27 {28 Invitation i = spy(Invitation.class);29 i.setCandidateFirstName("Fulltime");30 i.setCandidateLastName("Candidate");31 i.setCandidateEmail("candidate@fulltime.com");32 i.setManagerEmail("manager@symantec.com");33 i.setType(Invitation.Type.FULL_TIME);3435 return i;36 }3738 private Invitation buildInvalidFulltimeInvitation()39 {40 Invitation i = spy(Invitation.class);41 i.setCandidateFirstName("Fulltime");42 i.setCandidateLastName("Candidate");43 i.setCandidateEmail("candidate@fulltime.com");44 i.setManagerEmail("invalidemail");45 i.setType(Invitation.Type.FULL_TIME);4647 return i;48 }4950 @Test51 public void handleRequest_validInvitation_validated()52 {53 Invitation invite = buildValidFulltimeInvitation();5455 ICodingProblemBuilder builder = new FakeS3CodingProblemBuilder();56 IOcpV2DB db = mock(DynamoOcpV2DB.class);57 IEmailer emailer = mock(SESEmailHelper.class);5859 LambdaHandlerInviteCandidate lambda =60 new LambdaHandlerInviteCandidate(db, builder, emailer);6162 lambda.handleRequest(invite, null);6364 verify(invite, atLeast(1)).validate();65 }6667 @Test68 public void handleRequest_validInvitation_problemBuilt() throws IOException69 {70 Invitation i = buildValidFulltimeInvitation();7172 ICodingProblemBuilder builder = spy(FakeS3CodingProblemBuilder.class);73 IOcpV2DB db = mock(DynamoOcpV2DB.class);74 IEmailer emailer = mock(SESEmailHelper.class);7576 LambdaHandlerInviteCandidate lambda =77 new LambdaHandlerInviteCandidate(db, builder, emailer);7879 lambda.handleRequest(i, null);8081 verify(builder, atLeast(1)).buildCodingProblem();82 }8384 @Test85 public void handleRequest_validInvitation_candidateEmailed() throws IOException86 {87 Invitation i = buildValidFulltimeInvitation();8889 FakeS3CodingProblemBuilder builder = spy(FakeS3CodingProblemBuilder.class);90 IOcpV2DB db = mock(DynamoOcpV2DB.class);91 IEmailer emailer = mock(SESEmailHelper.class);9293 LambdaHandlerInviteCandidate lambda =94 new LambdaHandlerInviteCandidate(db, builder, emailer);9596 lambda.handleRequest(i, null);9798 ArgumentCaptor<String> emailText = ArgumentCaptor.forClass(String.class);99 verify(emailer, atLeast(1)).sendEmail(eq(i.getCandidateEmail()), anyString(), emailText.capture());100 List<String> capturedEmailBodies = emailText.getAllValues();101 assertThat(capturedEmailBodies.get(0),102 containsString(builder.getLastCodingProblemBuilt().getLandingPageUrl()));103 }104105 @Test106 public void handleRequest_validInvitation_managerEmailed() throws IOException107 {108 Invitation invite = buildValidFulltimeInvitation();109110 FakeS3CodingProblemBuilder builder = spy(FakeS3CodingProblemBuilder.class);111 IOcpV2DB db = mock(DynamoOcpV2DB.class);112 IEmailer emailer = mock(SESEmailHelper.class);113114 LambdaHandlerInviteCandidate lambda =115 new LambdaHandlerInviteCandidate(db, builder, emailer);116117 lambda.handleRequest(invite, null);118119 ArgumentCaptor<String> emailBodyTextCaptor = ArgumentCaptor.forClass(String.class);120 ArgumentCaptor<String> emailSubjectCaptor = ArgumentCaptor.forClass(String.class);121122 verify(emailer, times(2)).sendEmail(anyString(), emailSubjectCaptor.capture(), emailBodyTextCaptor.capture());123124 //check email contains candidate details125 List<String> capturedEmailSubjects = emailSubjectCaptor.getAllValues();126 String managerEmailSubject = capturedEmailSubjects.get(1); //manager email sent second127 assertThat(managerEmailSubject, StringContains.containsString(invite.getCandidateFirstName()));128 assertThat(managerEmailSubject, StringContains.containsString(invite.getCandidateLastName()));129 assertThat(managerEmailSubject, StringContains.containsString(invite.getCandidateEmail()));130131 //check email contains problem details132 CodingProblem cp = builder.getLastCodingProblemBuilt();133 List<String> capturedEmailBodies = emailBodyTextCaptor.getAllValues();134 String managerEmailBody = capturedEmailBodies.get(1); //manager email sent second135 assertThat(managerEmailBody,136 StringContains.containsString(cp.getLandingPageUrl()));137 assertThat(managerEmailBody,138 StringContains.containsString(cp.getName()));139 assertThat(managerEmailBody,140 StringContains.containsString(cp.getGuid()));141 }142143 @Test144 public void handleRequest_invalidInvitation_400()145 {146 Invitation invite = buildInvalidFulltimeInvitation();147148 ICodingProblemBuilder builder = new FakeS3CodingProblemBuilder();149 IOcpV2DB db = mock(DynamoOcpV2DB.class);150 IEmailer emailer = mock(SESEmailHelper.class);151152 LambdaHandlerInviteCandidate lambda =153 new LambdaHandlerInviteCandidate(db, builder, emailer);154 ...

Full Screen

Full Screen

Source:SkipEmptyTest.java Github

copy

Full Screen

...21 SkipEmptyProps skipEmptyProps = new SkipEmptyProps();22 AnnotationAwareRepresenter representer = new AnnotationAwareRepresenter(false);23 Yaml yaml = new Yaml(new Constructor(), representer);24 String dumped = yaml.dump(skipEmptyProps);25 assertThat(dumped, IsNot.not(StringContains.containsString("notDumped")));26 assertThat(dumped, StringContains.containsString("Homer"));27 assertThat(dumped, StringContains.containsString("collection: []"));28 assertThat(dumped, StringContains.containsString("map: null"));29 assertThat(dumped, StringContains.containsString("emptyString:"));30 assertThat(dumped, StringContains.containsString("nullString: null"));31 }32 @Test33 public void skipEmptyTrueTest() {34 SkipEmptyProps skipEmptyProps = new SkipEmptyProps();35 AnnotationAwareRepresenter representer = new AnnotationAwareRepresenter();36 Yaml yaml = new Yaml(new Constructor(), representer);37 String dumped = yaml.dump(skipEmptyProps);38 assertThat(dumped, IsNot.not(StringContains.containsString("notDumped")));39 assertThat(dumped, StringContains.containsString("Homer"));40 assertThat(dumped, IsNot.not(StringContains.containsString("collection:")));41 assertThat(dumped, IsNot.not(StringContains.containsString("map:")));42 assertThat(dumped, IsNot.not(StringContains.containsString("emptyString:")));43 assertThat(dumped, IsNot.not(StringContains.containsString("nullString:")));44 }45 // CHECKSTYLE:OFF46 public static class SkipEmptyProps {47 private String skipDump = "notDumped";48 private Collection<String> collection = new ArrayList<>();49 private Map<String, Object> map;50 private String name = "Homer";51 private String emptyString = "";52 private String nullString;53 @YamlProperty(skipAtDump = true)54 public String getSkipDump() {55 return skipDump;56 }57 public String getName() {...

Full Screen

Full Screen

Source:TestFileRead.java Github

copy

Full Screen

...20 List<SektionX> sektion = obj.getImports();21 //Imports och package22 Assert.assertThat(sektion.size(), IsEqual.equalTo(19));23 24 assertListContains(sektion, StringContains.containsString("package org.springframework.boot.devtools"));25 assertListContains(sektion, StringContains.containsString("import java.util.ArrayList"));26 assertListContains(sektion, StringContains.containsString("import java.util.Collection"));27 assertListContains(sektion, StringContains.containsString("import java.util.List"));28 assertListContains(sektion, StringContains.containsString("import org.springframework.boot.Banner"));29 assertListContains(sektion, StringContains.containsString("import org.springframework.boot.ResourceBanner"));30 assertListContains(sektion, StringContains.containsString("import org.springframework.boot.SpringApplication"));31 assertListContains(sektion,32 StringContains.containsString("import org.springframework.boot.WebApplicationType"));33 assertListContains(sektion, StringContains34 .containsString("import org.springframework.boot.context.config.AnsiOutputApplicationListener"));35 assertListContains(sektion, StringContains36 .containsString("import org.springframework.boot.context.config.ConfigFileApplicationListener"));37 assertListContains(sektion, StringContains38 .containsString("import org.springframework.boot.context.logging.ClasspathLoggingApplicationListener"));39 assertListContains(sektion, StringContains40 .containsString("import org.springframework.boot.context.logging.LoggingApplicationListener"));41 assertListContains(sektion, StringContains42 .containsString("import org.springframework.boot.devtools.remote.client.RemoteClientConfiguration"));43 assertListContains(sektion,44 StringContains.containsString("import org.springframework.boot.devtools.restart.RestartInitializer"));45 assertListContains(sektion, StringContains46 .containsString("import org.springframework.boot.devtools.restart.RestartScopeInitializer"));47 assertListContains(sektion,48 StringContains.containsString("import org.springframework.boot.devtools.restart.Restarter"));49 assertListContains(sektion,50 StringContains.containsString("import org.springframework.context.ApplicationContextInitializer"));51 assertListContains(sektion,52 StringContains.containsString("import org.springframework.context.ApplicationListener"));53 assertListContains(sektion,54 StringContains.containsString("import org.springframework.core.io.ClassPathResource"));55 //Klass56 Assert.assertThat(obj.getText(), IsEqual.equalTo("APA"));57 58 }59 private static void assertListContains(List<SektionX> items, Matcher<String> matcher) {60 Assert.assertTrue("Hittade inte sträng i lista", items.stream().anyMatch(s -> matcher.matches(s.getText())));61 }62}...

Full Screen

Full Screen

Source:Tests.java Github

copy

Full Screen

...37 String inputText = "Wanda wiedziała o wieściach od Wiesława.\nw";38 System.setIn(new ByteArrayInputStream(inputText.getBytes()));39 Task.main(new String[]{});40 assertThat("Oczekujemy w wyniku liczbę 6", outContent.toString(),41 StringContains.containsString("6"));42 assertThat("Oczekujemy w wyniku liczbę 18", outContent.toString(),43 StringContains.containsString("18"));44 assertThat("Oczekujemy w wyniku liczbę 37", outContent.toString(),45 StringContains.containsString("37"));46 //89.6, Double.parseDouble(outContent.toString().trim()), 0.1);47 }48 @Test49 public void testSolution2() {50 String inputText = "Wanda wiedziała o wieściach od Wiesława.\nW";51 System.setIn(new ByteArrayInputStream(inputText.getBytes()));52 Task.main(new String[]{});53 assertThat("Oczekujemy w wyniku liczbę 0", outContent.toString(),54 StringContains.containsString("0"));55 assertThat("Oczekujemy w wyniku liczbę 31", outContent.toString(),56 StringContains.containsString("31"));57 }58 @Test59 public void testSolution3() {60 String inputText = "12345678901\n1";61 System.setIn(new ByteArrayInputStream(inputText.getBytes()));62 Task.main(new String[]{});63 assertThat("Oczekujemy w wyniku liczbę 0", outContent.toString(),64 StringContains.containsString("0"));65 assertThat("Oczekujemy w wyniku liczbę 10", outContent.toString(),66 StringContains.containsString("10"));67 }68 @Test69 public void testSolution4() {70 String inputText = "AAAAaaaCCCC\nb";71 System.setIn(new ByteArrayInputStream(inputText.getBytes()));72 Task.main(new String[]{});73 for (int i = 0; i < inputText.length(); i++) {74 assertThat(String.format("Dla wejścia na indexie %d to %c a nie 'c'. Szukamy 'c'.", i, inputText.charAt(i)), outContent.toString(),75 CoreMatchers.not(StringContains.containsString(String.valueOf(i))));76 }77 }78}...

Full Screen

Full Screen

Source:ClassLoadingHelper.java Github

copy

Full Screen

...11import static org.hamcrest.CoreMatchers.is;12import static org.hamcrest.MatcherAssert.assertThat;13import static org.hamcrest.core.AllOf.allOf;14import static org.hamcrest.core.IsCollectionContaining.hasItems;15import static org.hamcrest.core.StringContains.containsString;16import java.util.HashMap;17import java.util.List;18import java.util.Map;19import java.util.Set;20import org.hamcrest.Matcher;21import org.hamcrest.core.StringContains;22public class ClassLoadingHelper {23 public static Map<String, ClassLoader> createdClassLoaders = new HashMap<>();24 public static void addClassLoader(String element) {25 createdClassLoaders.put(element, Thread.currentThread().getContextClassLoader());26 }27 public static void verifyUsedClassLoaders(String... phasesToExecute) {28 Map<String, ClassLoader> createdClassLoaders = ClassLoadingHelper.createdClassLoaders;29 List<ClassLoader> collect = createdClassLoaders.values().stream().distinct().collect(toList());30 collect.forEach(ClassLoadingHelper::assertExtensionClassLoader);31 Set<String> executedPhases = createdClassLoaders.keySet();32 assertThat(executedPhases, is(hasItems(stream(phasesToExecute).map(StringContains::containsString).toArray(Matcher[]::new))));33 }34 private static void assertExtensionClassLoader(ClassLoader classLoader) {35 assertThat(classLoader.toString(),36 allOf(containsString("classloading-extension"),37 anyOf(containsString(".TestRegionClassLoader[Region] @"),38 containsString("MuleArtifactClassLoader"))));39 }40}...

Full Screen

Full Screen

Source:StringContainsTest.java Github

copy

Full Screen

1package org.hamcrest.core;2import org.hamcrest.AbstractMatcherTest;3import org.hamcrest.Matcher;4import static org.hamcrest.core.StringContains.containsString;5import static org.hamcrest.core.StringContains.containsStringIgnoringCase;6public class StringContainsTest extends AbstractMatcherTest {7 static final String EXCERPT = "EXCERPT";8 final Matcher<String> stringContains = containsString(EXCERPT);9 @Override10 protected Matcher<?> createMatcher() {11 return stringContains;12 }13 public void testMatchesSubstrings() {14 assertMatches(stringContains, EXCERPT + "END");15 assertMatches(stringContains, "START" + EXCERPT);16 assertMatches(stringContains, "START" + EXCERPT + "END");17 assertMatches(stringContains, EXCERPT);18 assertDoesNotMatch(stringContains, EXCERPT.toLowerCase());19 assertMatches(stringContains, EXCERPT + EXCERPT);20 assertDoesNotMatch(stringContains, "XC");21 assertMismatchDescription("was \"Something else\"", stringContains, "Something else");22 assertDescription("a string containing \"EXCERPT\"", stringContains);23 }24 public void testMatchesSubstringsIgnoringCase() {25 final Matcher<String> ignoringCase = containsStringIgnoringCase("ExCert");26 assertMatches(ignoringCase, "eXcERT" + "END");27 assertMatches(ignoringCase, "START" + "EXCert");28 assertMatches(ignoringCase, "START" + "excERT" + "END");29 assertMatches(ignoringCase, "eXCert" + "excErt");30 assertDoesNotMatch(ignoringCase, "xc");31 assertMismatchDescription("was \"Something else\"", ignoringCase, "Something else");32 assertDescription("a string containing \"ExCert\" ignoring case", ignoringCase);33 }34}...

Full Screen

Full Screen

containsString

Using AI Code Generation

copy

Full Screen

1assertThat("The quick brown fox jumps over the lazy dog", containsString("fox"))2assertThat("The quick brown fox jumps over the lazy dog", containsStringIgnoringCase("FOX"))3assertThat("The quick brown fox jumps over the lazy dog", endsWith("dog"))4assertThat("The quick brown fox jumps over the lazy dog", endsWithIgnoringCase("DOG"))5assertThat("The quick brown fox jumps over the lazy dog", startsWith("The"))6assertThat("The quick brown fox jumps over the lazy dog", startsWithIgnoringCase("the"))7assertThat("The quick brown fox jumps over the lazy dog", equalToIgnoringCase("the quick brown fox jumps over the lazy dog"))8assertThat("The quick brown fox jumps over the lazy dog", equalToIgnoringWhiteSpace("The quick brown fox jumps over the lazy dog"))9assertThat("The quick brown fox jumps over the lazy dog", equalToCompressingWhiteSpace("The quick brown fox jumps over the lazy dog"))10assertThat("The quick brown fox jumps over the lazy dog", equalTo("The quick brown fox jumps over the lazy dog"))11assertThat("The quick brown fox jumps over the lazy dog", containsString("fox"))12assertThat("The quick brown fox jumps over the lazy dog", containsString("fox"))13assertThat("The quick brown fox jumps over the lazy dog", containsString("fox"))14assertThat("The quick brown fox jumps over

Full Screen

Full Screen

containsString

Using AI Code Generation

copy

Full Screen

1assertThat("Hello World", containsString("Hello"));2assertThat("Hello World", containsStringIgnoringCase("hello"));3assertThat("Hello World", containsStringIgnoringCase("hello"));4assertThat("Hello World", containsString("Hello"));5assertThat("Hello World", containsStringIgnoringCase("hello"));6assertThat("Hello World", containsStringIgnoringCase("hello"));7assertThat("Hello World", containsString("Hello"));8assertThat("Hello World", containsStringIgnoringCase("hello"));9assertThat("Hello World", containsStringIgnoringCase("hello"));10assertThat("Hello World", containsString("Hello"));11assertThat("Hello World", containsStringIgnoringCase("hello"));12assertThat("Hello World", containsStringIgnoringCase("hello"));13assertThat("Hello World", containsString("Hello"));14assertThat("Hello World", containsStringIgnoringCase("hello"));15assertThat("Hello World", containsStringIgnoringCase("hello"));16assertThat("Hello World", containsString("Hello"));17assertThat("Hello World", containsStringIgnoringCase("hello"));18assertThat("Hello World", containsStringIgnoringCase

Full Screen

Full Screen

containsString

Using AI Code Generation

copy

Full Screen

1import org.hamcrest.core.StringContains2assertThat response, StringContains.containsString("Hello World")3import org.hamcrest.core.StringContains4assertThat response, StringContains.containsStringIgnoringCase("hello world")5import static org.hamcrest.Matchers.*6assertThat response, containsString("Hello World")7import static org.hamcrest.Matchers.*8assertThat response, containsStringIgnoringCase("hello world")9def json = new JsonSlurper()10def jsonOutput = json.parseText(response)11def json = new JsonSlurper()12def jsonOutput = json.parseText(response)13assert jsonOutput.message.equalsIgnoreCase("hello world")14def xml = new MarkupBuilder()15def xmlOutput = xml.parseText(response)16def xml = new MarkupBuilder()17def xmlOutput = xml.parseText(response)18assert xmlOutput.message.equalsIgnoreCase("hello world")19def json = new JSONObject(response)20assert json.getString("message") == "Hello World"21def json = new JSONObject(response)22assert json.getString("message").equalsIgnoreCase("hello world")23def xml = new XML(response)24def xml = new XML(response)25assert xml.message.equalsIgnoreCase("hello world")26def xml = new XMLTokener(response)27assert xml.nextValue().message == "Hello World"28def xml = new XMLTokener(response)29assert xml.nextValue().message.equalsIgnoreCase("hello world")

Full Screen

Full Screen

containsString

Using AI Code Generation

copy

Full Screen

1import static org.hamcrest.Matchers.containsString2import static org.junit.Assert.assertThat3assertThat("Hello World", containsString("Hello"))4import static org.hamcrest.Matchers.containsStringIgnoringCase5import static org.junit.Assert.assertThat6assertThat("Hello World", containsStringIgnoringCase("hello"))7import static org.hamcrest.Matchers.endsWith8import static org.junit.Assert.assertThat9assertThat("Hello World", endsWith("World"))10import static org.hamcrest.Matchers.startsWith11import static org.junit.Assert.assertThat12assertThat("Hello World", startsWith("Hello"))13import static org.hamcrest.Matchers.stringContainsInOrder14import static org.junit.Assert.assertThat15assertThat("Hello World", stringContainsInOrder("Hello", "World"))16import static org.hamcrest.Matchers.stringContainsInOrderIgnoringCase17import static org.junit.Assert.assertThat18assertThat("Hello World", stringContainsInOrderIgnoringCase("hello", "world"))19import static org.hamcrest.Matchers.stringContainsInOrderIgnoringWhiteSpace20import static org.junit.Assert.assertThat21assertThat("Hello World", stringContainsInOrderIgnoringWhiteSpace("Hello", "World"))22import static org.hamcrest.Matchers.stringContainsInRelativeOrder23import static org.junit.Assert.assertThat24assertThat("Hello World", stringContainsInRelativeOrder("World", "Hello"))25import static org.hamcrest.Matchers.stringContainsInRelativeOrderIgnoringCase26import static org.junit.Assert.assertThat27assertThat("Hello World", stringContainsInRelativeOrderIgnoringCase("world", "hello"))28import static org.hamcrest.Matchers.stringContainsInRelativeOrderIgnoringWhiteSpace29import static org.junit.Assert.assertThat30assertThat("Hello World", stringContainsInRelativeOrderIgnoringWhiteSpace("World", "Hello"))

Full Screen

Full Screen

containsString

Using AI Code Generation

copy

Full Screen

1import static org.hamcrest.CoreMatchers.containsString2import static org.hamcrest.MatcherAssert.assertThat3assertThat("My name is John", containsString("John"))4import static org.hamcrest.Matchers.containsString5import static org.hamcrest.MatcherAssert.assertThat6assertThat("My name is John", containsString("John"))7import static org.hamcrest.text.IsEqualIgnoringCase.equalToIgnoringCase8import static org.hamcrest.MatcherAssert.assertThat9assertThat("My name is John", equalToIgnoringCase("John"))10import static org.hamcrest.core.IsEqual.equalTo11import static org.hamcrest.MatcherAssert.assertThat12assertThat("My name is John", equalTo("John"))13import static org.hamcrest.core.IsEqual.equalTo14import static org.hamcrest.MatcherAssert.assertThat15assertThat("My name is John", equalTo("John"))16import static org.hamcrest.core.IsEqual.equalTo17import static org.hamcrest.MatcherAssert.assertThat18assertThat("My name is John", equalTo("John"))19import static org.hamcrest.core.IsEqual.equalTo20import static org.hamcrest.MatcherAssert.assertThat21assertThat("My name is John", equalTo("John"))22import static org.hamcrest.core.IsEqual.equalTo23import static org.hamcrest.MatcherAssert.assertThat24assertThat("My name is John", equalTo("John"))25import static org.hamcrest.core.IsEqual.equalTo26import static org.hamcrest.MatcherAssert.assertThat27assertThat("My name is John", equalTo("John"))28import static org.hamcrest.core.IsEqual.equalTo29import static org.hamcrest.MatcherAssert.assertThat30assertThat("My name is John", equalTo("John"))31import static org.hamcrest.core.IsEqual.equalTo32import static org.hamcrest.MatcherAssert.assertThat33assertThat("My name is John", equalTo("John"))34import static org.hamcrest.core.IsEqual.equalTo35import static org.hamcrest.MatcherAssert.assertThat36assertThat("My name is John", equalTo("John"))

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 StringContains

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful