diff --git a/animal-sniffer-mvn-plugin/pom.xml b/animal-sniffer-mvn-plugin/pom.xml index 0fec5d0175..c2ed19b401 100644 --- a/animal-sniffer-mvn-plugin/pom.xml +++ b/animal-sniffer-mvn-plugin/pom.xml @@ -26,14 +26,6 @@ - - maven-compiler-plugin - 3.7.0 - - 1.8 - 1.8 - - org.codehaus.mojo animal-sniffer-maven-plugin diff --git a/annotations/annotation-processing/pom.xml b/annotations/annotation-processing/pom.xml index b5219d57ba..7dabe7a9a7 100644 --- a/annotations/annotation-processing/pom.xml +++ b/annotations/annotation-processing/pom.xml @@ -19,32 +19,11 @@ - com.google.auto.service auto-service ${auto-service.version} provided - - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - ${maven-compiler-plugin.version} - - 1.8 - 1.8 - - - - - - - \ No newline at end of file diff --git a/apache-cxf/cxf-introduction/pom.xml b/apache-cxf/cxf-introduction/pom.xml index 1b9ba22230..c584fcfe5b 100644 --- a/apache-cxf/cxf-introduction/pom.xml +++ b/apache-cxf/cxf-introduction/pom.xml @@ -25,15 +25,6 @@ com.baeldung.cxf.introduction.Server - - maven-surefire-plugin - ${surefire.version} - - - **/*LiveTest.java - - - diff --git a/apache-cxf/cxf-jaxrs-implementation/pom.xml b/apache-cxf/cxf-jaxrs-implementation/pom.xml index 981e0ef7aa..32b93c9e78 100644 --- a/apache-cxf/cxf-jaxrs-implementation/pom.xml +++ b/apache-cxf/cxf-jaxrs-implementation/pom.xml @@ -27,15 +27,6 @@ com.baeldung.cxf.jaxrs.implementation.RestfulServer - - maven-surefire-plugin - ${surefire.version} - - - **/*LiveTest.java - - - diff --git a/apache-cxf/cxf-spring/pom.xml b/apache-cxf/cxf-spring/pom.xml index 2cd700680b..9bfc2dd889 100644 --- a/apache-cxf/cxf-spring/pom.xml +++ b/apache-cxf/cxf-spring/pom.xml @@ -52,15 +52,6 @@ false - - maven-surefire-plugin - ${surefire.version} - - - **/*LiveTest.java - - - @@ -102,24 +93,6 @@ - - - maven-surefire-plugin - ${surefire.version} - - - integration-test - - test - - - - none - - - - - diff --git a/apache-spark/pom.xml b/apache-spark/pom.xml index 2f94987b11..e53e115ddd 100644 --- a/apache-spark/pom.xml +++ b/apache-spark/pom.xml @@ -32,17 +32,4 @@ test - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.7.0 - - 1.8 - 1.8 - - - - diff --git a/atomix/pom.xml b/atomix/pom.xml index 80c573dd86..0ecdf8987d 100644 --- a/atomix/pom.xml +++ b/atomix/pom.xml @@ -29,18 +29,4 @@ 1.2.17 - - - - maven-compiler-plugin - 3.7.0 - - 1.8 - 1.8 - - - - - - diff --git a/bootique/dependency-reduced-pom.xml b/bootique/dependency-reduced-pom.xml deleted file mode 100644 index ab09cfb7b1..0000000000 --- a/bootique/dependency-reduced-pom.xml +++ /dev/null @@ -1,56 +0,0 @@ - - - - bootique-parent - io.bootique.parent - 0.12 - - 4.0.0 - com.baeldung.bootique - bootique - bootique - 1.0-SNAPSHOT - http://maven.apache.org - - - - maven-shade-plugin - - - - - - io.bootique - bootique-test - 0.23 - test - - - junit - junit - 4.12 - test - - - hamcrest-core - org.hamcrest - - - - - - - - io.bootique.bom - bootique-bom - 0.23 - pom - import - - - - - com.baeldung.bootique.App - - - diff --git a/camel-api/pom.xml b/camel-api/pom.xml index 3f96e2209c..a1cdb1064e 100644 --- a/camel-api/pom.xml +++ b/camel-api/pom.xml @@ -45,14 +45,6 @@ spring-boot:run - - maven-compiler-plugin - ${maven-compiler-plugin.version} - - 1.8 - 1.8 - - org.springframework.boot spring-boot-maven-plugin @@ -71,7 +63,6 @@ UTF-8 3.7.0 - 2.19.1 2.19.1 1.5.4.RELEASE diff --git a/cas/cas-secured-app/pom.xml b/cas/cas-secured-app/pom.xml index d52597412e..947aa2f351 100644 --- a/cas/cas-secured-app/pom.xml +++ b/cas/cas-secured-app/pom.xml @@ -65,24 +65,6 @@ org.springframework.boot spring-boot-maven-plugin - - org.apache.maven.plugins - maven-surefire-plugin - ${maven-surefire-plugin.version} - - 3 - true - - **/*IntegrationTest.java - **/*LongRunningUnitTest.java - **/*ManualTest.java - **/JdbcTest.java - **/*LiveTest.java - - - - - diff --git a/core-groovy/pom.xml b/core-groovy/pom.xml index 91cbe66e35..e645e95a88 100644 --- a/core-groovy/pom.xml +++ b/core-groovy/pom.xml @@ -78,10 +78,6 @@ - - maven-surefire-plugin - ${maven-surefire-plugin.version} - maven-failsafe-plugin 2.19.1 diff --git a/core-java-9/pom.xml b/core-java-9/pom.xml index 40e29af35f..5f07a62e13 100644 --- a/core-java-9/pom.xml +++ b/core-java-9/pom.xml @@ -75,13 +75,6 @@ 1.9 - - - org.apache.maven.plugins - maven-surefire-plugin - ${maven-surefire-plugin.version} - - diff --git a/core-java-io/pom.xml b/core-java-io/pom.xml index 1c2a9b1249..03fd5799c9 100644 --- a/core-java-io/pom.xml +++ b/core-java-io/pom.xml @@ -232,18 +232,7 @@ - - - org.apache.maven.plugins - maven-compiler-plugin - ${maven-compiler-plugin.version} - - 1.8 - 1.8 - - - - + org.apache.maven.plugins maven-surefire-plugin @@ -256,7 +245,6 @@ true - org.springframework.boot spring-boot-maven-plugin diff --git a/core-java-sun/pom.xml b/core-java-sun/pom.xml index 2b654fa3a5..04c2454872 100644 --- a/core-java-sun/pom.xml +++ b/core-java-sun/pom.xml @@ -238,31 +238,6 @@ - - - org.apache.maven.plugins - maven-compiler-plugin - ${maven-compiler-plugin.version} - - 1.8 - 1.8 - - - - - org.apache.maven.plugins - maven-surefire-plugin - - - **/*LiveTest.java - **/*IntegrationTest.java - **/*LongRunningUnitTest.java - **/*ManualTest.java - - - - - org.apache.maven.plugins maven-dependency-plugin diff --git a/core-java/externalizable.txt b/core-java/externalizable.txt new file mode 100644 index 0000000000..ddd3e143a8 Binary files /dev/null and b/core-java/externalizable.txt differ diff --git a/core-java/pom.xml b/core-java/pom.xml index b7760dc250..f7bf9ed12a 100644 --- a/core-java/pom.xml +++ b/core-java/pom.xml @@ -247,17 +247,6 @@ - - - org.apache.maven.plugins - maven-compiler-plugin - ${maven-compiler-plugin.version} - - 1.8 - 1.8 - - - org.apache.maven.plugins maven-surefire-plugin diff --git a/core-java/src/main/java/com/baeldung/keystore/JavaKeyStore.java b/core-java/src/main/java/com/baeldung/keystore/JavaKeyStore.java new file mode 100644 index 0000000000..29cba37d43 --- /dev/null +++ b/core-java/src/main/java/com/baeldung/keystore/JavaKeyStore.java @@ -0,0 +1,92 @@ +package com.baeldung.keystore; + +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.security.KeyStore; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; +import java.security.PrivateKey; +import java.security.UnrecoverableEntryException; +import java.security.cert.Certificate; +import java.security.cert.CertificateException; +import java.util.Enumeration; + +/** + * Created by adi on 3/7/18. + */ +public class JavaKeyStore { + + private KeyStore keyStore; + + private String keyStoreName; + private String keyStoreType; + private String keyStorePassword; + + JavaKeyStore(String keyStoreType, String keyStorePassword, String keyStoreName) throws CertificateException, NoSuchAlgorithmException, KeyStoreException, IOException { + this.keyStoreName = keyStoreName; + this.keyStoreType = keyStoreType; + this.keyStorePassword = keyStorePassword; + } + + void createEmptyKeyStore() throws KeyStoreException, CertificateException, NoSuchAlgorithmException, IOException { + if(keyStoreType ==null || keyStoreType.isEmpty()){ + keyStoreType = KeyStore.getDefaultType(); + } + keyStore = KeyStore.getInstance(keyStoreType); + //load + char[] pwdArray = keyStorePassword.toCharArray(); + keyStore.load(null, pwdArray); + + // Save the keyStore + FileOutputStream fos = new FileOutputStream(keyStoreName); + keyStore.store(fos, pwdArray); + fos.close(); + } + + void loadKeyStore() throws IOException, KeyStoreException, CertificateException, NoSuchAlgorithmException { + char[] pwdArray = keyStorePassword.toCharArray(); + keyStore.load(new FileInputStream(keyStoreName), pwdArray); + } + + void setEntry(String alias, KeyStore.SecretKeyEntry secretKeyEntry, KeyStore.ProtectionParameter protectionParameter) throws KeyStoreException { + keyStore.setEntry(alias, secretKeyEntry, protectionParameter); + } + + KeyStore.Entry getEntry(String alias) throws UnrecoverableEntryException, NoSuchAlgorithmException, KeyStoreException { + KeyStore.ProtectionParameter protParam = new KeyStore.PasswordProtection(keyStorePassword.toCharArray()); + return keyStore.getEntry(alias, protParam); + } + + void setKeyEntry(String alias, PrivateKey privateKey, String keyPassword, Certificate[] certificateChain) throws KeyStoreException { + keyStore.setKeyEntry(alias, privateKey, keyPassword.toCharArray(), certificateChain); + } + + void setCertificateEntry(String alias, Certificate certificate) throws KeyStoreException { + keyStore.setCertificateEntry(alias, certificate); + } + + Certificate getCertificate(String alias) throws KeyStoreException { + return keyStore.getCertificate(alias); + } + + void deleteEntry(String alias) throws KeyStoreException { + keyStore.deleteEntry(alias); + } + + void deleteKeyStore() throws KeyStoreException, IOException { + Enumeration aliases = keyStore.aliases(); + while (aliases.hasMoreElements()) { + String alias = aliases.nextElement(); + keyStore.deleteEntry(alias); + } + keyStore = null; + Files.delete(Paths.get(keyStoreName)); + } + + KeyStore getKeyStore() { + return this.keyStore; + } +} diff --git a/core-java/src/test/java/com/baeldung/keystore/JavaKeyStoreTest.java b/core-java/src/test/java/com/baeldung/keystore/JavaKeyStoreTest.java new file mode 100644 index 0000000000..ff1d337597 --- /dev/null +++ b/core-java/src/test/java/com/baeldung/keystore/JavaKeyStoreTest.java @@ -0,0 +1,205 @@ +package com.baeldung.keystore; + +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import sun.security.x509.AlgorithmId; +import sun.security.x509.CertificateAlgorithmId; +import sun.security.x509.CertificateSerialNumber; +import sun.security.x509.CertificateValidity; +import sun.security.x509.CertificateVersion; +import sun.security.x509.CertificateX509Key; +import sun.security.x509.X500Name; +import sun.security.x509.X509CertImpl; +import sun.security.x509.X509CertInfo; + +import javax.crypto.KeyGenerator; +import javax.crypto.SecretKey; +import java.io.IOException; +import java.math.BigInteger; +import java.security.InvalidKeyException; +import java.security.KeyPair; +import java.security.KeyPairGenerator; +import java.security.KeyStore; +import java.security.NoSuchAlgorithmException; +import java.security.NoSuchProviderException; +import java.security.SecureRandom; +import java.security.SignatureException; +import java.security.cert.CertificateException; +import java.security.cert.X509Certificate; +import java.util.Date; + +/** + * Created by adi on 4/14/18. + */ +public class JavaKeyStoreTest { + + private JavaKeyStore keyStore; + + private static final String KEYSTORE_PWD = "abc123"; + private static final String KEYSTORE_NAME = "myKeyStore"; + private static final String KEY_STORE_TYPE = "JCEKS"; + + private static final String MY_SECRET_ENTRY = "mySecretEntry"; + private static final String DN_NAME = "CN=test, OU=test, O=test, L=test, ST=test, C=CY"; + private static final String SHA1WITHRSA = "SHA1withRSA"; + private static final String MY_PRIVATE_KEY = "myPrivateKey"; + private static final String MY_CERTIFICATE = "myCertificate"; + + @Before + public void setUp() throws Exception { + //using java cryptography extension keyStore instead of Keystore.getDefaultType + keyStore = new JavaKeyStore(KEY_STORE_TYPE, KEYSTORE_PWD, KEYSTORE_NAME); + } + + @After + public void tearDown() throws Exception { + if (keyStore.getKeyStore() != null) { + keyStore.deleteKeyStore(); + } + } + + @Test + public void givenNoKeyStore_whenCreateEmptyKeyStore_thenGetKeyStoreNotNull() throws Exception { + keyStore.createEmptyKeyStore(); + KeyStore result = keyStore.getKeyStore(); + Assert.assertNotNull(result); + } + + @Test + public void givenEmptyKeystore_whenLoadKeyStore_thenKeyStoreLoadedAndSizeZero() throws Exception { + keyStore.createEmptyKeyStore(); + keyStore.loadKeyStore(); + KeyStore result = keyStore.getKeyStore(); + Assert.assertNotNull(result); + Assert.assertTrue(result.size() == 0); + } + + @Test + public void givenLoadedKeyStore_whenSetEntry_thenSizeIsOneAndGetKeyNotNull() throws Exception { + keyStore.createEmptyKeyStore(); + keyStore.loadKeyStore(); + + KeyGenerator keygen = KeyGenerator.getInstance("HmacSHA256"); + SecretKey secretKey = keygen.generateKey(); + //ideally, password should be different for every key + KeyStore.ProtectionParameter protParam = new KeyStore.PasswordProtection(KEYSTORE_PWD.toCharArray()); + KeyStore.SecretKeyEntry secretKeyEntry = new KeyStore.SecretKeyEntry(secretKey); + keyStore.setEntry(MY_SECRET_ENTRY, secretKeyEntry, protParam); + + KeyStore result = keyStore.getKeyStore(); + Assert.assertTrue(result.size() == 1); + KeyStore.Entry entry = keyStore.getEntry(MY_SECRET_ENTRY); + Assert.assertTrue(entry != null); + } + + @Test + public void givenLoadedKeyStore_whenSetKeyEntry_thenSizeIsOneAndGetEntryNotNull() throws Exception { + keyStore.createEmptyKeyStore(); + keyStore.loadKeyStore(); + + // Generate the key pair + KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA"); + keyPairGenerator.initialize(1024); + KeyPair keyPair = keyPairGenerator.generateKeyPair(); + + // Generate a self signed certificate + X509Certificate certificate = generateSelfSignedCertificate(keyPair); + + X509Certificate[] certificateChain = new X509Certificate[1]; + certificateChain[0] = certificate; + keyStore.setKeyEntry(MY_PRIVATE_KEY, keyPair.getPrivate(), KEYSTORE_PWD, certificateChain); + + KeyStore result = keyStore.getKeyStore(); + Assert.assertTrue(result.size() == 1); + KeyStore.Entry entry = keyStore.getEntry(MY_PRIVATE_KEY); + Assert.assertTrue(entry != null); + } + + @Test + public void givenLoadedKeyStore_whenSetCertificateEntry_thenSizeIsOneAndGetCertificateEntryNotNull() throws Exception { + keyStore.createEmptyKeyStore(); + keyStore.loadKeyStore(); + + // Generate the key pair + KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA"); + keyPairGenerator.initialize(1024); + KeyPair keyPair = keyPairGenerator.generateKeyPair(); + + // Generate a self signed certificate + X509Certificate certificate = generateSelfSignedCertificate(keyPair); + + keyStore.setCertificateEntry(MY_CERTIFICATE, certificate); + + KeyStore result = this.keyStore.getKeyStore(); + Assert.assertTrue(result.size() == 1); + java.security.cert.Certificate resultCertificate = keyStore.getCertificate(MY_CERTIFICATE); + Assert.assertNotNull(resultCertificate); + } + + @Test + public void givenLoadedKeyStoreWithOneEntry_whenDeleteEntry_thenKeyStoreSizeIsZero() throws Exception { + keyStore.createEmptyKeyStore(); + keyStore.loadKeyStore(); + + KeyGenerator keygen = KeyGenerator.getInstance("HmacSHA256"); + SecretKey secretKey = keygen.generateKey(); + //ideally, password should be different for every key + KeyStore.ProtectionParameter protParam = new KeyStore.PasswordProtection(KEYSTORE_PWD.toCharArray()); + KeyStore.SecretKeyEntry secretKeyEntry = new KeyStore.SecretKeyEntry(secretKey); + keyStore.setEntry(MY_SECRET_ENTRY, secretKeyEntry, protParam); + + keyStore.deleteEntry(MY_SECRET_ENTRY); + + KeyStore result = this.keyStore.getKeyStore(); + Assert.assertTrue(result.size() == 0); + } + + @Test + public void givenLoadedKeystore_whenDeleteKeyStore_thenKeyStoreIsNull() throws Exception { + keyStore.createEmptyKeyStore(); + keyStore.loadKeyStore(); + + keyStore.deleteKeyStore(); + + KeyStore result = this.keyStore.getKeyStore(); + Assert.assertTrue(result == null); + } + + private X509Certificate generateSelfSignedCertificate(KeyPair keyPair) throws CertificateException, IOException, NoSuchProviderException, NoSuchAlgorithmException, InvalidKeyException, SignatureException { + X509CertInfo certInfo = new X509CertInfo(); + // Serial number and version + certInfo.set(X509CertInfo.SERIAL_NUMBER, new CertificateSerialNumber(new BigInteger(64, new SecureRandom()))); + certInfo.set(X509CertInfo.VERSION, new CertificateVersion(CertificateVersion.V3)); + + // Subject & Issuer + X500Name owner = new X500Name(DN_NAME); + certInfo.set(X509CertInfo.SUBJECT, owner); + certInfo.set(X509CertInfo.ISSUER, owner); + + // Key and algorithm + certInfo.set(X509CertInfo.KEY, new CertificateX509Key(keyPair.getPublic())); + AlgorithmId algorithm = new AlgorithmId(AlgorithmId.sha1WithRSAEncryption_oid); + certInfo.set(X509CertInfo.ALGORITHM_ID, new CertificateAlgorithmId(algorithm)); + + // Validity + Date validFrom = new Date(); + Date validTo = new Date(validFrom.getTime() + 50L * 365L * 24L * 60L * 60L * 1000L); //50 years + CertificateValidity validity = new CertificateValidity(validFrom, validTo); + certInfo.set(X509CertInfo.VALIDITY, validity); + + // Create certificate and sign it + X509CertImpl cert = new X509CertImpl(certInfo); + cert.sign(keyPair.getPrivate(), SHA1WITHRSA); + + // Since the SHA1withRSA provider may have a different algorithm ID to what we think it should be, + // we need to reset the algorithm ID, and resign the certificate + AlgorithmId actualAlgorithm = (AlgorithmId) cert.get(X509CertImpl.SIG_ALG); + certInfo.set(CertificateAlgorithmId.NAME + "." + CertificateAlgorithmId.ALGORITHM, actualAlgorithm); + X509CertImpl newCert = new X509CertImpl(certInfo); + newCert.sign(keyPair.getPrivate(), SHA1WITHRSA); + + return newCert; + } +} \ No newline at end of file diff --git a/core-java/yofile.txt b/core-java/yofile.txt new file mode 100644 index 0000000000..ad56bf35f7 Binary files /dev/null and b/core-java/yofile.txt differ diff --git a/core-java/yofile2.txt b/core-java/yofile2.txt new file mode 100644 index 0000000000..8393b6e98b Binary files /dev/null and b/core-java/yofile2.txt differ diff --git a/core-kotlin/.gitignore b/core-kotlin/.gitignore new file mode 100644 index 0000000000..ae3c172604 --- /dev/null +++ b/core-kotlin/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/core-kotlin/README.md b/core-kotlin/README.md index 54528a076b..d6bd41a111 100644 --- a/core-kotlin/README.md +++ b/core-kotlin/README.md @@ -23,3 +23,4 @@ - [Kotlin Dependency Injection with Kodein](http://www.baeldung.com/kotlin-kodein-dependency-injection) - [Regular Expressions in Kotlin](http://www.baeldung.com/kotlin-regular-expressions) - [Objects in Kotlin](http://www.baeldung.com/kotlin-objects) +- [Reading from a File in Kotlin](http://www.baeldung.com/kotlin-read-file) diff --git a/core-kotlin/pom.xml b/core-kotlin/pom.xml index 36298ca084..b5aeb264e1 100644 --- a/core-kotlin/pom.xml +++ b/core-kotlin/pom.xml @@ -21,6 +21,11 @@ + + org.apache.commons + commons-math3 + ${commons-math3.version} + org.junit.jupiter junit-jupiter-engine @@ -33,12 +38,6 @@ ${junit.platform.version} test - - junit - junit - ${junit4.version} - test - org.jetbrains.kotlin kotlin-stdlib @@ -46,7 +45,7 @@ org.jetbrains.kotlin - kotlin-stdlib-jre8 + kotlin-stdlib-jdk8 ${kotlin-stdlib.version} @@ -160,10 +159,6 @@ - - maven-surefire-plugin - ${maven-surefire-plugin.version} - maven-failsafe-plugin 2.19.1 @@ -194,14 +189,16 @@ UTF-8 - 1.1.2 - 1.1.2 - 1.1.2 - 1.1.2 + 1.2.31 + 1.2.31 + 1.2.31 + 1.2.31 0.15 1.5.0 4.1.0 + 3.6.1 + 5.0.0 1.0.0 4.12.0 diff --git a/core-kotlin/src/test/kotlin/com/baeldung/filter/ChunkedTest.kt b/core-kotlin/src/test/kotlin/com/baeldung/filter/ChunkedTest.kt new file mode 100644 index 0000000000..20797cc633 --- /dev/null +++ b/core-kotlin/src/test/kotlin/com/baeldung/filter/ChunkedTest.kt @@ -0,0 +1,39 @@ +package com.baeldung.filter + +import org.junit.jupiter.api.Assertions.assertIterableEquals +import org.junit.jupiter.api.Test + +internal class ChunkedTest { + + @Test + fun givenDNAFragmentString_whenChunking_thenProduceListOfChunks() { + val dnaFragment = "ATTCGCGGCCGCCAA" + + val fragments = dnaFragment.chunked(3) + + assertIterableEquals(listOf("ATT", "CGC", "GGC", "CGC", "CAA"), fragments) + } + + @Test + fun givenDNAString_whenChunkingWithTransformer_thenProduceTransformedList() { + val codonTable = mapOf("ATT" to "Isoleucine", "CAA" to "Glutamine", "CGC" to "Arginine", "GGC" to "Glycine") + val dnaFragment = "ATTCGCGGCCGCCAA" + + val proteins = dnaFragment.chunked(3) { codon -> + codonTable[codon.toString()] ?: error("Unknown codon") + } + + assertIterableEquals(listOf("Isoleucine", "Arginine", "Glycine", "Arginine", "Glutamine"), proteins) + } + + @Test + fun givenListOfValues_whenChunking_thenProduceListOfArrays() { + val whole = listOf(1, 4, 7, 4753, 2, 34, 62, 76, 5868, 0) + val chunks = whole.chunked(6) + + val expected = listOf(listOf(1, 4, 7, 4753, 2, 34), listOf(62, 76, 5868, 0)) + + assertIterableEquals(expected, chunks) + } + +} \ No newline at end of file diff --git a/core-kotlin/src/test/kotlin/com/baeldung/filter/DistinctTest.kt b/core-kotlin/src/test/kotlin/com/baeldung/filter/DistinctTest.kt new file mode 100644 index 0000000000..4cc6f647e1 --- /dev/null +++ b/core-kotlin/src/test/kotlin/com/baeldung/filter/DistinctTest.kt @@ -0,0 +1,71 @@ +package com.baeldung.filter + +import org.junit.jupiter.api.Assertions.assertIterableEquals +import org.junit.jupiter.api.Test + +internal class DistinctTest { + data class SmallClass(val key: String, val num: Int) + + @Test + fun whenApplyingDistinct_thenReturnListOfNoDuplicateValues() { + val array = arrayOf(1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 5, 6, 7, 8, 9) + val result = array.distinct() + val expected = listOf(1, 2, 3, 4, 5, 6, 7, 8, 9) + + assertIterableEquals(expected, result) + } + + @Test + fun givenArrayOfClassObjects_whenApplyingDistinctOnClassProperty_thenReturnListDistinctOnThatValue() { + + val original = arrayOf( + SmallClass("key1", 1), + SmallClass("key2", 2), + SmallClass("key3", 3), + SmallClass("key4", 3), + SmallClass("er", 9), + SmallClass("er", 10), + SmallClass("er", 11)) + + val actual = original.distinctBy { it.key } + + val expected = listOf( + SmallClass("key1", 1), + SmallClass("key2", 2), + SmallClass("key3", 3), + SmallClass("key4", 3), + SmallClass("er", 9)) + + + assertIterableEquals(expected, actual) + } + + @Test + fun givenArrayOfClassObjects_whenApplyingComplicatedSelector_thenReturnFirstElementToMatchEachSelectorValue() { + val array = arrayOf( + SmallClass("key1", 1), + SmallClass("key2", 2), + SmallClass("key3", 3), + SmallClass("key4", 3), + SmallClass("er", 9), + SmallClass("er", 10), + SmallClass("er", 11), + SmallClass("er", 11), + SmallClass("er", 91), + SmallClass("blob", 22), + SmallClass("dob", 27), + SmallClass("high", 201_434_314)) + + val actual = array.distinctBy { Math.floor(it.num / 10.0) } + + val expected = listOf( + SmallClass("key1", 1), + SmallClass("er", 10), + SmallClass("er", 91), + SmallClass("blob", 22), + SmallClass("high", 201_434_314)) + + assertIterableEquals(expected, actual) + } + +} \ No newline at end of file diff --git a/core-kotlin/src/test/kotlin/com/baeldung/filter/DropTest.kt b/core-kotlin/src/test/kotlin/com/baeldung/filter/DropTest.kt new file mode 100644 index 0000000000..7c2685f39b --- /dev/null +++ b/core-kotlin/src/test/kotlin/com/baeldung/filter/DropTest.kt @@ -0,0 +1,53 @@ +package com.baeldung.filter + +import org.junit.jupiter.api.Assertions.assertIterableEquals +import org.junit.jupiter.api.Test + +internal class DropTest { + + @Test + fun whenDroppingFirstTwoItemsOfArray_thenTwoLess() { + val array = arrayOf(1, 2, 3, 4) + val result = array.drop(2) + val expected = listOf(3, 4) + + assertIterableEquals(expected, result) + } + + @Test + fun whenDroppingMoreItemsOfArray_thenEmptyList() { + val array = arrayOf(1, 2, 3, 4) + val result = array.drop(5) + val expected = listOf() + + assertIterableEquals(expected, result) + } + + @Test + fun givenArray_whenDroppingLastElement_thenReturnListWithoutLastElement() { + val array = arrayOf("1", "2", "3", "4") + val result = array.dropLast(1) + val expected = listOf("1", "2", "3") + + assertIterableEquals(expected, result) + } + + @Test + fun givenArrayOfFloats_whenDroppingLastUntilPredicateIsFalse_thenReturnSubsetListOfFloats() { + val array = arrayOf(1f, 1f, 1f, 1f, 1f, 2f, 1f, 1f, 1f) + val result = array.dropLastWhile { it == 1f } + val expected = listOf(1f, 1f, 1f, 1f, 1f, 2f) + + assertIterableEquals(expected, result) + } + + @Test + fun givenList_whenDroppingMoreThanAvailable_thenThrowException() { + val list = listOf('a', 'e', 'i', 'o', 'u') + val result = list.drop(6) + val expected: List = listOf() + + assertIterableEquals(expected, result) + } + +} \ No newline at end of file diff --git a/core-kotlin/src/test/kotlin/com/baeldung/filter/FilterTest.kt b/core-kotlin/src/test/kotlin/com/baeldung/filter/FilterTest.kt new file mode 100644 index 0000000000..efe6354f25 --- /dev/null +++ b/core-kotlin/src/test/kotlin/com/baeldung/filter/FilterTest.kt @@ -0,0 +1,39 @@ +package com.baeldung.filter + +import org.apache.commons.math3.primes.Primes +import org.junit.jupiter.api.Assertions.assertIterableEquals +import org.junit.jupiter.api.Test +import kotlin.test.assertTrue + +internal class FilterTest { + + @Test + fun givenAscendingValueMap_whenFilteringOnValue_ThenReturnSubsetOfMap() { + val originalMap = mapOf("key1" to 1, "key2" to 2, "key3" to 3) + val filteredMap = originalMap.filter { it.value < 2 } + val expectedMap = mapOf("key1" to 1) + + assertTrue { expectedMap == filteredMap } + } + + @Test + fun givenSeveralCollections_whenFilteringToAccumulativeList_thenListContainsAllContents() { + val array1 = arrayOf(90, 92, 93, 94, 92, 95, 93) + val array2 = sequenceOf(51, 31, 83, 674_506_111, 256_203_161, 15_485_863) + val list1 = listOf(0, 1, 2, 3, 4, 5, 6, 7, 8, 9) + val primes = mutableListOf() + + val expected = listOf(2, 3, 5, 7, 31, 83, 15_485_863, 256_203_161, 674_506_111) + + val primeCheck = { num: Int -> Primes.isPrime(num) } + + array1.filterTo(primes, primeCheck) + list1.filterTo(primes, primeCheck) + array2.filterTo(primes, primeCheck) + + primes.sort() + + assertIterableEquals(expected, primes) + } + +} \ No newline at end of file diff --git a/core-kotlin/src/test/kotlin/com/baeldung/filter/SliceTest.kt b/core-kotlin/src/test/kotlin/com/baeldung/filter/SliceTest.kt new file mode 100644 index 0000000000..dca167928d --- /dev/null +++ b/core-kotlin/src/test/kotlin/com/baeldung/filter/SliceTest.kt @@ -0,0 +1,44 @@ +package com.baeldung.filter + +import org.junit.jupiter.api.Assertions.assertIterableEquals +import org.junit.jupiter.api.Assertions.assertThrows +import org.junit.jupiter.api.Test + +internal class SliceTest { + + @Test + fun whenSlicingAnArrayWithDotRange_ThenListEqualsTheSlice() { + val original = arrayOf(1, 2, 3, 2, 1) + val actual = original.slice(1..3) + val expected = listOf(2, 3, 2) + + assertIterableEquals(expected, actual) + } + + @Test + fun whenSlicingAnArrayWithDownToRange_thenListMadeUpOfReverseSlice() { + val original = arrayOf(1, 2, 3, 2, 1) + val actual = original.slice(3 downTo 0) + val expected = listOf(2, 3, 2, 1) + + assertIterableEquals(expected, actual) + } + + @Test + fun whenSlicingBeyondTheRangeOfTheArray_thenContainManyNulls() { + val original = arrayOf(12, 3, 34, 4) + val actual = original.slice(3..8) + val expected = listOf(4, null, null, null, null, null) + + assertIterableEquals(expected, actual) + } + + @Test + fun whenSlicingBeyondRangeOfArrayWithStep_thenOutOfBoundsException() { + assertThrows(ArrayIndexOutOfBoundsException::class.java) { + val original = arrayOf(12, 3, 34, 4) + original.slice(3..8 step 2) + } + } + +} \ No newline at end of file diff --git a/core-kotlin/src/test/kotlin/com/baeldung/filter/TakeTest.kt b/core-kotlin/src/test/kotlin/com/baeldung/filter/TakeTest.kt new file mode 100644 index 0000000000..d021177de8 --- /dev/null +++ b/core-kotlin/src/test/kotlin/com/baeldung/filter/TakeTest.kt @@ -0,0 +1,38 @@ +package com.baeldung.filter + +import org.junit.jupiter.api.Assertions.assertIterableEquals +import org.junit.jupiter.api.Test + +internal class TakeTest { + + @Test + fun `given array of alternating types, when predicating on 'is String', then produce list of array up until predicate is false`() { + val originalArray = arrayOf("val1", 2, "val3", 4, "val5", 6) + val actualList = originalArray.takeWhile { it is String } + val expectedList = listOf("val1") + + assertIterableEquals(expectedList, actualList) + } + + @Test + fun `given array of alternating types, when taking 4 items, then produce list of first 4 items`() { + val originalArray = arrayOf("val1", 2, "val3", 4, "val5", 6) + val actualList = originalArray.take(4) + val expectedList = listOf("val1", 2, "val3", 4) + + println(originalArray.drop(4)) + println(actualList) + + assertIterableEquals(expectedList, actualList) + } + + @Test + fun `when taking more items than available, then return all elements`() { + val originalArray = arrayOf(1, 2) + val actual = originalArray.take(10) + val expected = listOf(1, 2) + + assertIterableEquals(expected, actual) + } + +} \ No newline at end of file diff --git a/drools/pom.xml b/drools/pom.xml index 5f228802fa..35f3f7331c 100644 --- a/drools/pom.xml +++ b/drools/pom.xml @@ -60,28 +60,5 @@ spring-core 4.3.6.RELEASE - - - - - - org.apache.maven.plugins - maven-surefire-plugin - ${maven-surefire-plugin.version} - - 3 - true - - **/*IntegrationTest.java - **/*LongRunningUnitTest.java - **/*ManualTest.java - **/JdbcTest.java - **/*LiveTest.java - - - - - - diff --git a/dubbo/pom.xml b/dubbo/pom.xml index af242e5905..866d1c49c9 100644 --- a/dubbo/pom.xml +++ b/dubbo/pom.xml @@ -47,27 +47,4 @@ - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.7.0 - - 1.8 - 1.8 - - - - maven-surefire-plugin - ${surefire.version} - - - **/*LiveTest.java - - - - - - diff --git a/ejb/ejb-session-beans/pom.xml b/ejb/ejb-session-beans/pom.xml index b89ff6ed15..8d05389a95 100644 --- a/ejb/ejb-session-beans/pom.xml +++ b/ejb/ejb-session-beans/pom.xml @@ -80,14 +80,6 @@ - - maven-compiler-plugin - 3.7.0 - - 1.8 - 1.8 - - maven-war-plugin 2.4 @@ -95,10 +87,6 @@ false - - maven-surefire-plugin - 2.17 - diff --git a/geotools/pom.xml b/geotools/pom.xml index 01bd6448bb..edd3c4bf3a 100644 --- a/geotools/pom.xml +++ b/geotools/pom.xml @@ -57,20 +57,6 @@ http://repo.opengeo.org - - - - true - org.apache.maven.plugins - maven-compiler-plugin - 3.7.0 - - 1.8 - 1.8 - - - - 15.2 15.2 diff --git a/guest/core-java/pom.xml b/guest/core-java/pom.xml index 35756f784b..ccad9b87cf 100644 --- a/guest/core-java/pom.xml +++ b/guest/core-java/pom.xml @@ -40,19 +40,6 @@ test - - - - - maven-compiler-plugin - 3.7.0 - - 1.8 - 1.8 - - - - 2.8.2 1.3 diff --git a/guest/deep-jsf/pom.xml b/guest/deep-jsf/pom.xml index 4697bbf588..bbb544443f 100644 --- a/guest/deep-jsf/pom.xml +++ b/guest/deep-jsf/pom.xml @@ -29,17 +29,6 @@ deep-jsf - - - org.apache.maven.plugins - maven-compiler-plugin - 3.7.0 - - 1.8 - 1.8 - - - \ No newline at end of file diff --git a/guest/junit5-example/pom.xml b/guest/junit5-example/pom.xml index 0e92060a71..c9ea232715 100644 --- a/guest/junit5-example/pom.xml +++ b/guest/junit5-example/pom.xml @@ -44,14 +44,6 @@ - - maven-compiler-plugin - 3.7.0 - - 1.8 - 1.8 - - maven-surefire-plugin 2.19.1 diff --git a/guest/log4j2-example/pom.xml b/guest/log4j2-example/pom.xml index 594b759538..26e026448f 100644 --- a/guest/log4j2-example/pom.xml +++ b/guest/log4j2-example/pom.xml @@ -41,16 +41,6 @@ - - - maven-compiler-plugin - 3.7.0 - - 1.8 - 1.8 - - - diff --git a/guest/logback-example/pom.xml b/guest/logback-example/pom.xml index 1f277787d3..8240e45b6a 100644 --- a/guest/logback-example/pom.xml +++ b/guest/logback-example/pom.xml @@ -28,19 +28,5 @@ janino 3.0.7 - - - - - - maven-compiler-plugin - 3.7.0 - - 1.8 - 1.8 - - - - \ No newline at end of file diff --git a/guest/memory-leaks/pom.xml b/guest/memory-leaks/pom.xml index e0f256b2d5..63d5af9474 100644 --- a/guest/memory-leaks/pom.xml +++ b/guest/memory-leaks/pom.xml @@ -30,15 +30,5 @@ src/test/resources/ - - - maven-compiler-plugin - 3.7.0 - - 1.8 - 1.8 - - - \ No newline at end of file diff --git a/guest/thread-pools/pom.xml b/guest/thread-pools/pom.xml index 32ae6384e2..42770edb2a 100644 --- a/guest/thread-pools/pom.xml +++ b/guest/thread-pools/pom.xml @@ -17,17 +17,4 @@ 1.2.3 - - - - - maven-compiler-plugin - 3.7.0 - - 1.8 - 1.8 - - - - \ No newline at end of file diff --git a/guest/tomcat-app/pom.xml b/guest/tomcat-app/pom.xml index 02f3abcc32..2ea5190248 100644 --- a/guest/tomcat-app/pom.xml +++ b/guest/tomcat-app/pom.xml @@ -55,14 +55,6 @@ - - maven-compiler-plugin - 3.7.0 - - 1.8 - 1.8 - - maven-war-plugin 3.0.0 diff --git a/guest/webservices/rest-client/pom.xml b/guest/webservices/rest-client/pom.xml index d74d713a29..b124e632a3 100644 --- a/guest/webservices/rest-client/pom.xml +++ b/guest/webservices/rest-client/pom.xml @@ -12,14 +12,6 @@ - - maven-compiler-plugin - 3.7.0 - - 1.8 - 1.8 - - maven-war-plugin 2.6 diff --git a/guest/webservices/rest-server/pom.xml b/guest/webservices/rest-server/pom.xml index be43a85166..a183d4110c 100644 --- a/guest/webservices/rest-server/pom.xml +++ b/guest/webservices/rest-server/pom.xml @@ -36,14 +36,6 @@ - - maven-compiler-plugin - 3.7.0 - - 1.8 - 1.8 - - maven-war-plugin 3.0.0 diff --git a/hibernate5/pom.xml b/hibernate5/pom.xml index 31fe10ee97..a9dcf56c1c 100644 --- a/hibernate5/pom.xml +++ b/hibernate5/pom.xml @@ -67,33 +67,5 @@ true - - - - org.apache.maven.plugins - maven-compiler-plugin - ${maven-compiler-plugin.version} - - 1.8 - 1.8 - - - - - org.apache.maven.plugins - maven-surefire-plugin - - 3 - true - - **/*IntegrationTest.java - **/*LiveTest.java - - - - - - - diff --git a/java-difference-date/pom.xml b/java-difference-date/pom.xml index ac3f0fa3b5..7a1ee5f1eb 100644 --- a/java-difference-date/pom.xml +++ b/java-difference-date/pom.xml @@ -36,22 +36,7 @@ - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.7.0 - - 1.8 - 1.8 - - - - - - 1.8 4.12 2.9.9 1.5.1 diff --git a/jee-7/src/main/java/com/baeldung/javaeeannotations/JavaEEAnnotationsSample/pom.xml b/jee-7/src/main/java/com/baeldung/javaeeannotations/JavaEEAnnotationsSample/pom.xml index de69efa43a..3c9dbcc5a5 100644 --- a/jee-7/src/main/java/com/baeldung/javaeeannotations/JavaEEAnnotationsSample/pom.xml +++ b/jee-7/src/main/java/com/baeldung/javaeeannotations/JavaEEAnnotationsSample/pom.xml @@ -6,7 +6,11 @@ war JavaEEAnnotationsSample JavaEEAnnotationsSample - + + com.baeldung + parent-modules + 1.0.0-SNAPSHOT + @@ -31,15 +35,6 @@ - - org.apache.maven.plugins - maven-compiler-plugin - 3.7.0 - - 1.8 - 1.8 - - org.apache.maven.plugins maven-war-plugin diff --git a/jpa-storedprocedure/pom.xml b/jpa-storedprocedure/pom.xml index cbda37a7b3..a054994fcb 100644 --- a/jpa-storedprocedure/pom.xml +++ b/jpa-storedprocedure/pom.xml @@ -19,7 +19,6 @@ 5.2.5.Final 6.0.5 2.5 - 2.19.1 diff --git a/jsonb/pom.xml b/jsonb/pom.xml index 03f4f227b1..63dc331f7a 100644 --- a/jsonb/pom.xml +++ b/jsonb/pom.xml @@ -99,7 +99,6 @@ 1.8 1.0.0 5.0.0 - 2.20 1.0 1.1.3 1.0 diff --git a/libraries-data/pom.xml b/libraries-data/pom.xml index 55bf02ae16..d19d03b3ff 100644 --- a/libraries-data/pom.xml +++ b/libraries-data/pom.xml @@ -89,15 +89,6 @@ - - org.apache.maven.plugins - maven-compiler-plugin - ${maven-compiler-plugin.version} - - 1.8 - 1.8 - - diff --git a/libraries/pom.xml b/libraries/pom.xml index 71a520e20e..c036c591ca 100644 --- a/libraries/pom.xml +++ b/libraries/pom.xml @@ -791,7 +791,6 @@ - maven-compiler-plugin @@ -838,7 +837,6 @@ - diff --git a/linkrest/pom.xml b/linkrest/pom.xml index 819436236f..1dac87c4e9 100644 --- a/linkrest/pom.xml +++ b/linkrest/pom.xml @@ -35,14 +35,6 @@ - - maven-compiler-plugin - 3.7.0 - - 1.8 - 1.8 - - maven-war-plugin 2.6 diff --git a/mustache/pom.xml b/mustache/pom.xml index 1c64dbdb0b..5e40402cbc 100644 --- a/mustache/pom.xml +++ b/mustache/pom.xml @@ -71,24 +71,7 @@ org.springframework.boot spring-boot-maven-plugin - - org.apache.maven.plugins - maven-surefire-plugin - ${maven-surefire-plugin.version} - - 3 - true - - **/*IntegrationTest.java - **/*LongRunningUnitTest.java - **/*ManualTest.java - **/JdbcTest.java - **/*LiveTest.java - - - - diff --git a/out/production/main180/com/baeldung/javaeeannotations/JavaEEAnnotationsSample/pom.xml b/out/production/main180/com/baeldung/javaeeannotations/JavaEEAnnotationsSample/pom.xml index de69efa43a..89ea844fc8 100644 --- a/out/production/main180/com/baeldung/javaeeannotations/JavaEEAnnotationsSample/pom.xml +++ b/out/production/main180/com/baeldung/javaeeannotations/JavaEEAnnotationsSample/pom.xml @@ -31,15 +31,6 @@ - - org.apache.maven.plugins - maven-compiler-plugin - 3.7.0 - - 1.8 - 1.8 - - org.apache.maven.plugins maven-war-plugin diff --git a/patterns/behavioral-patterns/pom.xml b/patterns/behavioral-patterns/pom.xml index 3c40520ce1..11170b70bc 100644 --- a/patterns/behavioral-patterns/pom.xml +++ b/patterns/behavioral-patterns/pom.xml @@ -20,15 +20,6 @@ test - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.7.0 - - - UTF-8 1.8 diff --git a/patterns/facade/README.md b/patterns/facade/README.md new file mode 100644 index 0000000000..cb44bf4bc4 --- /dev/null +++ b/patterns/facade/README.md @@ -0,0 +1,2 @@ +### Relevant Articles: +- [Facade Design Pattern in Java](http://www.baeldung.com/java-facade-pattern) diff --git a/patterns/facade/pom.xml b/patterns/facade/pom.xml index ee46a2a80d..6b9bc739db 100644 --- a/patterns/facade/pom.xml +++ b/patterns/facade/pom.xml @@ -20,15 +20,6 @@ test - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.7.0 - - - UTF-8 1.8 diff --git a/patterns/front-controller/pom.xml b/patterns/front-controller/pom.xml index b746d5dc6c..c41e2f5e09 100644 --- a/patterns/front-controller/pom.xml +++ b/patterns/front-controller/pom.xml @@ -22,15 +22,6 @@ - - org.apache.maven.plugins - maven-compiler-plugin - 3.7.0 - - 1.8 - 1.8 - - org.apache.maven.plugins maven-war-plugin diff --git a/persistence-modules/liquibase/pom.xml b/persistence-modules/liquibase/pom.xml index a70483437f..bb5a3700b1 100644 --- a/persistence-modules/liquibase/pom.xml +++ b/persistence-modules/liquibase/pom.xml @@ -23,16 +23,6 @@ baeldung-liquibase-demo - - org.apache.maven.plugins - maven-compiler-plugin - 3.7.0 - - 1.8 - 1.8 - - - org.liquibase liquibase-maven-plugin diff --git a/persistence-modules/spring-hibernate-5/pom.xml b/persistence-modules/spring-hibernate-5/pom.xml index 86e952c0e4..5b244dfd63 100644 --- a/persistence-modules/spring-hibernate-5/pom.xml +++ b/persistence-modules/spring-hibernate-5/pom.xml @@ -149,32 +149,6 @@ true - - - - - org.apache.maven.plugins - maven-compiler-plugin - ${maven-compiler-plugin.version} - - 1.8 - 1.8 - - - - - org.apache.maven.plugins - maven-surefire-plugin - ${maven-surefire-plugin.version} - - - **/*IntegrationTest.java - - - - - - diff --git a/pom.xml b/pom.xml index 64744eb2da..f0cb72e4d0 100644 --- a/pom.xml +++ b/pom.xml @@ -64,6 +64,7 @@ core-java core-java-io core-java-8 + core-groovy core-java-concurrency diff --git a/resteasy/bin/pom.xml b/resteasy/bin/pom.xml index 2e1f839a55..f275bc814f 100644 --- a/resteasy/bin/pom.xml +++ b/resteasy/bin/pom.xml @@ -13,6 +13,12 @@ 2.5 1.6.1 + + + com.baeldung + resteasy-tutorial + 1.0 + RestEasyTutorial @@ -73,66 +79,5 @@ commons-io ${commons-io.version} - - - - - live - - - - org.apache.maven.plugins - maven-surefire-plugin - - - integration-test - - test - - - - **/*IntegrationTest.java - - - **/*LiveTest.java - - - - - - - json - - - - - org.codehaus.cargo - cargo-maven2-plugin - ${cargo-maven2-plugin.version} - - false - - - - start-server - pre-integration-test - - start - - - - stop-server - post-integration-test - - stop - - - - - - - - - \ No newline at end of file diff --git a/spring-5/src/main/java/com/baeldung/assertions/Car.java b/spring-5/src/main/java/com/baeldung/assertions/Car.java index 4e210dfaab..abff27f0b0 100644 --- a/spring-5/src/main/java/com/baeldung/assertions/Car.java +++ b/spring-5/src/main/java/com/baeldung/assertions/Car.java @@ -39,8 +39,8 @@ public class Car { // ... } - public void сhangeOilWithIsNull(String oil) { - Assert.isNull(oil, "oil must be null"); + public void replaceBattery(CarBattery carBattery) { + Assert.isNull(carBattery.getCharge(), "to replace battery the charge must be null"); // ... } @@ -99,7 +99,9 @@ public class Car { car.fuel(); car.сhangeOil("oil"); - car.сhangeOilWithIsNull(null); + + CarBattery carBattery = new CarBattery(); + car.replaceBattery(carBattery); car.сhangeEngine(new ToyotaEngine()); diff --git a/spring-5/src/main/java/com/baeldung/assertions/CarBattery.java b/spring-5/src/main/java/com/baeldung/assertions/CarBattery.java new file mode 100644 index 0000000000..a75457a7ec --- /dev/null +++ b/spring-5/src/main/java/com/baeldung/assertions/CarBattery.java @@ -0,0 +1,13 @@ +package com.baeldung.assertions; + +public class CarBattery { + private String charge; + + public String getCharge() { + return charge; + } + + public void setCharge(String charge) { + this.charge = charge; + } +} diff --git a/spring-boot-bootstrap/pom.xml b/spring-boot-bootstrap/pom.xml index ad2512846b..07466c76f2 100644 --- a/spring-boot-bootstrap/pom.xml +++ b/spring-boot-bootstrap/pom.xml @@ -86,15 +86,6 @@ - - - - org.springframework.boot - spring-boot-maven-plugin - - - - integration diff --git a/spring-cloud/spring-cloud-aws/pom.xml b/spring-cloud/spring-cloud-aws/pom.xml index b27b6c0d18..28f04cd435 100644 --- a/spring-cloud/spring-cloud-aws/pom.xml +++ b/spring-cloud/spring-cloud-aws/pom.xml @@ -70,12 +70,7 @@ - - - org.springframework.boot - spring-boot-maven-plugin - - + maven-surefire-plugin diff --git a/spring-cloud/spring-cloud-bootstrap/gateway/pom.xml b/spring-cloud/spring-cloud-bootstrap/gateway/pom.xml index f32de88076..566fbb2a42 100644 --- a/spring-cloud/spring-cloud-bootstrap/gateway/pom.xml +++ b/spring-cloud/spring-cloud-bootstrap/gateway/pom.xml @@ -69,24 +69,6 @@ org.springframework.boot spring-boot-maven-plugin - - org.apache.maven.plugins - maven-compiler-plugin - ${maven-compiler-plugin.version} - - 1.8 - 1.8 - - - - org.apache.maven.plugins - maven-surefire-plugin - - - **/*LiveTest.java - - - maven-antrun-plugin diff --git a/spring-cloud/spring-cloud-connectors-heroku/pom.xml b/spring-cloud/spring-cloud-connectors-heroku/pom.xml index 83e8e360c8..f0154d5b36 100644 --- a/spring-cloud/spring-cloud-connectors-heroku/pom.xml +++ b/spring-cloud/spring-cloud-connectors-heroku/pom.xml @@ -61,13 +61,8 @@ Brixton.SR7 - - - org.springframework.boot - spring-boot-maven-plugin - org.apache.maven.plugins maven-surefire-plugin @@ -85,16 +80,6 @@ true - - org.apache.maven.plugins - maven-compiler-plugin - 3.7.0 - - 1.8 - 1.8 - - - \ No newline at end of file diff --git a/spring-cloud/spring-cloud-consul/pom.xml b/spring-cloud/spring-cloud-consul/pom.xml index 7ce570d50d..fe791071c0 100644 --- a/spring-cloud/spring-cloud-consul/pom.xml +++ b/spring-cloud/spring-cloud-consul/pom.xml @@ -34,25 +34,4 @@ 1.3.0.RELEASE - - - - - - org.apache.maven.plugins - maven-compiler-plugin - ${maven-compiler-plugin.version} - - 1.8 - 1.8 - - - - org.springframework.boot - spring-boot-maven-plugin - ${spring-boot-maven-plugin.version} - - - - diff --git a/spring-cloud/spring-cloud-contract/spring-cloud-contract-consumer/pom.xml b/spring-cloud/spring-cloud-contract/spring-cloud-contract-consumer/pom.xml index 67fea178eb..b80f453106 100644 --- a/spring-cloud/spring-cloud-contract/spring-cloud-contract-consumer/pom.xml +++ b/spring-cloud/spring-cloud-contract/spring-cloud-contract-consumer/pom.xml @@ -54,15 +54,4 @@ test - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - - diff --git a/spring-cloud/spring-cloud-eureka/pom.xml b/spring-cloud/spring-cloud-eureka/pom.xml index e90609c48d..01b1f45e1e 100644 --- a/spring-cloud/spring-cloud-eureka/pom.xml +++ b/spring-cloud/spring-cloud-eureka/pom.xml @@ -29,25 +29,4 @@ 3.7.0 1.4.2.RELEASE - - - - - - org.apache.maven.plugins - maven-compiler-plugin - ${maven-compiler-plugin.version} - - 1.8 - 1.8 - - - - org.springframework.boot - spring-boot-maven-plugin - ${spring-boot-maven-plugin.version} - - - - diff --git a/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-client/pom.xml b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-client/pom.xml index cd363ffef1..bf0167fd00 100644 --- a/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-client/pom.xml +++ b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-client/pom.xml @@ -43,24 +43,6 @@ - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.7.0 - - 1.8 - 1.8 - - - - org.springframework.boot - spring-boot-maven-plugin - - - - Brixton.SR7 1.2.3.RELEASE diff --git a/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client/pom.xml b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client/pom.xml index 038a0ab81d..54e1beb349 100644 --- a/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client/pom.xml +++ b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client/pom.xml @@ -53,24 +53,6 @@ - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.7.0 - - 1.8 - 1.8 - - - - org.springframework.boot - spring-boot-maven-plugin - - - - Brixton.SR7 1.2.3.RELEASE diff --git a/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-server/pom.xml b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-server/pom.xml index e4bae32011..ecd6a79e7e 100644 --- a/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-server/pom.xml +++ b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-server/pom.xml @@ -37,25 +37,7 @@ - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.7.0 - - 1.8 - 1.8 - - - - org.springframework.boot - spring-boot-maven-plugin - - - - + Brixton.SR7 1.2.3.RELEASE diff --git a/spring-cloud/spring-cloud-gateway/pom.xml b/spring-cloud/spring-cloud-gateway/pom.xml index 90737f369d..0592af8b03 100644 --- a/spring-cloud/spring-cloud-gateway/pom.xml +++ b/spring-cloud/spring-cloud-gateway/pom.xml @@ -75,25 +75,4 @@ - - - - - - org.apache.maven.plugins - maven-compiler-plugin - ${maven-compiler-plugin.version} - - 1.8 - 1.8 - - - - org.springframework.boot - spring-boot-maven-plugin - ${spring-boot-maven-plugin.version} - - - - diff --git a/spring-cloud/spring-cloud-hystrix/feign-rest-consumer/pom.xml b/spring-cloud/spring-cloud-hystrix/feign-rest-consumer/pom.xml index 5913b60a01..ce6e743f5c 100644 --- a/spring-cloud/spring-cloud-hystrix/feign-rest-consumer/pom.xml +++ b/spring-cloud/spring-cloud-hystrix/feign-rest-consumer/pom.xml @@ -66,25 +66,7 @@ - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.7.0 - - 1.8 - 1.8 - - - - org.springframework.boot - spring-boot-maven-plugin - - - - + 1.2.3.RELEASE 1.2.3.RELEASE diff --git a/spring-cloud/spring-cloud-hystrix/pom.xml b/spring-cloud/spring-cloud-hystrix/pom.xml index 9a6af9a790..5bfbba5a14 100644 --- a/spring-cloud/spring-cloud-hystrix/pom.xml +++ b/spring-cloud/spring-cloud-hystrix/pom.xml @@ -28,25 +28,4 @@ 3.7.0 1.4.2.RELEASE - - - - - - org.apache.maven.plugins - maven-compiler-plugin - ${maven-compiler-plugin.version} - - 1.8 - 1.8 - - - - org.springframework.boot - spring-boot-maven-plugin - ${spring-boot-maven-plugin.version} - - - - diff --git a/spring-cloud/spring-cloud-hystrix/rest-consumer/pom.xml b/spring-cloud/spring-cloud-hystrix/rest-consumer/pom.xml index 46e408d339..d2e1bc5b08 100644 --- a/spring-cloud/spring-cloud-hystrix/rest-consumer/pom.xml +++ b/spring-cloud/spring-cloud-hystrix/rest-consumer/pom.xml @@ -56,25 +56,7 @@ - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.7.0 - - 1.8 - 1.8 - - - - org.springframework.boot - spring-boot-maven-plugin - - - - + Brixton.SR7 1.2.3.RELEASE diff --git a/spring-cloud/spring-cloud-hystrix/rest-producer/pom.xml b/spring-cloud/spring-cloud-hystrix/rest-producer/pom.xml index 804ef2eb29..f491175982 100644 --- a/spring-cloud/spring-cloud-hystrix/rest-producer/pom.xml +++ b/spring-cloud/spring-cloud-hystrix/rest-producer/pom.xml @@ -24,25 +24,7 @@ ${spring-boot-starter-web.version} - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.7.0 - - 1.8 - 1.8 - - - - org.springframework.boot - spring-boot-maven-plugin - - - - + Brixton.SR7 diff --git a/spring-cloud/spring-cloud-stream/pom.xml b/spring-cloud/spring-cloud-stream/pom.xml index 65a327e664..65b343d46f 100644 --- a/spring-cloud/spring-cloud-stream/pom.xml +++ b/spring-cloud/spring-cloud-stream/pom.xml @@ -47,25 +47,4 @@ - - - - - - org.apache.maven.plugins - maven-compiler-plugin - ${maven-compiler-plugin.version} - - 1.8 - 1.8 - - - - org.springframework.boot - spring-boot-maven-plugin - ${spring-boot-maven-plugin.version} - - - - diff --git a/spring-cloud/spring-cloud-zuul-eureka-integration/bin/eureka-client/pom.xml b/spring-cloud/spring-cloud-zuul-eureka-integration/bin/eureka-client/pom.xml index a3185a44d4..978a804819 100644 --- a/spring-cloud/spring-cloud-zuul-eureka-integration/bin/eureka-client/pom.xml +++ b/spring-cloud/spring-cloud-zuul-eureka-integration/bin/eureka-client/pom.xml @@ -42,24 +42,6 @@ - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.7.0 - - 1.8 - 1.8 - - - - org.springframework.boot - spring-boot-maven-plugin - - - - Brixton.SR7 1.2.3.RELEASE diff --git a/spring-cloud/spring-cloud-zuul-eureka-integration/bin/eureka-server/pom.xml b/spring-cloud/spring-cloud-zuul-eureka-integration/bin/eureka-server/pom.xml index d86cfa8589..8204b1f42a 100644 --- a/spring-cloud/spring-cloud-zuul-eureka-integration/bin/eureka-server/pom.xml +++ b/spring-cloud/spring-cloud-zuul-eureka-integration/bin/eureka-server/pom.xml @@ -42,25 +42,6 @@ - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.7.0 - - 1.8 - 1.8 - - - - org.springframework.boot - spring-boot-maven-plugin - - - - Brixton.SR7 1.2.3.RELEASE diff --git a/spring-cloud/spring-cloud-zuul-eureka-integration/bin/pom.xml b/spring-cloud/spring-cloud-zuul-eureka-integration/bin/pom.xml index fabad77a77..f9def34004 100644 --- a/spring-cloud/spring-cloud-zuul-eureka-integration/bin/pom.xml +++ b/spring-cloud/spring-cloud-zuul-eureka-integration/bin/pom.xml @@ -27,26 +27,6 @@ 1.10 - - - - - org.apache.maven.plugins - maven-compiler-plugin - ${maven-compiler-plugin.version} - - 1.8 - 1.8 - - - - org.springframework.boot - spring-boot-maven-plugin - ${spring-boot-maven-plugin.version} - - - - zuul-server eureka-server diff --git a/spring-cloud/spring-cloud-zuul-eureka-integration/bin/zuul-server/pom.xml b/spring-cloud/spring-cloud-zuul-eureka-integration/bin/zuul-server/pom.xml index 2622a3e36b..d423ed8fe2 100644 --- a/spring-cloud/spring-cloud-zuul-eureka-integration/bin/zuul-server/pom.xml +++ b/spring-cloud/spring-cloud-zuul-eureka-integration/bin/zuul-server/pom.xml @@ -41,21 +41,4 @@ - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.7.0 - - 1.8 - 1.8 - - - - org.springframework.boot - spring-boot-maven-plugin - - - \ No newline at end of file diff --git a/spring-cloud/spring-cloud-zuul-eureka-integration/eureka-client/pom.xml b/spring-cloud/spring-cloud-zuul-eureka-integration/eureka-client/pom.xml index a3185a44d4..978a804819 100644 --- a/spring-cloud/spring-cloud-zuul-eureka-integration/eureka-client/pom.xml +++ b/spring-cloud/spring-cloud-zuul-eureka-integration/eureka-client/pom.xml @@ -42,24 +42,6 @@ - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.7.0 - - 1.8 - 1.8 - - - - org.springframework.boot - spring-boot-maven-plugin - - - - Brixton.SR7 1.2.3.RELEASE diff --git a/spring-cloud/spring-cloud-zuul-eureka-integration/eureka-server/pom.xml b/spring-cloud/spring-cloud-zuul-eureka-integration/eureka-server/pom.xml index d86cfa8589..8005db761b 100644 --- a/spring-cloud/spring-cloud-zuul-eureka-integration/eureka-server/pom.xml +++ b/spring-cloud/spring-cloud-zuul-eureka-integration/eureka-server/pom.xml @@ -43,24 +43,6 @@ - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.7.0 - - 1.8 - 1.8 - - - - org.springframework.boot - spring-boot-maven-plugin - - - - Brixton.SR7 1.2.3.RELEASE diff --git a/spring-cloud/spring-cloud-zuul-eureka-integration/pom.xml b/spring-cloud/spring-cloud-zuul-eureka-integration/pom.xml index b4c7188abe..773d9af758 100644 --- a/spring-cloud/spring-cloud-zuul-eureka-integration/pom.xml +++ b/spring-cloud/spring-cloud-zuul-eureka-integration/pom.xml @@ -28,26 +28,6 @@ 1.2.10 - - - - - org.apache.maven.plugins - maven-compiler-plugin - ${maven-compiler-plugin.version} - - 1.8 - 1.8 - - - - org.springframework.boot - spring-boot-maven-plugin - ${spring-boot-maven-plugin.version} - - - - zuul-server eureka-server diff --git a/spring-cloud/spring-cloud-zuul-eureka-integration/zuul-server/pom.xml b/spring-cloud/spring-cloud-zuul-eureka-integration/zuul-server/pom.xml index b68fd63155..1600681239 100644 --- a/spring-cloud/spring-cloud-zuul-eureka-integration/zuul-server/pom.xml +++ b/spring-cloud/spring-cloud-zuul-eureka-integration/zuul-server/pom.xml @@ -46,21 +46,4 @@ - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.7.0 - - 1.8 - 1.8 - - - - org.springframework.boot - spring-boot-maven-plugin - - - \ No newline at end of file diff --git a/spring-mvc-simple/pom.xml b/spring-mvc-simple/pom.xml index 4e7f39bad3..31b57c496f 100644 --- a/spring-mvc-simple/pom.xml +++ b/spring-mvc-simple/pom.xml @@ -7,11 +7,13 @@ 0.0.1-SNAPSHOT Spring MVC simple Maven Webapp http://maven.apache.org + com.baeldung parent-modules 1.0.0-SNAPSHOT + 1.8 1.8 @@ -164,11 +166,6 @@ ${deploy-path} - - org.apache.maven.plugins - maven-compiler-plugin - ${maven.compiler.version} - maven-surefire-plugin ${maven-surefire-plugin.version} diff --git a/spring-security-mvc-socket/pom.xml b/spring-security-mvc-socket/pom.xml index 1bc295a778..382f141483 100644 --- a/spring-security-mvc-socket/pom.xml +++ b/spring-security-mvc-socket/pom.xml @@ -154,14 +154,6 @@ - - maven-compiler-plugin - 3.7.0 - - 1.8 - 1.8 - - org.apache.tomcat.maven tomcat7-maven-plugin diff --git a/spring-swagger-codegen/spring-swagger-codegen-api-client/pom.xml b/spring-swagger-codegen/spring-swagger-codegen-api-client/pom.xml index 61df37ad57..265ca1ec26 100644 --- a/spring-swagger-codegen/spring-swagger-codegen-api-client/pom.xml +++ b/spring-swagger-codegen/spring-swagger-codegen-api-client/pom.xml @@ -120,15 +120,6 @@ - - org.apache.maven.plugins - maven-compiler-plugin - 3.7.0 - - 1.8 - 1.8 - - org.apache.maven.plugins maven-javadoc-plugin diff --git a/testing-modules/junit-5/pom.xml b/testing-modules/junit-5/pom.xml index 28a29d8545..87e424e0da 100644 --- a/testing-modules/junit-5/pom.xml +++ b/testing-modules/junit-5/pom.xml @@ -41,14 +41,6 @@ - - maven-compiler-plugin - ${maven-compiler-plugin.version} - - ${java.version} - ${java.version} - - maven-surefire-plugin ${maven-surefire-plugin.version} diff --git a/testing-modules/mocks/mock-comparisons/src/main/java/com/baeldung/easymock/IUserService.java b/testing-modules/mocks/mock-comparisons/src/main/java/com/baeldung/easymock/IUserService.java new file mode 100644 index 0000000000..4bb74abb64 --- /dev/null +++ b/testing-modules/mocks/mock-comparisons/src/main/java/com/baeldung/easymock/IUserService.java @@ -0,0 +1,11 @@ +package com.baeldung.easymock; + +import java.util.List; + +public interface IUserService { + public boolean addUser(User user); + public List findByFirstName(String firstName); + public List findByLastName(String lastName); + public List findByAge(double age); + public List findByEmail(String email); +} diff --git a/testing-modules/mocks/mock-comparisons/src/main/java/com/baeldung/easymock/User.java b/testing-modules/mocks/mock-comparisons/src/main/java/com/baeldung/easymock/User.java new file mode 100644 index 0000000000..e5ef460e49 --- /dev/null +++ b/testing-modules/mocks/mock-comparisons/src/main/java/com/baeldung/easymock/User.java @@ -0,0 +1,109 @@ +package com.baeldung.easymock; + +public class User { + private long id; + private String firstName; + private String lastName; + private double age; + private String email; + + public User() { + super(); + } + + public User(String firstName, String lastName) { + super(); + this.firstName = firstName; + this.lastName = lastName; + } + + // + + public long getId() { + return id; + } + public void setId(long id) { + this.id = id; + } + public String getFirstName() { + return firstName; + } + public void setFirstName(String firstName) { + this.firstName = firstName; + } + public String getLastName() { + return lastName; + } + public void setLastName(String lastName) { + this.lastName = lastName; + } + public double getAge() { + return age; + } + public void setAge(double age) { + this.age = age; + } + public String getEmail() { + return email; + } + public void setEmail(String email) { + this.email = email; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + long temp; + temp = Double.doubleToLongBits(age); + result = prime * result + (int) (temp ^ (temp >>> 32)); + result = prime * result + ((email == null) ? 0 : email.hashCode()); + result = prime * result + ((firstName == null) ? 0 : firstName.hashCode()); + result = prime * result + (int) (id ^ (id >>> 32)); + result = prime * result + ((lastName == null) ? 0 : lastName.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + User other = (User) obj; + if (Double.doubleToLongBits(age) != Double.doubleToLongBits(other.age)) { + return false; + } + if (email == null) { + if (other.email != null) { + return false; + } + } else if (!email.equals(other.email)) { + return false; + } + if (firstName == null) { + if (other.firstName != null) { + return false; + } + } else if (!firstName.equals(other.firstName)) { + return false; + } + if (id != other.id) { + return false; + } + if (lastName == null) { + if (other.lastName != null) { + return false; + } + } else if (!lastName.equals(other.lastName)) { + return false; + } + return true; + } + +} diff --git a/testing-modules/mocks/mock-comparisons/src/test/java/com/baeldung/easymock/ArgumentMatchersUnitTest.java b/testing-modules/mocks/mock-comparisons/src/test/java/com/baeldung/easymock/ArgumentMatchersUnitTest.java new file mode 100644 index 0000000000..6d4f4c09f5 --- /dev/null +++ b/testing-modules/mocks/mock-comparisons/src/test/java/com/baeldung/easymock/ArgumentMatchersUnitTest.java @@ -0,0 +1,220 @@ +package com.baeldung.easymock; + +import static org.easymock.EasyMock.and; +import static org.easymock.EasyMock.anyString; +import static org.easymock.EasyMock.contains; +import static org.easymock.EasyMock.endsWith; +import static org.easymock.EasyMock.eq; +import static org.easymock.EasyMock.expect; +import static org.easymock.EasyMock.geq; +import static org.easymock.EasyMock.gt; +import static org.easymock.EasyMock.isA; +import static org.easymock.EasyMock.isNull; +import static org.easymock.EasyMock.lt; +import static org.easymock.EasyMock.matches; +import static org.easymock.EasyMock.mock; +import static org.easymock.EasyMock.not; +import static org.easymock.EasyMock.notNull; +import static org.easymock.EasyMock.replay; +import static org.easymock.EasyMock.same; +import static org.easymock.EasyMock.startsWith; +import static org.easymock.EasyMock.verify; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.util.Collections; +import java.util.List; + +import org.easymock.EasyMock; +import org.easymock.IArgumentMatcher; +import org.junit.Test; + +public class ArgumentMatchersUnitTest { + + private IUserService userService = mock(IUserService.class); + + //====================== equals + @Test + public void givenUserService_whenAddNewUser_thenOK() { + expect(userService.addUser(eq(new User()))).andReturn(true); + replay(userService); + + boolean result = userService.addUser(new User()); + verify(userService); + assertTrue(result); + } + + //================ same + @Test + public void givenUserService_whenAddSpecificUser_thenOK() { + User user = new User(); + + expect(userService.addUser(same(user))).andReturn(true); + replay(userService); + + boolean result = userService.addUser(user); + verify(userService); + assertTrue(result); + } + + //============= anyX + @Test + public void givenUserService_whenSearchForUserByFirstName_thenFound() { + expect(userService.findByFirstName(anyString())).andReturn(Collections.emptyList()); + replay(userService); + + List result = userService.findByFirstName("joe"); + verify(userService); + assertEquals(0,result.size()); + } + + //================= isA + @Test + public void givenUserService_whenAddUser_thenOK() { + expect(userService.addUser(isA(User.class))).andReturn(true); + replay(userService); + + boolean result = userService.addUser(new User()); + verify(userService); + assertTrue(result); + } + + //=================== null, not null + @Test + public void givenUserService_whenAddNull_thenFail() { + expect(userService.addUser(isNull())).andReturn(false); + replay(userService); + + boolean result = userService.addUser(null); + verify(userService); + assertFalse(result); + } + + @Test + public void givenUserService_whenAddNotNull_thenOK() { + expect(userService.addUser(notNull())).andReturn(true); + replay(userService); + + boolean result = userService.addUser(new User()); + verify(userService); + assertTrue(result); + } + + // number less,great + @Test + public void givenUserService_whenSearchForUserByAgeLessThan_thenFound() { + expect(userService.findByAge(lt(100.0))).andReturn(Collections.emptyList()); + replay(userService); + + List result = userService.findByAge(20); + verify(userService); + assertEquals(0,result.size()); + } + + @Test + public void givenUserService_whenSearchForUserByAgeGreaterThan_thenFound() { + expect(userService.findByAge(geq(10.0))).andReturn(Collections.emptyList()); + replay(userService); + + List result = userService.findByAge(20); + verify(userService); + assertEquals(0,result.size()); + } + + //=============== string + //=============== start + @Test + public void givenUserService_whenSearchForUserByEmailStartsWith_thenFound() { + expect(userService.findByEmail(startsWith("test"))).andReturn(Collections.emptyList()); + replay(userService); + + List result = userService.findByEmail("test@example.com"); + verify(userService); + assertEquals(0,result.size()); + } + + //==================end + @Test + public void givenUserService_whenSearchForUserByEmailEndsWith_thenFound() { + expect(userService.findByEmail(endsWith(".com"))).andReturn(Collections.emptyList()); + replay(userService); + + List result = userService.findByEmail("test@example.com"); + verify(userService); + assertEquals(0,result.size()); + } + + //=================contain + @Test + public void givenUserService_whenSearchForUserByEmailContains_thenFound() { + expect(userService.findByEmail(contains("@"))).andReturn(Collections.emptyList()); + replay(userService); + + List result = userService.findByEmail("test@example.com"); + verify(userService); + assertEquals(0,result.size()); + } + + //==================matches + @Test + public void givenUserService_whenSearchForUserByEmailMatches_thenFound() { + expect(userService.findByEmail(matches(".+\\@.+\\..+"))).andReturn(Collections.emptyList()); + replay(userService); + + List result = userService.findByEmail("test@example.com"); + verify(userService); + assertEquals(0,result.size()); + } + + //================== combine and, or, not + @Test + public void givenUserService_whenSearchForUserByAgeRange_thenFound() { + expect(userService.findByAge(and(gt(10.0),lt(100.0)))).andReturn(Collections.emptyList()); + replay(userService); + + List result = userService.findByAge(20); + verify(userService); + assertEquals(0,result.size()); + } + + @Test + public void givenUserService_whenSearchForUserByEmailNotEndsWith_thenFound() { + expect(userService.findByEmail(not(endsWith(".com")))).andReturn(Collections.emptyList()); + replay(userService); + + List result = userService.findByEmail("test@example.org"); + verify(userService); + assertEquals(0,result.size()); + } + + //================ custom matcher + + @Test + public void givenUserService_whenSearchForUserByLastName_thenFound() { + expect(userService.findByLastName(charCount(3))).andReturn(Collections.emptyList()); + replay(userService); + + List result = userService.findByLastName("doe"); + verify(userService); + assertEquals(0,result.size()); + } + + public static String charCount(int value){ + EasyMock.reportMatcher(new IArgumentMatcher() { + @Override + public boolean matches(Object argument) { + return argument instanceof String + && ((String) argument).length() == value; + } + + @Override + public void appendTo(StringBuffer buffer) { + buffer.append("charCount(\"" + value + "\")"); + } + }); + return null; + } +} + + diff --git a/testing-modules/mockserver/pom.xml b/testing-modules/mockserver/pom.xml index 8d3e97f129..7f2d85e4c0 100644 --- a/testing-modules/mockserver/pom.xml +++ b/testing-modules/mockserver/pom.xml @@ -7,6 +7,12 @@ com.baeldung mockserver 1.0.0-SNAPSHOT + + com.baeldung + parent-modules + 1.0.0-SNAPSHOT + ../../ + 3.10.8 4.4.1 @@ -35,20 +41,5 @@ httpcore ${apche-http-version} - - - - - maven-surefire-plugin - 2.20 - - - **/**LiveTest.java - - - - - - \ No newline at end of file diff --git a/vavr/pom.xml b/vavr/pom.xml index 28747af3ee..f6733d229c 100644 --- a/vavr/pom.xml +++ b/vavr/pom.xml @@ -65,28 +65,7 @@ http://repo.spring.io/snapshot - - - - - org.apache.maven.plugins - maven-surefire-plugin - ${maven-surefire-plugin.version} - - 3 - true - - **/*IntegrationTest.java - **/*LongRunningUnitTest.java - **/*ManualTest.java - **/JdbcTest.java - **/*LiveTest.java - - - - - - + 1.8 0.9.1 diff --git a/vraptor/pom.xml b/vraptor/pom.xml index e90f286630..59e5eb645c 100644 --- a/vraptor/pom.xml +++ b/vraptor/pom.xml @@ -116,15 +116,6 @@ vraptor src/main/webapp/WEB-INF/classes - - org.apache.maven.plugins - maven-compiler-plugin - 3.7.0 - - 1.8 - 1.8 - - org.apache.tomcat.maven tomcat7-maven-plugin diff --git a/xml/pom.xml b/xml/pom.xml index 66c17a4f33..c001c264d2 100644 --- a/xml/pom.xml +++ b/xml/pom.xml @@ -156,16 +156,6 @@ - - org.apache.maven.plugins - maven-compiler-plugin - 3.7.0 - - ${java-version} - ${java-version} - - - org.apache.maven.plugins maven-surefire-plugin