Skip to content

Commit 1070bc3

Browse files
author
chaos2418
committedNov 7, 2021
Merge branch 'master' of https://github.com/eugenp/tutorials into JAVA-1672
2 parents ca24b6b + 683f319 commit 1070bc3

File tree

14 files changed

+209
-0
lines changed

14 files changed

+209
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.baeldung.hexformat;
2+
3+
import java.util.HexFormat;
4+
import org.junit.jupiter.api.Test;
5+
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
6+
import static org.junit.jupiter.api.Assertions.assertEquals;
7+
8+
class ByteHexadecimalConversionUnitTest {
9+
10+
private HexFormat hexFormat = HexFormat.of();
11+
12+
@Test
13+
void givenInitialisedHexFormat_whenHexStringIsPassed_thenByteArrayRepresentationIsReturned() {
14+
byte[] hexBytes = hexFormat.parseHex("ABCDEF0123456789");
15+
assertArrayEquals(new byte[] { -85, -51, -17, 1, 35, 69, 103, -119 }, hexBytes);
16+
}
17+
18+
@Test
19+
void givenInitialisedHexFormat_whenByteArrayIsPassed_thenHexStringRepresentationIsReturned() {
20+
String bytesAsString = hexFormat.formatHex(new byte[] { -85, -51, -17, 1, 35, 69, 103, -119});
21+
assertEquals("abcdef0123456789", bytesAsString);
22+
}
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.baeldung.hexformat;
2+
3+
import java.util.HexFormat;
4+
import org.junit.jupiter.api.Test;
5+
import static org.junit.jupiter.api.Assertions.assertEquals;
6+
7+
public class PrimitiveTypeHexadecimalConversionUnitTest {
8+
9+
private HexFormat hexFormat = HexFormat.of();
10+
11+
@Test
12+
void givenInitialisedHexFormat_whenPrimitiveByteIsPassed_thenHexStringRepresentationIsReturned() {
13+
String fromByte = hexFormat.toHexDigits((byte)64);
14+
assertEquals("40", fromByte);
15+
}
16+
17+
@Test
18+
void givenInitialisedHexFormat_whenPrimitiveLongIsPassed_thenHexStringRepresentationIsReturned() {
19+
String fromLong = hexFormat.toHexDigits(1234_5678_9012_3456L);
20+
assertEquals("000462d53c8abac0", fromLong);
21+
}
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.baeldung.hexformat;
2+
3+
import java.util.HexFormat;
4+
import org.junit.jupiter.api.Test;
5+
import static org.junit.jupiter.api.Assertions.assertEquals;
6+
7+
public class StringFormattingUnitTest {
8+
9+
private HexFormat hexFormat = HexFormat.of().withPrefix("[").withSuffix("]").withDelimiter(", ");
10+
11+
@Test
12+
public void givenInitialisedHexFormatWithFormattedStringOptions_whenByteArrayIsPassed_thenHexStringRepresentationFormattedCorrectlyIsReturned() {
13+
assertEquals("[48], [0c], [11]", hexFormat.formatHex(new byte[] {72, 12, 17}));
14+
}
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.baeldung.hexformat;
2+
3+
import java.util.HexFormat;
4+
import org.junit.jupiter.api.Test;
5+
import static org.junit.jupiter.api.Assertions.assertTrue;
6+
7+
public class UppercaseLowercaseOutputUnitTest {
8+
9+
@Test
10+
public void givenInitialisedHexFormat_whenByteArrayIsPassed_thenLowerCaseHexStringRepresentationIsReturned() {
11+
HexFormat hexFormat = HexFormat.of();
12+
String bytesAsString = hexFormat.formatHex(new byte[] { -85, -51, -17, 1, 35, 69, 103, -119});
13+
assertTrue(isLowerCase(bytesAsString));
14+
}
15+
16+
@Test
17+
public void givenInitialisedHexFormatWithUpperCaseOption_whenByteArrayIsPassed_thenLowerCaseHexStringRepresentationIsReturned() {
18+
HexFormat hexFormat = HexFormat.of().withUpperCase();
19+
String bytesAsString = hexFormat.formatHex(new byte[] { -85, -51, -17, 1, 35, 69, 103, -119});
20+
assertTrue(isUpperCase(bytesAsString));
21+
}
22+
23+
private boolean isLowerCase(String str) {
24+
char[] charArray = str.toCharArray();
25+
for (int i=0; i < charArray.length; i++) {
26+
if (Character.isUpperCase(charArray[i]))
27+
return false;
28+
}
29+
return true;
30+
}
31+
32+
private boolean isUpperCase(String str) {
33+
char[] charArray = str.toCharArray();
34+
for (int i=0; i < charArray.length; i++) {
35+
if (Character.isLowerCase(charArray[i]))
36+
return false;
37+
}
38+
return true;
39+
}
40+
}

‎docker/docker-sample-app/Dockerfile

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
FROM openjdk:11
2+
COPY target/docker-sample-app-0.0.1.jar app.jar
3+
ENTRYPOINT ["java","-jar","/app.jar"]

‎docker/docker-sample-app/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
### Relevant Articles:
2+
3+
- How to Get Docker-Compose to Always Use the Latest Image
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
version: '2.4'
2+
services:
3+
db:
4+
image: postgres
5+
my_app:
6+
build: .
7+
ports:
8+
- "8080:8080"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
version: '2.4'
2+
services:
3+
db:
4+
image: postgres
5+
my_app:
6+
image: "eugen/test-app:latest"
7+
ports:
8+
- "8080:8080"
9+

‎docker/docker-sample-app/pom.xml

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<parent>
6+
<groupId>com.baeldung.docker</groupId>
7+
<artifactId>docker</artifactId>
8+
<version>0.0.1</version>
9+
</parent>
10+
11+
<artifactId>docker-sample-app</artifactId>
12+
<name>docker-sample-app</name>
13+
<description>Demo project for Spring Boot and Docker</description>
14+
15+
<properties>
16+
<java.version>11</java.version>
17+
</properties>
18+
19+
<dependencies>
20+
<dependency>
21+
<groupId>org.springframework.boot</groupId>
22+
<artifactId>spring-boot-starter</artifactId>
23+
</dependency>
24+
<dependency>
25+
<groupId>org.springframework.boot</groupId>
26+
<artifactId>spring-boot-starter-web</artifactId>
27+
</dependency>
28+
29+
<dependency>
30+
<groupId>org.springframework.boot</groupId>
31+
<artifactId>spring-boot-starter-test</artifactId>
32+
<scope>test</scope>
33+
</dependency>
34+
</dependencies>
35+
36+
<build>
37+
<plugins>
38+
<plugin>
39+
<groupId>org.springframework.boot</groupId>
40+
<artifactId>spring-boot-maven-plugin</artifactId>
41+
</plugin>
42+
</plugins>
43+
</build>
44+
45+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.baeldung.docker.app;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
public class DockAppApplication {
8+
9+
public static void main(String[] args) {
10+
SpringApplication.run(DockAppApplication.class, args);
11+
}
12+
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.baeldung.docker.app.endpoint;
2+
3+
import org.springframework.web.bind.annotation.GetMapping;
4+
import org.springframework.web.bind.annotation.RestController;
5+
6+
@RestController
7+
public class MyController {
8+
9+
@GetMapping
10+
public String version() {
11+
return "1.7";
12+
}
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.baeldung.docker.app;
2+
3+
import org.junit.jupiter.api.Test;
4+
import org.springframework.boot.test.context.SpringBootTest;
5+
6+
@SpringBootTest
7+
class DockAppApplicationUnitTest {
8+
9+
@Test
10+
void contextLoads() {
11+
}
12+
13+
}

‎docker/pom.xml

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
<modules>
2626
<module>docker-internal-dto</module>
2727
<module>docker-spring-boot</module>
28+
<module>docker-sample-app</module>
2829
</modules>
2930

3031
</project>

0 commit comments

Comments
 (0)