Skip to content

Commit

Permalink
Merge branch 'master' into BAEL-16633
Browse files Browse the repository at this point in the history
  • Loading branch information
alessiostalla committed Oct 29, 2019
2 parents 0e37289 + 18c6a1a commit 4bdc333
Show file tree
Hide file tree
Showing 262 changed files with 2,520 additions and 4,027 deletions.
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,10 @@ software-security/sql-injection-samples/derby.log
spring-soap/src/main/java/com/baeldung/springsoap/gen/
/report-*.json
transaction.log
*-shell.log
*-shell.log

apache-cxf/cxf-aegis/baeldung.xml
apache-fop/src/test/resources/input.xml
apache-fop/src/test/resources/output_herold.pdf
apache-fop/src/test/resources/output_html2fo.pdf
apache-fop/src/test/resources/output_jtidy.pdf
1,674 changes: 0 additions & 1,674 deletions apache-fop/src/test/resources/input.xml

This file was deleted.

Binary file removed apache-fop/src/test/resources/output_herold.pdf
Binary file not shown.
Binary file removed apache-fop/src/test/resources/output_html2fo.pdf
Binary file not shown.
Binary file removed apache-fop/src/test/resources/output_jtidy.pdf
Binary file not shown.
12 changes: 9 additions & 3 deletions code-generation/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,16 @@
</parent>

<dependencies>
<dependency>
<groupId>com.google.auto.value</groupId>
<artifactId>auto-value-annotations</artifactId>
<version>${auto-value.version}</version>
</dependency>
<dependency>
<groupId>com.google.auto.value</groupId>
<artifactId>auto-value</artifactId>
<version>${auto-value.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.auto.factory</groupId>
Expand Down Expand Up @@ -43,9 +49,9 @@
</dependencies>

<properties>
<auto-value.version>1.3</auto-value.version>
<auto-factory.version>1.0-beta5</auto-factory.version>
<auto-service.version>1.0-rc5</auto-service.version>
<auto-value.version>1.6.6</auto-value.version>
<auto-factory.version>1.0-beta6</auto-factory.version>
<auto-service.version>1.0-rc6</auto-service.version>
<guice.version>4.2.0</guice.version>
</properties>

Expand Down
38 changes: 38 additions & 0 deletions code-generation/src/main/java/com/baeldung/autovalue/Person.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.baeldung.autovalue;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import com.google.auto.value.AutoValue;

@AutoValue
public abstract class Person {

public abstract String name();

public abstract List<String> favoriteMovies();

public static Builder builder() {
return new AutoValue_Person.Builder();
}

@AutoValue.Builder
public static abstract class Builder {

public abstract Builder name(String value);

public abstract Builder favoriteMovies(List<String> value);

abstract List<String> favoriteMovies();

abstract Person autoBuild();

public Person build() {
List<String> favoriteMovies = favoriteMovies();
List<String> copy = Collections.unmodifiableList(new ArrayList<>(favoriteMovies));
favoriteMovies(copy);
return autoBuild();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.baeldung.autovalue;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;

import java.util.ArrayList;
import java.util.List;

import org.junit.Test;

/**
* Unit Test which verifies that the {@link Person} value object creates defensive copies of its favoriteMovies list.
*/
public class PersonUnitTest {

@Test
public void givenNewPerson_whenModifyOriginalList_thenValueObjectIsNotAlsoModified() {
// GIVEN new Person
List<String> originalFavoriteMoviesList = new ArrayList<String>();
originalFavoriteMoviesList.add("Training Day");
originalFavoriteMoviesList.add("Fast and the Furious");
Person person = Person.builder()
.name("Dan")
.favoriteMovies(originalFavoriteMoviesList)
.build();

// WHEN modify original list
originalFavoriteMoviesList.add("Friday");

// THEN Person remains unaffected
assertFalse(person.favoriteMovies()
.contains("Friday"));
assertEquals(2, person.favoriteMovies()
.size());
}

}
4 changes: 3 additions & 1 deletion core-groovy-collections/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ This module contains articles about Groovy core collections
## Relevant articles:

- [Maps in Groovy](https://www.baeldung.com/groovy-maps)

- [Finding Elements in Collections in Groovy](https://www.baeldung.com/groovy-collections-find-elements)
- [Lists in Groovy](https://www.baeldung.com/groovy-lists)
- [A Quick Guide to Iterating a Map in Groovy](https://www.baeldung.com/groovy-map-iterating)
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.baeldung.lists
package com.baeldung.find

import com.baeldung.Person
import com.baeldung.find.Person
import org.junit.Test

import static org.junit.Assert.*

class ListUnitTest {
class ListFindUnitTest {

private final personList = [
new Person("Regina", "Fitzpatrick", 25),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,96 +1,18 @@
package com.baeldung.map
package com.baeldung.find

import com.baeldung.Person
import com.baeldung.find.Person
import org.junit.Test

import static org.junit.Assert.*

class MapUnitTest {
class MapFindUnitTest {

private final personMap = [
Regina : new Person("Regina", "Fitzpatrick", 25),
Abagail: new Person("Abagail", "Ballard", 26),
Lucian : new Person("Lucian", "Walter", 30)
]

@Test
void whenUsingEach_thenMapIsIterated() {
def map = [
'FF0000' : 'Red',
'00FF00' : 'Lime',
'0000FF' : 'Blue',
'FFFF00' : 'Yellow'
]

map.each { println "Hex Code: $it.key = Color Name: $it.value" }
}

@Test
void whenUsingEachWithEntry_thenMapIsIterated() {
def map = [
'E6E6FA' : 'Lavender',
'D8BFD8' : 'Thistle',
'DDA0DD' : 'Plum',
]

map.each { entry -> println "Hex Code: $entry.key = Color Name: $entry.value" }
}

@Test
void whenUsingEachWithKeyAndValue_thenMapIsIterated() {
def map = [
'000000' : 'Black',
'FFFFFF' : 'White',
'808080' : 'Gray'
]

map.each { key, val ->
println "Hex Code: $key = Color Name $val"
}
}

@Test
void whenUsingEachWithIndexAndEntry_thenMapIsIterated() {
def map = [
'800080' : 'Purple',
'4B0082' : 'Indigo',
'6A5ACD' : 'Slate Blue'
]

map.eachWithIndex { entry, index ->
def indent = ((index == 0 || index % 2 == 0) ? " " : "")
println "$indent Hex Code: $entry.key = Color Name: $entry.value"
}
}

@Test
void whenUsingEachWithIndexAndKeyAndValue_thenMapIsIterated() {
def map = [
'FFA07A' : 'Light Salmon',
'FF7F50' : 'Coral',
'FF6347' : 'Tomato',
'FF4500' : 'Orange Red'
]

map.eachWithIndex { key, val, index ->
def indent = ((index == 0 || index % 2 == 0) ? " " : "")
println "$indent Hex Code: $key = Color Name: $val"
}
}

@Test
void whenUsingForLoop_thenMapIsIterated() {
def map = [
'2E8B57' : 'Seagreen',
'228B22' : 'Forest Green',
'008000' : 'Green'
]

for (entry in map) {
println "Hex Code: $entry.key = Color Name: $entry.value"
}
}

@Test
void whenMapContainsKeyElement_thenCheckReturnsTrue() {
def map = [a: 'd', b: 'e', c: 'f']
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.baeldung
package com.baeldung.find

class Person {
private String firstname
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.baeldung.set
package com.baeldung.find

import org.junit.Test

import static org.junit.Assert.assertTrue

class SetUnitTest {
class SetFindUnitTest {

@Test
void whenSetContainsElement_thenCheckReturnsTrue() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package com.baeldung.iteratemap

import com.baeldung.find.Person
import org.junit.Test

import static org.junit.Assert.*

class IterateMapUnitTest {

@Test
void whenUsingEach_thenMapIsIterated() {
def map = [
'FF0000' : 'Red',
'00FF00' : 'Lime',
'0000FF' : 'Blue',
'FFFF00' : 'Yellow'
]

map.each { println "Hex Code: $it.key = Color Name: $it.value" }
}

@Test
void whenUsingEachWithEntry_thenMapIsIterated() {
def map = [
'E6E6FA' : 'Lavender',
'D8BFD8' : 'Thistle',
'DDA0DD' : 'Plum',
]

map.each { entry -> println "Hex Code: $entry.key = Color Name: $entry.value" }
}

@Test
void whenUsingEachWithKeyAndValue_thenMapIsIterated() {
def map = [
'000000' : 'Black',
'FFFFFF' : 'White',
'808080' : 'Gray'
]

map.each { key, val ->
println "Hex Code: $key = Color Name $val"
}
}

@Test
void whenUsingEachWithIndexAndEntry_thenMapIsIterated() {
def map = [
'800080' : 'Purple',
'4B0082' : 'Indigo',
'6A5ACD' : 'Slate Blue'
]

map.eachWithIndex { entry, index ->
def indent = ((index == 0 || index % 2 == 0) ? " " : "")
println "$indent Hex Code: $entry.key = Color Name: $entry.value"
}
}

@Test
void whenUsingEachWithIndexAndKeyAndValue_thenMapIsIterated() {
def map = [
'FFA07A' : 'Light Salmon',
'FF7F50' : 'Coral',
'FF6347' : 'Tomato',
'FF4500' : 'Orange Red'
]

map.eachWithIndex { key, val, index ->
def indent = ((index == 0 || index % 2 == 0) ? " " : "")
println "$indent Hex Code: $key = Color Name: $val"
}
}

@Test
void whenUsingForLoop_thenMapIsIterated() {
def map = [
'2E8B57' : 'Seagreen',
'228B22' : 'Forest Green',
'008000' : 'Green'
]

for (entry in map) {
println "Hex Code: $entry.key = Color Name: $entry.value"
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.baeldung.groovy.lists
package com.baeldung.lists

import static groovy.test.GroovyAssert.*
import org.junit.Test

class ListTest{
class ListUnitTest {

@Test
void testCreateList() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.baeldung.map;
package com.baeldung.maps;

import static groovy.test.GroovyAssert.*
import org.junit.Test
Expand Down
3 changes: 0 additions & 3 deletions core-groovy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@ This module contains articles about core Groovy concepts
- [Working with JSON in Groovy](https://www.baeldung.com/groovy-json)
- [Reading a File in Groovy](https://www.baeldung.com/groovy-file-read)
- [Types of Strings in Groovy](https://www.baeldung.com/groovy-strings)
- [A Quick Guide to Iterating a Map in Groovy](https://www.baeldung.com/groovy-map-iterating)
- [An Introduction to Traits in Groovy](https://www.baeldung.com/groovy-traits)
- [Closures in Groovy](https://www.baeldung.com/groovy-closures)
- [Finding Elements in Collections in Groovy](https://www.baeldung.com/groovy-collections-find-elements)
- [Lists in Groovy](https://www.baeldung.com/groovy-lists)
- [Converting a String to a Date in Groovy](https://www.baeldung.com/groovy-string-to-date)
- [Guide to I/O in Groovy](https://www.baeldung.com/groovy-io)
- [[More -->]](/core-groovy-2)
Loading

0 comments on commit 4bdc333

Please sign in to comment.