commit
15e0ab6a62
@ -1,4 +1,4 @@
|
||||
package com.baeldung.list;
|
||||
package com.baeldung.list.duplicatescounter;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
@ -33,9 +33,9 @@ public class CollectionFilteringUnitTest {
|
||||
|
||||
for (Employee employee : originalList) {
|
||||
for (String name : nameFilter) {
|
||||
if (employee.getName()
|
||||
.equalsIgnoreCase(name)) {
|
||||
if (employee.getName().equals(name)) {
|
||||
filteredList.add(employee);
|
||||
//break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
package com.baeldung.list;
|
||||
package com.baeldung.list.duplicatescounter;
|
||||
|
||||
import org.assertj.core.util.Lists;
|
||||
import org.junit.jupiter.api.Test;
|
@ -11,148 +11,171 @@ import static org.junit.Assert.*;
|
||||
public class FileClassDemoUnitTest {
|
||||
|
||||
@Test
|
||||
public void givenDirectoryCreated_whenMkdirIsInvoked_thenDirectoryIsDeleted() {
|
||||
File directory = new File("testDirectory");
|
||||
if (!directory.isDirectory() || !directory.exists()) {
|
||||
directory.mkdir();
|
||||
}
|
||||
|
||||
public void givenDir_whenMkdir_thenDirIsDeleted() {
|
||||
File directory = new File("dir");
|
||||
assertTrue(directory.mkdir());
|
||||
assertTrue(directory.delete());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenFileCreated_whenCreateNewFileIsInvoked_thenFileIsDeleted() throws IOException {
|
||||
File file = new File("testFile.txt");
|
||||
if (!file.isFile() || !file.exists()) {
|
||||
file.createNewFile();
|
||||
public void givenFile_whenCreateNewFile_thenFileIsDeleted() {
|
||||
File file = new File("file.txt");
|
||||
try {
|
||||
assertTrue(file.createNewFile());
|
||||
} catch (IOException e) {
|
||||
fail("Could not create " + "file.txt");
|
||||
}
|
||||
|
||||
assertTrue(file.delete());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenFile_whenCreateNewFile_thenMetadataIsCorrect() {
|
||||
|
||||
String sep = File.separator;
|
||||
|
||||
File parentDir = makeDir("filesDir");
|
||||
|
||||
File child = new File(parentDir, "file.txt");
|
||||
try {
|
||||
child.createNewFile();
|
||||
} catch (IOException e) {
|
||||
fail("Could not create " + "file.txt");
|
||||
}
|
||||
|
||||
assertEquals("file.txt", child.getName());
|
||||
assertEquals(parentDir.getName(), child.getParentFile().getName());
|
||||
assertEquals(parentDir.getPath() + sep + "file.txt", child.getPath());
|
||||
|
||||
removeDir(parentDir);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void givenFileCreated_whenCreateNewFileInvoked_thenMetadataIsAsExpected() throws IOException {
|
||||
public void givenReadOnlyFile_whenCreateNewFile_thenCantModFile() {
|
||||
File parentDir = makeDir("readDir");
|
||||
|
||||
// different Operating systems have different separator characters
|
||||
String separatorCharacter = System.getProperty("file.separator");
|
||||
|
||||
File parentDirectory = makeDirectory("filesDirectory");
|
||||
|
||||
File childFile = new File(parentDirectory, "file1.txt");
|
||||
childFile.createNewFile();
|
||||
|
||||
assertTrue(childFile.getName().equals("file1.txt"));
|
||||
assertTrue(childFile.getParentFile().getName().equals(parentDirectory.getName()));
|
||||
assertTrue(childFile.getPath().equals(parentDirectory.getPath() + separatorCharacter + "file1.txt"));
|
||||
|
||||
removeDirectory(parentDirectory);
|
||||
}
|
||||
|
||||
|
||||
@Test(expected = FileNotFoundException.class)
|
||||
public void givenReadOnlyFileCreated_whenCreateNewFileInvoked_thenFileCannotBeWrittenTo() throws IOException {
|
||||
File parentDirectory = makeDirectory("filesDirectory");
|
||||
|
||||
File childFile = new File(parentDirectory, "file1.txt");
|
||||
childFile.createNewFile();
|
||||
|
||||
childFile.setWritable(false);
|
||||
|
||||
FileOutputStream fos = new FileOutputStream(childFile);
|
||||
fos.write("Hello World".getBytes()); // write operation
|
||||
fos.flush();
|
||||
fos.close();
|
||||
|
||||
removeDirectory(parentDirectory);
|
||||
}
|
||||
|
||||
@Test(expected = FileNotFoundException.class)
|
||||
public void givenWriteOnlyFileCreated_whenCreateNewFileInvoked_thenFileCannotBeReadFrom() throws IOException {
|
||||
File parentDirectory = makeDirectory("filesDirectory");
|
||||
|
||||
File childFile = new File(parentDirectory, "file1.txt");
|
||||
childFile.createNewFile();
|
||||
|
||||
childFile.setReadable(false);
|
||||
|
||||
FileInputStream fis = new FileInputStream(childFile);
|
||||
fis.read(); // read operation
|
||||
fis.close();
|
||||
|
||||
removeDirectory(parentDirectory);
|
||||
File child = new File(parentDir, "file.txt");
|
||||
try {
|
||||
child.createNewFile();
|
||||
} catch (IOException e) {
|
||||
fail("Could not create " + "file.txt");
|
||||
}
|
||||
child.setWritable(false);
|
||||
boolean writable = true;
|
||||
try (FileOutputStream fos = new FileOutputStream(child)) {
|
||||
fos.write("Hello World".getBytes()); // write operation
|
||||
fos.flush();
|
||||
} catch (IOException e) {
|
||||
writable = false;
|
||||
} finally {
|
||||
removeDir(parentDir);
|
||||
}
|
||||
assertFalse(writable);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenFilesCreatedInDirectory_whenCreateNewFileInvoked_thenTheyCanBeListedAsExpected() throws IOException {
|
||||
File directory = makeDirectory("filtersDirectory");
|
||||
public void givenWriteOnlyFile_whenCreateNewFile_thenCantReadFile() {
|
||||
File parentDir = makeDir("writeDir");
|
||||
|
||||
File csvFile = new File(directory, "csvFile.csv");
|
||||
csvFile.createNewFile();
|
||||
File child = new File(parentDir, "file.txt");
|
||||
try {
|
||||
child.createNewFile();
|
||||
} catch (IOException e) {
|
||||
fail("Could not create " + "file.txt");
|
||||
}
|
||||
child.setReadable(false);
|
||||
boolean readable = true;
|
||||
try (FileInputStream fis = new FileInputStream(child)) {
|
||||
fis.read(); // read operation
|
||||
} catch (IOException e) {
|
||||
readable = false;
|
||||
} finally {
|
||||
removeDir(parentDir);
|
||||
}
|
||||
assertFalse(readable);
|
||||
}
|
||||
|
||||
File txtFile = new File(directory, "txtFile.txt");
|
||||
txtFile.createNewFile();
|
||||
@Test
|
||||
public void givenFilesInDir_whenCreateNewFile_thenCanListFiles() {
|
||||
File parentDir = makeDir("filtersDir");
|
||||
|
||||
String[] files = {"file1.csv", "file2.txt"};
|
||||
for (String file : files) {
|
||||
try {
|
||||
new File(parentDir, file).createNewFile();
|
||||
} catch (IOException e) {
|
||||
fail("Could not create " + file);
|
||||
}
|
||||
}
|
||||
|
||||
//normal listing
|
||||
assertEquals(2, directory.list().length);
|
||||
assertEquals(2, parentDir.list().length);
|
||||
|
||||
//filtered listing
|
||||
FilenameFilter csvFilter = (dir, ext) -> ext.endsWith(".csv");
|
||||
assertEquals(1, directory.list(csvFilter).length);
|
||||
assertEquals(1, parentDir.list(csvFilter).length);
|
||||
|
||||
removeDirectory(directory);
|
||||
removeDir(parentDir);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenDirectoryIsCreated_whenMkdirInvoked_thenDirectoryCanBeRenamed() {
|
||||
public void givenDir_whenMkdir_thenCanRenameDir() {
|
||||
|
||||
File source = makeDirectory("source");
|
||||
File destination = makeDirectory("destination");
|
||||
source.renameTo(destination);
|
||||
File source = makeDir("source");
|
||||
File destination = makeDir("destination");
|
||||
boolean renamed = source.renameTo(destination);
|
||||
|
||||
assertFalse(source.isDirectory());
|
||||
assertTrue(destination.isDirectory());
|
||||
if (renamed) {
|
||||
assertFalse(source.isDirectory());
|
||||
assertTrue(destination.isDirectory());
|
||||
|
||||
removeDirectory(destination);
|
||||
removeDir(destination);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenDataIsWrittenToFile_whenWriteIsInvoked_thenFreeSpaceOnSystemDecreases() throws IOException {
|
||||
public void givenDataWritten_whenWrite_thenFreeSpaceReduces() {
|
||||
|
||||
String name = System.getProperty("user.home") + System.getProperty("file.separator") + "test";
|
||||
File testDir = makeDirectory(name);
|
||||
String home = System.getProperty("user.home");
|
||||
String sep = File.separator;
|
||||
File testDir = makeDir(home + sep + "test");
|
||||
File sample = new File(testDir, "sample.txt");
|
||||
|
||||
long freeSpaceBeforeWrite = testDir.getFreeSpace();
|
||||
writeSampleDataToFile(sample);
|
||||
long freeSpaceBefore = testDir.getFreeSpace();
|
||||
try {
|
||||
writeSampleDataToFile(sample);
|
||||
} catch (IOException e) {
|
||||
fail("Could not write to " + "sample.txt");
|
||||
}
|
||||
|
||||
long freeSpaceAfterWrite = testDir.getFreeSpace();
|
||||
assertTrue(freeSpaceAfterWrite < freeSpaceBeforeWrite);
|
||||
long freeSpaceAfter = testDir.getFreeSpace();
|
||||
assertTrue(freeSpaceAfter < freeSpaceBefore);
|
||||
|
||||
removeDirectory(testDir);
|
||||
removeDir(testDir);
|
||||
}
|
||||
|
||||
private static File makeDirectory(String directoryName) {
|
||||
File directory = new File(directoryName);
|
||||
private static File makeDir(String name) {
|
||||
File directory = new File(name);
|
||||
directory.mkdir();
|
||||
if (directory.isDirectory()) {
|
||||
return directory;
|
||||
}
|
||||
throw new RuntimeException("Directory not created for " + directoryName);
|
||||
throw new RuntimeException("'" + name + "' not made!");
|
||||
}
|
||||
|
||||
private static void removeDirectory(File directory) {
|
||||
private static void removeDir(File directory) {
|
||||
// make sure you don't delete your home directory here
|
||||
if (directory.getPath().equals(System.getProperty("user.home"))) {
|
||||
String home = System.getProperty("user.home");
|
||||
if (directory.getPath().equals(home)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// remove directory and its files from system
|
||||
if (directory != null && directory.exists()) {
|
||||
if (directory.exists()) {
|
||||
// delete all files inside the directory
|
||||
File[] filesInDirectory = directory.listFiles();
|
||||
if (filesInDirectory != null) {
|
||||
List<File> files = Arrays.asList(filesInDirectory);
|
||||
File[] dirFiles = directory.listFiles();
|
||||
if (dirFiles != null) {
|
||||
List<File> files = Arrays.asList(dirFiles);
|
||||
files.forEach(f -> deleteFile(f));
|
||||
}
|
||||
|
||||
@ -171,8 +194,8 @@ public class FileClassDemoUnitTest {
|
||||
//write sample text to file
|
||||
try (FileOutputStream out = new FileOutputStream(sample)) {
|
||||
for (int i = 1; i <= 100000; i++) {
|
||||
String sampleText = "Sample line number " + i + "\n";
|
||||
out.write(sampleText.getBytes());
|
||||
String text = "Sample line number " + i + "\n";
|
||||
out.write(text.getBytes());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,5 @@
|
||||
package com.baeldung.strictfpUsage;
|
||||
|
||||
public strictfp interface Circle {
|
||||
double computeArea(double radius);
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package com.baeldung.strictfpUsage;
|
||||
|
||||
public strictfp class ScientificCalculator {
|
||||
|
||||
public double sum(double value1, double value2) {
|
||||
return value1 + value2;
|
||||
}
|
||||
|
||||
public double diff(double value1, double value2) {
|
||||
return value1 - value2;
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.baeldung.strictfpUsage;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
public class ScientificCalculatorUnitTest {
|
||||
|
||||
@Test
|
||||
public void whenMethodOfstrictfpClassInvoked_thenIdenticalResultOnAllPlatforms() {
|
||||
ScientificCalculator calculator = new ScientificCalculator();
|
||||
double result = calculator.sum(23e10, 98e17);
|
||||
assertThat(result, is(9.800000230000001E18));
|
||||
result = calculator.diff(Double.MAX_VALUE, 1.56);
|
||||
assertThat(result, is(1.7976931348623157E308));
|
||||
}
|
||||
}
|
@ -14,4 +14,4 @@ This module contains articles about core Java non-blocking input and output (IO)
|
||||
- [Java NIO2 Path API](https://www.baeldung.com/java-nio-2-path)
|
||||
- [Guide to Java NIO2 Asynchronous Channel APIs](https://www.baeldung.com/java-nio-2-async-channels)
|
||||
- [A Guide to NIO2 Asynchronous Socket Channel](https://www.baeldung.com/java-nio2-async-socket-channel)
|
||||
- [[More -->]](/core-java-modules/core-java-nio-2)
|
||||
- [[More -->]](/core-java-modules/core-java-nio-2)
|
||||
|
@ -0,0 +1,19 @@
|
||||
package com.baeldung.streams.debug.entity;
|
||||
|
||||
public class Customer {
|
||||
private final String name;
|
||||
private final int age;
|
||||
|
||||
public Customer(String name, int age) {
|
||||
this.name = name;
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public int getAge() {
|
||||
return age;
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.baeldung.streams.debug;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class Example1 {
|
||||
@Test
|
||||
public void whenDebugging_thenInformationIsShown() {
|
||||
int[] listOutputSorted = IntStream.of(-3, 10, -4, 1, 3)
|
||||
.sorted()
|
||||
.toArray();
|
||||
|
||||
assertThat(listOutputSorted).isSorted();
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package com.baeldung.streams.debug;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.baeldung.streams.debug.entity.Customer;
|
||||
|
||||
public class Example2 {
|
||||
@Test
|
||||
public void whenDebugging_thenInformationIsShown() {
|
||||
List<Optional<Customer>> customers = Arrays.asList(
|
||||
Optional.of(new Customer("John P.", 15)),
|
||||
Optional.of(new Customer("Sarah M.", 78)),
|
||||
Optional.empty(),
|
||||
Optional.of(new Customer("Mary T.", 20)),
|
||||
Optional.empty(),
|
||||
Optional.of(new Customer("Florian G.", 89)),
|
||||
Optional.empty()
|
||||
);
|
||||
|
||||
long numberOf65PlusCustomers = customers.stream()
|
||||
.flatMap(c -> c.map(Stream::of)
|
||||
.orElseGet(Stream::empty))
|
||||
.mapToInt(Customer::getAge)
|
||||
.filter(c -> c > 65)
|
||||
.count();
|
||||
|
||||
assertThat(numberOf65PlusCustomers).isEqualTo(2);
|
||||
}
|
||||
}
|
@ -12,5 +12,5 @@ This module contains articles about string-related algorithms.
|
||||
- [Pad a String with Zeros or Spaces in Java](https://www.baeldung.com/java-pad-string)
|
||||
- [Remove Leading and Trailing Characters from a String](https://www.baeldung.com/java-remove-trailing-characters)
|
||||
- [Counting Words in a String](https://www.baeldung.com/java-word-counting)
|
||||
- [Finding the Difference Between Two Strings](https://www.baeldung.com/java-difference-between-two-strings)
|
||||
- [Finding the Difference Between Two Strings in Java](https://www.baeldung.com/java-difference-between-two-strings)
|
||||
- More articles: [[<-- prev]](../core-java-string-algorithms)
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
This module contains articles about HttpClient 4.x
|
||||
|
||||
###The Course
|
||||
### The Course
|
||||
|
||||
The "REST With Spring" Classes: http://bit.ly/restwithspring
|
||||
|
||||
|
@ -2,10 +2,12 @@
|
||||
|
||||
This module contains articles about Jackson.
|
||||
|
||||
###The Course
|
||||
### The Course
|
||||
|
||||
The "REST With Spring" Classes: http://bit.ly/restwithspring
|
||||
|
||||
### Relevant Articles:
|
||||
|
||||
- [Jackson – Unmarshall to Collection/Array](https://www.baeldung.com/jackson-collection-array)
|
||||
- [Jackson – Custom Serializer](https://www.baeldung.com/jackson-custom-serialization)
|
||||
- [Getting Started with Custom Deserialization in Jackson](https://www.baeldung.com/jackson-deserialization)
|
||||
@ -24,7 +26,7 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring
|
||||
- [Map Serialization and Deserialization with Jackson](https://www.baeldung.com/jackson-map)
|
||||
- [Jackson Streaming API](https://www.baeldung.com/jackson-streaming-api)
|
||||
- [Jackson – JsonMappingException (No serializer found for class)](https://www.baeldung.com/jackson-jsonmappingexception)
|
||||
- [How To Serialize Enums as JSON Objects with Jackson](https://www.baeldung.com/jackson-serialize-enums)
|
||||
- [How To Serialize and Deserialize Enums with Jackson](https://www.baeldung.com/jackson-serialize-enums)
|
||||
- [Jackson – Marshall String to JsonNode](https://www.baeldung.com/jackson-json-to-jsonnode)
|
||||
- [Jackson – Unmarshall to Collection/Array](https://www.baeldung.com/jackson-collection-array)
|
||||
- [Serialize Only Fields that meet a Custom Criteria with Jackson](https://www.baeldung.com/jackson-serialize-field-custom-criteria)
|
||||
|
@ -2,6 +2,6 @@
|
||||
|
||||
This module contains articles about JDI, the Java Debug Interface.
|
||||
|
||||
###Relevant articles
|
||||
### Relevant articles
|
||||
|
||||
- [An Intro to the Java Debug Interface (JDI)](https://www.baeldung.com/java-debug-interface)
|
||||
|
@ -0,0 +1,14 @@
|
||||
#!/bin/bash
|
||||
|
||||
while getopts u:a:f: flag
|
||||
do
|
||||
case "${flag}"
|
||||
in
|
||||
u) username=${OPTARG};;
|
||||
a) age=${OPTARG};;
|
||||
f) fullname=${OPTARG};;
|
||||
esac
|
||||
done
|
||||
echo "Username: $username";
|
||||
echo "Age: $age";
|
||||
echo "Full Name: $fullname";
|
@ -0,0 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
echo "Username: $1";
|
||||
echo "Age: $2";
|
||||
echo "Full Name: $3";
|
@ -0,0 +1,8 @@
|
||||
#!/bin/bash
|
||||
|
||||
i=1;
|
||||
for user in "$@"
|
||||
do
|
||||
echo "Username - $i: $user";
|
||||
i=$((i + 1));
|
||||
done
|
@ -0,0 +1,10 @@
|
||||
#!/bin/bash
|
||||
|
||||
i=1;
|
||||
j=$#;
|
||||
while [ $i -le $j ]
|
||||
do
|
||||
echo "Username - $i: $1";
|
||||
i=$((i + 1));
|
||||
shift 1;
|
||||
done
|
@ -77,10 +77,11 @@
|
||||
<properties>
|
||||
<!-- lombok: https://projectlombok.org/changelog.html -->
|
||||
<lombok.version>1.18.10</lombok.version>
|
||||
|
||||
<!-- various -->
|
||||
<hibernate-jpa-2.1-api.version>1.0.0.Final</hibernate-jpa-2.1-api.version>
|
||||
<!-- delombok maven plugin -->
|
||||
<delombok-maven-plugin.version>1.18.4.0</delombok-maven-plugin.version>
|
||||
<delombok-maven-plugin.version>1.18.10.0</delombok-maven-plugin.version>
|
||||
<assertj-core.version>3.8.0</assertj-core.version>
|
||||
</properties>
|
||||
|
||||
|
@ -3,8 +3,8 @@ package com.baeldung.lombok.accessors.model;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
public class BasicAccount {
|
||||
String name;
|
||||
BigDecimal balance;
|
||||
private String name;
|
||||
private BigDecimal balance;
|
||||
|
||||
public BigDecimal getBalance() {
|
||||
return this.balance;
|
||||
|
@ -10,6 +10,6 @@ import java.math.BigDecimal;
|
||||
@Getter
|
||||
@Setter
|
||||
public class ChainedAccount {
|
||||
String name;
|
||||
BigDecimal balance;
|
||||
private String name;
|
||||
private BigDecimal balance;
|
||||
}
|
||||
|
@ -10,6 +10,6 @@ import java.math.BigDecimal;
|
||||
@Getter
|
||||
@Setter
|
||||
public class ChainedFluentAccount {
|
||||
String name;
|
||||
BigDecimal balance;
|
||||
private String name;
|
||||
private BigDecimal balance;
|
||||
}
|
||||
|
@ -10,6 +10,6 @@ import java.math.BigDecimal;
|
||||
@Getter
|
||||
@Setter
|
||||
public class FluentAccount {
|
||||
String name;
|
||||
BigDecimal balance;
|
||||
private String name;
|
||||
private BigDecimal balance;
|
||||
}
|
||||
|
@ -11,6 +11,10 @@ import java.math.BigDecimal;
|
||||
@Getter
|
||||
@Setter
|
||||
public class PrefixedAccount {
|
||||
String sName;
|
||||
BigDecimal bdBalance;
|
||||
private String sName;
|
||||
private BigDecimal bdBalance;
|
||||
|
||||
@Accessors(prefix = "s_")
|
||||
private String s_notes;
|
||||
|
||||
}
|
||||
|
@ -10,6 +10,6 @@ import java.math.BigDecimal;
|
||||
@Getter
|
||||
@Setter
|
||||
public class PrefixedFluentAccount {
|
||||
String sName;
|
||||
BigDecimal bdBalance;
|
||||
private String sName;
|
||||
private BigDecimal bdBalance;
|
||||
}
|
||||
|
@ -8,6 +8,6 @@ import java.math.BigDecimal;
|
||||
@Getter
|
||||
@Setter
|
||||
public class StandardAccount {
|
||||
String name;
|
||||
BigDecimal balance;
|
||||
private String name;
|
||||
private BigDecimal balance;
|
||||
}
|
||||
|
@ -12,11 +12,11 @@ public class AccessorsUnitTest {
|
||||
@Test
|
||||
public void givenBasicAccount_thenUseBasicAccessors() {
|
||||
BasicAccount account = new BasicAccount();
|
||||
account.setBalance(BigDecimal.TEN);
|
||||
account.setName("Basic Accessors");
|
||||
account.setBalance(BigDecimal.TEN);
|
||||
|
||||
assertEquals(BigDecimal.TEN, account.getBalance());
|
||||
assertEquals("Basic Accessors", account.getName());
|
||||
assertEquals(BigDecimal.TEN, account.getBalance());
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -25,8 +25,8 @@ public class AccessorsUnitTest {
|
||||
account.name("Fluent Account");
|
||||
account.balance(BigDecimal.TEN);
|
||||
|
||||
assertEquals(BigDecimal.TEN, account.balance());
|
||||
assertEquals("Fluent Account", account.name());
|
||||
assertEquals(BigDecimal.TEN, account.balance());
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -34,8 +34,8 @@ public class AccessorsUnitTest {
|
||||
ChainedAccount account = new ChainedAccount();
|
||||
account.setName("Chained Account").setBalance(BigDecimal.TEN);
|
||||
|
||||
assertEquals(BigDecimal.TEN, account.getBalance());
|
||||
assertEquals("Chained Account", account.getName());
|
||||
assertEquals(BigDecimal.TEN, account.getBalance());
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -44,8 +44,8 @@ public class AccessorsUnitTest {
|
||||
.name("Fluent Account")
|
||||
.balance(BigDecimal.TEN);
|
||||
|
||||
assertEquals(BigDecimal.TEN, account.balance());
|
||||
assertEquals("Fluent Account", account.name());
|
||||
assertEquals(BigDecimal.TEN, account.balance());
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -53,9 +53,11 @@ public class AccessorsUnitTest {
|
||||
PrefixedAccount account = new PrefixedAccount();
|
||||
account.setName("Prefixed Fields");
|
||||
account.setBalance(BigDecimal.TEN);
|
||||
account.setNotes("Notes");
|
||||
|
||||
assertEquals(BigDecimal.TEN, account.getBalance());
|
||||
assertEquals("Prefixed Fields", account.getName());
|
||||
assertEquals(BigDecimal.TEN, account.getBalance());
|
||||
assertEquals("Notes", account.getNotes());
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -65,8 +67,8 @@ public class AccessorsUnitTest {
|
||||
.name("Prefixed Fluent Fields")
|
||||
.balance(BigDecimal.TEN);
|
||||
|
||||
assertEquals(BigDecimal.TEN, account.balance());
|
||||
assertEquals("Prefixed Fluent Fields", account.name());
|
||||
assertEquals(BigDecimal.TEN, account.balance());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,7 +2,8 @@
|
||||
|
||||
This module contains articles about MapStruct.
|
||||
|
||||
###Relevant Articles:
|
||||
### Relevant Articles:
|
||||
|
||||
- [Quick Guide to MapStruct](https://www.baeldung.com/mapstruct)
|
||||
- [Custom Mapper with MapStruct](https://www.baeldung.com/mapstruct-custom-mapper)
|
||||
- [Using Multiple Source Objects with MapStruct](https://www.baeldung.com/mapstruct-multiple-source-objects)
|
||||
|
3
persistence-modules/hibernate5-2/README.md
Normal file
3
persistence-modules/hibernate5-2/README.md
Normal file
@ -0,0 +1,3 @@
|
||||
### Relevant Articles:
|
||||
- [Hibernate Error “Not all named parameters have been set”](https://www.baeldung.com/hibernate-error-named-parameters-not-set)
|
||||
|
@ -1,3 +1,3 @@
|
||||
#Relevant Articles
|
||||
### Relevant Articles
|
||||
|
||||
- [Spring Data with Reactive Cassandra](https://www.baeldung.com/spring-data-cassandra-reactive)
|
||||
|
3
persistence-modules/spring-data-jpa-3/README.md
Normal file
3
persistence-modules/spring-data-jpa-3/README.md
Normal file
@ -0,0 +1,3 @@
|
||||
### Relevant Articles:
|
||||
- [Programmatic Transaction Management in Spring](https://www.baeldung.com/spring-programmatic-transaction-management)
|
||||
|
4
pom.xml
4
pom.xml
@ -610,7 +610,7 @@
|
||||
|
||||
<module>tensorflow-java</module>
|
||||
<module>spf4j</module>
|
||||
<module>spring-boot-configuration</module>
|
||||
<module>spring-boot-config-jpa-error</module>
|
||||
<module>spring-boot-flowable</module>
|
||||
<module>spring-boot-mvc-2</module>
|
||||
<module>spring-boot-performance</module>
|
||||
@ -697,7 +697,7 @@
|
||||
<module>spring-boot-bootstrap</module>
|
||||
<module>spring-boot-camel</module>
|
||||
<!-- <module>spring-boot-cli</module> --> <!-- Not a maven project -->
|
||||
<module>spring-boot-configuration</module>
|
||||
<module>spring-boot-config-jpa-error</module>
|
||||
<module>spring-boot-client</module>
|
||||
|
||||
<module>spring-boot-crud</module>
|
||||
|
@ -15,4 +15,4 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring
|
||||
- [Spring ResponseStatusException](https://www.baeldung.com/spring-response-status-exception)
|
||||
- [Spring Assert Statements](https://www.baeldung.com/spring-assert)
|
||||
- [Configuring a Hikari Connection Pool with Spring Boot](https://www.baeldung.com/spring-boot-hikari)
|
||||
- [Difference between <context:annotation-config> vs <context:component-scan>](https://www.baeldung.com/spring-contextannotation-contextcomponentscan)
|
||||
- [Difference between \<context:annotation-config> vs \<context:component-scan>](https://www.baeldung.com/spring-contextannotation-contextcomponentscan)
|
||||
|
@ -1,6 +1,6 @@
|
||||
# Spring Boot Configuration
|
||||
# Spring Boot - DataJpaTest Error
|
||||
|
||||
This module contains articles about Spring Boot Configuration.
|
||||
This module contains examples about a corner case using @DataJpaTest with a multi module project.
|
||||
|
||||
### Relevant Articles:
|
||||
- [Unable to Find @SpringBootConfiguration with @DataJpaTest](https://www.baeldung.com/spring-boot-unable-to-find-springbootconfiguration-with-datajpatest)
|
@ -5,8 +5,8 @@
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung.spring-boot-configuration</groupId>
|
||||
<artifactId>spring-boot-configuration</artifactId>
|
||||
<groupId>com.baeldung.spring-boot-config-jpa-error</groupId>
|
||||
<artifactId>spring-boot-config-jpa-error</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
</project>
|
@ -5,8 +5,8 @@
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung.spring-boot-configuration</groupId>
|
||||
<artifactId>spring-boot-configuration</artifactId>
|
||||
<groupId>com.baeldung.spring-boot-config-jpa-error</groupId>
|
||||
<artifactId>spring-boot-config-jpa-error</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
</project>
|
@ -1,8 +1,8 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.baeldung.spring-boot-configuration</groupId>
|
||||
<artifactId>spring-boot-configuration</artifactId>
|
||||
<groupId>com.baeldung.spring-boot-config-jpa-error</groupId>
|
||||
<artifactId>spring-boot-config-jpa-error</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<packaging>pom</packaging>
|
||||
|
3
spring-boot-springdoc/README.md
Normal file
3
spring-boot-springdoc/README.md
Normal file
@ -0,0 +1,3 @@
|
||||
### Relevant Articles:
|
||||
- [Documenting a Spring REST API Using OpenAPI 3.0](https://www.baeldung.com/spring-rest-openapi-documentation)
|
||||
|
@ -1,3 +1,3 @@
|
||||
#Revelant Articles:
|
||||
# Relevant Articles:
|
||||
|
||||
- [Using a Spring Cloud App Starter](http://www.baeldung.com/spring-cloud-app-starter)
|
||||
|
@ -1,7 +1,7 @@
|
||||
## Relevant Articles:
|
||||
|
||||
- [Understanding getBean() in Spring](https://www.baeldung.com/spring-getbean)
|
||||
- [Exploring the Spring BeanFactory API](https://www.baeldung.com/spring-beanfactory)
|
||||
- [Guide to the Spring BeanFactory](https://www.baeldung.com/spring-beanfactory)
|
||||
- [How to use the Spring FactoryBean?](https://www.baeldung.com/spring-factorybean)
|
||||
- [Spring – Injecting Collections](https://www.baeldung.com/spring-injecting-collections)
|
||||
- More articles: [[<-- prev]](/spring-core-2)
|
||||
- More articles: [[<-- prev]](/spring-core-2)
|
||||
|
@ -2,10 +2,12 @@
|
||||
|
||||
This module contains articles about Spring MVC with XML configuration
|
||||
|
||||
###The Course
|
||||
### The Course
|
||||
|
||||
The "REST With Spring" Classes: http://bit.ly/restwithspring
|
||||
|
||||
### Relevant Articles:
|
||||
|
||||
- [Java Session Timeout](https://www.baeldung.com/servlet-session-timeout)
|
||||
- [Returning Image/Media Data with Spring MVC](https://www.baeldung.com/spring-mvc-image-media-data)
|
||||
- [Geolocation by IP in Java](https://www.baeldung.com/geolocation-by-ip-with-maxmind)
|
||||
@ -17,4 +19,5 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring
|
||||
- [Debugging the Spring MVC 404 “No mapping found for HTTP request” Error](https://www.baeldung.com/spring-mvc-404-error)
|
||||
|
||||
## Spring MVC with XML Configuration Example Project
|
||||
|
||||
- access a sample jsp page at: `http://localhost:8080/spring-mvc-xml/sample.html`
|
||||
|
@ -2,10 +2,12 @@
|
||||
|
||||
This module contains articles about Spring Security with custom MVC applications
|
||||
|
||||
###The Course
|
||||
### The Course
|
||||
|
||||
The "REST With Spring" Classes: http://github.learnspringsecurity.com
|
||||
|
||||
### Relevant Articles:
|
||||
|
||||
- [Spring Security Remember Me](https://www.baeldung.com/spring-security-remember-me)
|
||||
- [Redirect to different pages after Login with Spring Security](https://www.baeldung.com/spring_redirect_after_login)
|
||||
- [Changing Spring Model Parameters with Handler Interceptor](https://www.baeldung.com/spring-model-parameters-with-handler-interceptor)
|
||||
@ -15,6 +17,7 @@ The "REST With Spring" Classes: http://github.learnspringsecurity.com
|
||||
- [How to Manually Authenticate User with Spring Security](https://www.baeldung.com/manually-set-user-authentication-spring-security)
|
||||
|
||||
### Build the Project
|
||||
|
||||
```
|
||||
mvn clean install
|
||||
```
|
||||
|
@ -2,10 +2,12 @@
|
||||
|
||||
This module contains articles about digest authentication with Spring Security
|
||||
|
||||
###The Course
|
||||
### The Course
|
||||
|
||||
The "Learn Spring Security" Classes: http://github.learnspringsecurity.com
|
||||
|
||||
### Relevant Article:
|
||||
|
||||
- [Spring Security Digest Authentication](https://www.baeldung.com/spring-security-digest-authentication)
|
||||
- [RestTemplate with Digest Authentication](https://www.baeldung.com/resttemplate-digest-authentication)
|
||||
|
||||
|
@ -2,14 +2,17 @@
|
||||
|
||||
This module contains articles about Spring Security LDAP
|
||||
|
||||
###The Course
|
||||
### The Course
|
||||
|
||||
The "Learn Spring Security" Classes: http://github.learnspringsecurity.com
|
||||
|
||||
### Relevant Article:
|
||||
|
||||
- [Spring Security – security none, filters none, access permitAll](https://www.baeldung.com/security-none-filters-none-access-permitAll)
|
||||
- [Intro to Spring Security LDAP](https://www.baeldung.com/spring-security-ldap)
|
||||
|
||||
### Notes
|
||||
|
||||
- the project uses Spring Boot - simply run 'SampleLDAPApplication.java' to start up Spring Boot with a Tomcat container and embedded LDAP server.
|
||||
- Once started, open 'http://localhost:8080'
|
||||
- This will display the publicly available Home Page
|
||||
|
@ -2,13 +2,16 @@
|
||||
|
||||
This module contains articles about 'remember me' with Spring Security
|
||||
|
||||
###The Course
|
||||
### The Course
|
||||
|
||||
The "Learn Spring Security" Classes: http://github.learnspringsecurity.com
|
||||
|
||||
### Relevant Articles:
|
||||
|
||||
- [Spring Security – Persistent Remember Me](https://www.baeldung.com/spring-security-persistent-remember-me)
|
||||
|
||||
### Build the Project
|
||||
|
||||
```
|
||||
mvn clean install
|
||||
```
|
||||
|
@ -2,15 +2,18 @@
|
||||
|
||||
This module contains articles about Spring Security in MVC applications
|
||||
|
||||
###The Course
|
||||
### The Course
|
||||
|
||||
The "Learn Spring Security" Classes: http://github.learnspringsecurity.com
|
||||
|
||||
### Relevant Articles:
|
||||
|
||||
- [HttpSessionListener Example – Monitoring](https://www.baeldung.com/httpsessionlistener_with_metrics)
|
||||
- [Control the Session with Spring Security](https://www.baeldung.com/spring-security-session)
|
||||
|
||||
|
||||
### Build the Project
|
||||
|
||||
```
|
||||
mvn clean install
|
||||
```
|
||||
|
@ -2,11 +2,12 @@
|
||||
|
||||
This module contains articles about basic authentication in RESTful APIs with Spring Security
|
||||
|
||||
###The Course
|
||||
### The Course
|
||||
|
||||
The "Learn Spring Security" Classes: http://github.learnspringsecurity.com
|
||||
|
||||
### Relevant Articles:
|
||||
|
||||
- [Basic Authentication with the RestTemplate](https://www.baeldung.com/how-to-use-resttemplate-with-basic-authentication-in-spring)
|
||||
- [A Custom Filter in the Spring Security Filter Chain](https://www.baeldung.com/spring-security-custom-filter)
|
||||
- [Spring Security Basic Authentication](https://www.baeldung.com/spring-security-basic-authentication)
|
||||
|
@ -2,10 +2,12 @@
|
||||
|
||||
This module contains articles about REST APIs with Spring Security
|
||||
|
||||
###The Course
|
||||
### The Course
|
||||
|
||||
The "REST With Spring" Classes: http://github.learnspringsecurity.com
|
||||
|
||||
### Relevant Articles:
|
||||
|
||||
- [Spring Security Authentication Provider](https://www.baeldung.com/spring-security-authentication-provider)
|
||||
- [Retrieve User Information in Spring Security](https://www.baeldung.com/get-user-in-spring-security)
|
||||
- [Spring Security – Run-As Authentication](https://www.baeldung.com/spring-security-run-as-auth)
|
||||
|
@ -1,4 +1,5 @@
|
||||
###Relevant Articles:
|
||||
### Relevant Articles:
|
||||
|
||||
- [A Guide to REST-assured](http://www.baeldung.com/rest-assured-tutorial)
|
||||
- [REST-assured Support for Spring MockMvc](https://www.baeldung.com/spring-mock-mvc-rest-assured)
|
||||
- [Getting and Verifying Response Data with REST-assured](https://www.baeldung.com/rest-assured-response)
|
||||
|
@ -2,10 +2,12 @@
|
||||
|
||||
## REST Testing and Examples
|
||||
|
||||
###The Course
|
||||
### The Course
|
||||
|
||||
The "REST With Spring" Classes: http://bit.ly/restwithspring
|
||||
|
||||
### Relevant Articles:
|
||||
|
||||
- [Introduction to WireMock](http://www.baeldung.com/introduction-to-wiremock)
|
||||
- [Using WireMock Scenarios](https://www.baeldung.com/wiremock-scenarios)
|
||||
- [REST API Testing with Cucumber](http://www.baeldung.com/cucumber-rest-api-testing)
|
||||
|
@ -1,2 +1,3 @@
|
||||
###Relevant Articles:
|
||||
### Relevant Articles:
|
||||
|
||||
- [Introduction To XMLUnit 2.x](http://www.baeldung.com/xmlunit2)
|
||||
|
Loading…
x
Reference in New Issue
Block a user