forked from eugenp/tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into BAEL-16633
- Loading branch information
Showing
262 changed files
with
2,520 additions
and
4,027 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
code-generation/src/main/java/com/baeldung/autovalue/Person.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
code-generation/src/test/java/com/baeldung/autovalue/PersonUnitTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
...vy/com/baeldung/lists/ListUnitTest.groovy → ...com/baeldung/find/ListFindUnitTest.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 3 additions & 81 deletions
84
...roovy/com/baeldung/map/MapUnitTest.groovy → .../com/baeldung/find/MapFindUnitTest.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...rc/main/groovy/com/baeldung/Person.groovy → ...st/groovy/com/baeldung/find/Person.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
4 changes: 2 additions & 2 deletions
4
...roovy/com/baeldung/set/SetUnitTest.groovy → .../com/baeldung/find/SetFindUnitTest.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
core-groovy-collections/src/test/groovy/com/baeldung/iteratemap/IterateMapUnitTest.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
...groovy/com/baeldung/lists/ListTest.groovy → ...vy/com/baeldung/lists/ListUnitTest.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...st/groovy/com/baeldung/map/MapTest.groovy → ...t/groovy/com/baeldung/maps/MapTest.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.