+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.baeldung.list;
|
||||
package com.baeldung.list.duplicatescounter;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
+2
-2
@@ -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
-1
@@ -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;
|
||||
+117
-94
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
package com.baeldung.strictfpUsage;
|
||||
|
||||
public strictfp interface Circle {
|
||||
double computeArea(double radius);
|
||||
}
|
||||
+12
@@ -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;
|
||||
}
|
||||
}
|
||||
+18
@@ -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)
|
||||
|
||||
+19
@@ -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;
|
||||
}
|
||||
}
|
||||
+18
@@ -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();
|
||||
}
|
||||
}
|
||||
+36
@@ -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
|
||||
|
||||
|
||||
+4
-2
@@ -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)
|
||||
|
||||
+1
-1
@@ -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
|
||||
+2
-1
@@ -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
-1
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user