Skip to content

Commit 6de5660

Browse files
committed
Merge branch 'master' of github.com:eugenp/tutorials into geroza/BAEL-9523_migrate-projects-to-paren-t-pom-2
2 parents 6e49a75 + b8e1843 commit 6de5660

File tree

72 files changed

+305
-183
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+305
-183
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.baeldung;
2+
3+
import java.lang.reflect.Method;
4+
5+
public class Outer {
6+
7+
public void outerPublic() {
8+
}
9+
10+
private void outerPrivate() {
11+
}
12+
13+
class Inner {
14+
15+
public void innerPublic() {
16+
outerPrivate();
17+
}
18+
19+
public void innerPublicReflection(Outer ob) throws Exception {
20+
Method method = ob.getClass().getDeclaredMethod("outerPrivate");
21+
method.invoke(ob);
22+
}
23+
}
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.baeldung;
2+
3+
import static org.junit.Assert.assertTrue;
4+
import static org.hamcrest.CoreMatchers.is;
5+
6+
import java.util.Arrays;
7+
import java.util.Set;
8+
import java.util.stream.Collectors;
9+
import org.junit.Test;
10+
11+
public class OuterUnitTest {
12+
13+
private static final String NEST_HOST_NAME = "com.baeldung.Outer";
14+
15+
@Test
16+
public void whenGetNestHostFromOuter_thenGetNestHost() {
17+
is(Outer.class.getNestHost().getName()).equals(NEST_HOST_NAME);
18+
}
19+
20+
@Test
21+
public void whenGetNestHostFromInner_thenGetNestHost() {
22+
is(Outer.Inner.class.getNestHost().getName()).equals(NEST_HOST_NAME);
23+
}
24+
25+
@Test
26+
public void whenCheckNestmatesForNestedClasses_thenGetTrue() {
27+
is(Outer.Inner.class.isNestmateOf(Outer.class)).equals(true);
28+
}
29+
30+
@Test
31+
public void whenCheckNestmatesForUnrelatedClasses_thenGetFalse() {
32+
is(Outer.Inner.class.isNestmateOf(Outer.class)).equals(false);
33+
}
34+
35+
@Test
36+
public void whenGetNestMembersForNestedClasses_thenGetAllNestedClasses() {
37+
Set<String> nestMembers = Arrays.stream(Outer.Inner.class.getNestMembers())
38+
.map(Class::getName)
39+
.collect(Collectors.toSet());
40+
41+
is(nestMembers.size()).equals(2);
42+
43+
assertTrue(nestMembers.contains("com.baeldung.Outer"));
44+
assertTrue(nestMembers.contains("com.baeldung.Outer$Inner"));
45+
}
46+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.baeldung.optional;
2+
3+
import org.junit.Test;
4+
5+
import java.util.Optional;
6+
7+
import static org.junit.Assert.assertFalse;
8+
import static org.junit.Assert.assertTrue;
9+
10+
/**
11+
* Unit tests for {@link Optional} in Java 11.
12+
*/
13+
public class OptionalUnitTest {
14+
15+
@Test
16+
public void givenAnEmptyOptional_isEmpty_thenBehavesAsExpected() {
17+
Optional<String> opt = Optional.of("Baeldung");
18+
assertFalse(opt.isEmpty());
19+
20+
opt = Optional.ofNullable(null);
21+
assertTrue(opt.isEmpty());
22+
}
23+
}

core-java-collections-list/README.md

+27

core-java-collections-list/pom.xml

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<artifactId>core-java-collections-list</artifactId>
5+
<version>0.1.0-SNAPSHOT</version>
6+
<packaging>jar</packaging>
7+
<name>core-java-collections-list</name>
8+
9+
<parent>
10+
<groupId>com.baeldung</groupId>
11+
<artifactId>parent-java</artifactId>
12+
<version>0.0.1-SNAPSHOT</version>
13+
<relativePath>../parent-java</relativePath>
14+
</parent>
15+
16+
<dependencies>
17+
<dependency>
18+
<groupId>org.apache.commons</groupId>
19+
<artifactId>commons-collections4</artifactId>
20+
<version>${commons-collections4.version}</version>
21+
</dependency>
22+
<dependency>
23+
<groupId>org.apache.commons</groupId>
24+
<artifactId>commons-lang3</artifactId>
25+
<version>${commons-lang3.version}</version>
26+
</dependency>
27+
<dependency>
28+
<groupId>org.assertj</groupId>
29+
<artifactId>assertj-core</artifactId>
30+
<version>${assertj.version}</version>
31+
<scope>test</scope>
32+
</dependency>
33+
<dependency>
34+
<groupId>org.projectlombok</groupId>
35+
<artifactId>lombok</artifactId>
36+
<version>${lombok.version}</version>
37+
<scope>provided</scope>
38+
</dependency>
39+
</dependencies>
40+
41+
<properties>
42+
<commons-collections4.version>4.1</commons-collections4.version>
43+
<commons-lang3.version>3.8.1</commons-lang3.version>
44+
<avaitility.version>1.7.0</avaitility.version>
45+
<assertj.version>3.11.1</assertj.version>
46+
<lombok.version>1.16.12</lombok.version>
47+
</properties>
48+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<configuration>
3+
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
4+
<encoder>
5+
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
6+
</pattern>
7+
</encoder>
8+
</appender>
9+
10+
<root level="INFO">
11+
<appender-ref ref="STDOUT" />
12+
</root>
13+
</configuration>

core-java/src/test/java/com/baeldung/RandomListElementUnitTest.java renamed to core-java-collections-list/src/test/java/org/baeldung/RandomListElementUnitTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.baeldung;
1+
package org.baeldung;
22

33
import com.google.common.collect.Lists;
44
import org.junit.Test;

core-java-collections/README.md

+1-24

core-java/src/test/java/com/baeldung/keystore/JavaKeyStoreUnitTest.java

+27
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,24 @@
44
import org.junit.Assert;
55
import org.junit.Before;
66
import org.junit.Test;
7+
78
import sun.security.x509.AlgorithmId;
89
import sun.security.x509.CertificateAlgorithmId;
910
import sun.security.x509.CertificateSerialNumber;
1011
import sun.security.x509.CertificateValidity;
1112
import sun.security.x509.CertificateVersion;
1213
import sun.security.x509.CertificateX509Key;
14+
import sun.security.x509.SubjectAlternativeNameExtension;
1315
import sun.security.x509.X500Name;
1416
import sun.security.x509.X509CertImpl;
1517
import sun.security.x509.X509CertInfo;
18+
import sun.security.x509.CertificateExtensions;
19+
import sun.security.x509.GeneralNames;
20+
import sun.security.x509.GeneralName;
21+
import sun.security.x509.GeneralNameInterface;
22+
import sun.security.x509.DNSName;
23+
import sun.security.x509.IPAddressName;
24+
import sun.security.util.DerOutputStream;
1625

1726
import javax.crypto.KeyGenerator;
1827
import javax.crypto.SecretKey;
@@ -188,6 +197,23 @@ private X509Certificate generateSelfSignedCertificate(KeyPair keyPair) throws Ce
188197
Date validTo = new Date(validFrom.getTime() + 50L * 365L * 24L * 60L * 60L * 1000L); //50 years
189198
CertificateValidity validity = new CertificateValidity(validFrom, validTo);
190199
certInfo.set(X509CertInfo.VALIDITY, validity);
200+
201+
GeneralNameInterface dnsName = new DNSName("baeldung.com");
202+
DerOutputStream dnsNameOutputStream = new DerOutputStream();
203+
dnsName.encode(dnsNameOutputStream);
204+
205+
GeneralNameInterface ipAddress = new IPAddressName("127.0.0.1");
206+
DerOutputStream ipAddressOutputStream = new DerOutputStream();
207+
ipAddress.encode(ipAddressOutputStream);
208+
209+
GeneralNames generalNames = new GeneralNames();
210+
generalNames.add(new GeneralName(dnsName));
211+
generalNames.add(new GeneralName(ipAddress));
212+
213+
CertificateExtensions ext = new CertificateExtensions();
214+
ext.set(SubjectAlternativeNameExtension.NAME, new SubjectAlternativeNameExtension(generalNames));
215+
216+
certInfo.set(X509CertInfo.EXTENSIONS, ext);
191217

192218
// Create certificate and sign it
193219
X509CertImpl cert = new X509CertImpl(certInfo);
@@ -202,4 +228,5 @@ private X509Certificate generateSelfSignedCertificate(KeyPair keyPair) throws Ce
202228

203229
return newCert;
204230
}
231+
205232
}

ethereum/src/main/java/com/baeldung/web3j/controllers/EthereumRestController.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ public Future<ResponseTransfer> getBlock() {
3232

3333
return CompletableFuture.supplyAsync(() -> {
3434
try {
35-
CompletableFuture<EthBlockNumber> result = web3Service.getBlockNumber();
36-
responseTransfer.setMessage(result.get().toString());
35+
EthBlockNumber result = web3Service.getBlockNumber();
36+
responseTransfer.setMessage(result.toString());
3737
} catch (Exception e) {
3838
responseTransfer.setMessage(GENERIC_EXCEPTION);
3939
}
@@ -51,8 +51,8 @@ public Future<ResponseTransfer> getAccounts() {
5151

5252
return CompletableFuture.supplyAsync(() -> {
5353
try {
54-
CompletableFuture<EthAccounts> result = web3Service.getEthAccounts();
55-
responseTransfer.setMessage(result.get().toString());
54+
EthAccounts result = web3Service.getEthAccounts();
55+
responseTransfer.setMessage(result.toString());
5656
} catch (Exception e) {
5757
responseTransfer.setMessage(GENERIC_EXCEPTION);
5858
}
@@ -70,8 +70,8 @@ public Future<ResponseTransfer> getTransactions() {
7070
Instant start = TimeHelper.start();
7171
return CompletableFuture.supplyAsync(() -> {
7272
try {
73-
CompletableFuture<EthGetTransactionCount> result = web3Service.getTransactionCount();
74-
responseTransfer.setMessage(result.get().toString());
73+
EthGetTransactionCount result = web3Service.getTransactionCount();
74+
responseTransfer.setMessage(result.toString());
7575
} catch (Exception e) {
7676
responseTransfer.setMessage(GENERIC_EXCEPTION);
7777
}
@@ -88,8 +88,8 @@ public Future<ResponseTransfer> getBalance() {
8888
Instant start = TimeHelper.start();
8989
return CompletableFuture.supplyAsync(() -> {
9090
try {
91-
CompletableFuture<EthGetBalance> result = web3Service.getEthBalance();
92-
responseTransfer.setMessage(result.get().toString());
91+
EthGetBalance result = web3Service.getEthBalance();
92+
responseTransfer.setMessage(result.toString());
9393
} catch (Exception e) {
9494
responseTransfer.setMessage(GENERIC_EXCEPTION);
9595
}

0 commit comments

Comments
 (0)