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' of https://github.com/eugenp/tutorials into JAV…
…A-1672
- Loading branch information
Showing
14 changed files
with
209 additions
and
0 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
.../core-java-17/src/test/java/com/baeldung/hexformat/ByteHexadecimalConversionUnitTest.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,23 @@ | ||
package com.baeldung.hexformat; | ||
|
||
import java.util.HexFormat; | ||
import org.junit.jupiter.api.Test; | ||
import static org.junit.jupiter.api.Assertions.assertArrayEquals; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
class ByteHexadecimalConversionUnitTest { | ||
|
||
private HexFormat hexFormat = HexFormat.of(); | ||
|
||
@Test | ||
void givenInitialisedHexFormat_whenHexStringIsPassed_thenByteArrayRepresentationIsReturned() { | ||
byte[] hexBytes = hexFormat.parseHex("ABCDEF0123456789"); | ||
assertArrayEquals(new byte[] { -85, -51, -17, 1, 35, 69, 103, -119 }, hexBytes); | ||
} | ||
|
||
@Test | ||
void givenInitialisedHexFormat_whenByteArrayIsPassed_thenHexStringRepresentationIsReturned() { | ||
String bytesAsString = hexFormat.formatHex(new byte[] { -85, -51, -17, 1, 35, 69, 103, -119}); | ||
assertEquals("abcdef0123456789", bytesAsString); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...a-17/src/test/java/com/baeldung/hexformat/PrimitiveTypeHexadecimalConversionUnitTest.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,22 @@ | ||
package com.baeldung.hexformat; | ||
|
||
import java.util.HexFormat; | ||
import org.junit.jupiter.api.Test; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class PrimitiveTypeHexadecimalConversionUnitTest { | ||
|
||
private HexFormat hexFormat = HexFormat.of(); | ||
|
||
@Test | ||
void givenInitialisedHexFormat_whenPrimitiveByteIsPassed_thenHexStringRepresentationIsReturned() { | ||
String fromByte = hexFormat.toHexDigits((byte)64); | ||
assertEquals("40", fromByte); | ||
} | ||
|
||
@Test | ||
void givenInitialisedHexFormat_whenPrimitiveLongIsPassed_thenHexStringRepresentationIsReturned() { | ||
String fromLong = hexFormat.toHexDigits(1234_5678_9012_3456L); | ||
assertEquals("000462d53c8abac0", fromLong); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...a-modules/core-java-17/src/test/java/com/baeldung/hexformat/StringFormattingUnitTest.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,15 @@ | ||
package com.baeldung.hexformat; | ||
|
||
import java.util.HexFormat; | ||
import org.junit.jupiter.api.Test; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class StringFormattingUnitTest { | ||
|
||
private HexFormat hexFormat = HexFormat.of().withPrefix("[").withSuffix("]").withDelimiter(", "); | ||
|
||
@Test | ||
public void givenInitialisedHexFormatWithFormattedStringOptions_whenByteArrayIsPassed_thenHexStringRepresentationFormattedCorrectlyIsReturned() { | ||
assertEquals("[48], [0c], [11]", hexFormat.formatHex(new byte[] {72, 12, 17})); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...s/core-java-17/src/test/java/com/baeldung/hexformat/UppercaseLowercaseOutputUnitTest.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,40 @@ | ||
package com.baeldung.hexformat; | ||
|
||
import java.util.HexFormat; | ||
import org.junit.jupiter.api.Test; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
public class UppercaseLowercaseOutputUnitTest { | ||
|
||
@Test | ||
public void givenInitialisedHexFormat_whenByteArrayIsPassed_thenLowerCaseHexStringRepresentationIsReturned() { | ||
HexFormat hexFormat = HexFormat.of(); | ||
String bytesAsString = hexFormat.formatHex(new byte[] { -85, -51, -17, 1, 35, 69, 103, -119}); | ||
assertTrue(isLowerCase(bytesAsString)); | ||
} | ||
|
||
@Test | ||
public void givenInitialisedHexFormatWithUpperCaseOption_whenByteArrayIsPassed_thenLowerCaseHexStringRepresentationIsReturned() { | ||
HexFormat hexFormat = HexFormat.of().withUpperCase(); | ||
String bytesAsString = hexFormat.formatHex(new byte[] { -85, -51, -17, 1, 35, 69, 103, -119}); | ||
assertTrue(isUpperCase(bytesAsString)); | ||
} | ||
|
||
private boolean isLowerCase(String str) { | ||
char[] charArray = str.toCharArray(); | ||
for (int i=0; i < charArray.length; i++) { | ||
if (Character.isUpperCase(charArray[i])) | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
private boolean isUpperCase(String str) { | ||
char[] charArray = str.toCharArray(); | ||
for (int i=0; i < charArray.length; i++) { | ||
if (Character.isLowerCase(charArray[i])) | ||
return false; | ||
} | ||
return true; | ||
} | ||
} |
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,3 @@ | ||
FROM openjdk:11 | ||
COPY target/docker-sample-app-0.0.1.jar app.jar | ||
ENTRYPOINT ["java","-jar","/app.jar"] |
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,3 @@ | ||
### Relevant Articles: | ||
|
||
- How to Get Docker-Compose to Always Use the Latest Image |
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,8 @@ | ||
version: '2.4' | ||
services: | ||
db: | ||
image: postgres | ||
my_app: | ||
build: . | ||
ports: | ||
- "8080:8080" |
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,9 @@ | ||
version: '2.4' | ||
services: | ||
db: | ||
image: postgres | ||
my_app: | ||
image: "eugen/test-app:latest" | ||
ports: | ||
- "8080:8080" | ||
|
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,45 @@ | ||
<?xml version="1.0" encoding="UTF-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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>com.baeldung.docker</groupId> | ||
<artifactId>docker</artifactId> | ||
<version>0.0.1</version> | ||
</parent> | ||
|
||
<artifactId>docker-sample-app</artifactId> | ||
<name>docker-sample-app</name> | ||
<description>Demo project for Spring Boot and Docker</description> | ||
|
||
<properties> | ||
<java.version>11</java.version> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
13 changes: 13 additions & 0 deletions
13
docker/docker-sample-app/src/main/java/com/baeldung/docker/app/DockAppApplication.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,13 @@ | ||
package com.baeldung.docker.app; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@SpringBootApplication | ||
public class DockAppApplication { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(DockAppApplication.class, args); | ||
} | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
docker/docker-sample-app/src/main/java/com/baeldung/docker/app/endpoint/MyController.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,13 @@ | ||
package com.baeldung.docker.app.endpoint; | ||
|
||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
public class MyController { | ||
|
||
@GetMapping | ||
public String version() { | ||
return "1.7"; | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
docker/docker-sample-app/src/main/resources/application.properties
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 @@ | ||
|
13 changes: 13 additions & 0 deletions
13
...r/docker-sample-app/src/test/java/com/baeldung/docker/app/DockAppApplicationUnitTest.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,13 @@ | ||
package com.baeldung.docker.app; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
|
||
@SpringBootTest | ||
class DockAppApplicationUnitTest { | ||
|
||
@Test | ||
void contextLoads() { | ||
} | ||
|
||
} |
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