Skip to content

Commit ce4bbd0

Browse files
Merge remote-tracking branch 'origin/master'
2 parents 955ba97 + 79ec294 commit ce4bbd0

204 files changed

Lines changed: 8568 additions & 893 deletions

File tree

Some content is hidden

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

‎README.md‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
The "REST with Spring" Classes
33
==============================
4-
After 5 months of work, here's the Master Class: <br/>
4+
After 5 months of work, here's the Master Class of REST With Spring: <br/>
55
**[>> THE REST WITH SPRING MASTER CLASS](http://www.baeldung.com/rest-with-spring-course?utm_source=github&utm_medium=social&utm_content=tutorials&utm_campaign=rws#master-class)**
66

77

@@ -19,3 +19,8 @@ Any IDE can be used to work with the projects, but if you're using Eclipse, cons
1919

2020
- import the included **formatter** in Eclipse:
2121
`https://github.com/eugenp/tutorials/tree/master/eclipse`
22+
23+
24+
CI - Jenkins
25+
================================
26+
This tutorials project is being built **[>> HERE](https://rest-security.ci.cloudbees.com/job/tutorials/)**

‎assertj/pom.xml‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>com.baeldung</groupId>
8+
<artifactId>assertj</artifactId>
9+
<version>1.0.0-SNAPSHOT</version>
10+
11+
<dependencies>
12+
<dependency>
13+
<groupId>com.google.guava</groupId>
14+
<artifactId>guava</artifactId>
15+
<version>19.0</version>
16+
</dependency>
17+
<dependency>
18+
<groupId>junit</groupId>
19+
<artifactId>junit</artifactId>
20+
<version>4.12</version>
21+
<scope>test</scope>
22+
</dependency>
23+
<dependency>
24+
<groupId>org.assertj</groupId>
25+
<artifactId>assertj-core</artifactId>
26+
<version>3.4.1</version>
27+
<scope>test</scope>
28+
</dependency>
29+
<dependency>
30+
<groupId>org.assertj</groupId>
31+
<artifactId>assertj-guava</artifactId>
32+
<version>3.0.0</version>
33+
</dependency>
34+
</dependencies>
35+
36+
<build>
37+
<plugins>
38+
<plugin>
39+
<groupId>org.apache.maven.plugins</groupId>
40+
<artifactId>maven-compiler-plugin</artifactId>
41+
<version>3.3</version>
42+
<configuration>
43+
<source>1.8</source>
44+
<target>1.8</target>
45+
</configuration>
46+
</plugin>
47+
</plugins>
48+
</build>
49+
</project>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.baeldung.assertj.introduction.domain;
2+
3+
public class Dog {
4+
private String name;
5+
private Float weight;
6+
7+
public Dog(String name, Float weight) {
8+
this.name = name;
9+
this.weight = weight;
10+
}
11+
12+
public String getName() {
13+
return name;
14+
}
15+
16+
public Float getWeight() {
17+
return weight;
18+
}
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.baeldung.assertj.introduction.domain;
2+
3+
public class Person {
4+
private String name;
5+
private Integer age;
6+
7+
public Person(String name, Integer age) {
8+
this.name = name;
9+
this.age = age;
10+
}
11+
12+
public String getName() {
13+
return name;
14+
}
15+
16+
public Integer getAge() {
17+
return age;
18+
}
19+
}
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
package com.baeldung.assertj.introduction;
2+
3+
import com.baeldung.assertj.introduction.domain.Dog;
4+
import com.baeldung.assertj.introduction.domain.Person;
5+
import org.assertj.core.util.Maps;
6+
import org.junit.Ignore;
7+
import org.junit.Test;
8+
9+
import java.io.ByteArrayInputStream;
10+
import java.io.File;
11+
import java.io.InputStream;
12+
import java.util.Arrays;
13+
import java.util.List;
14+
import java.util.Map;
15+
import java.util.NoSuchElementException;
16+
17+
import static org.assertj.core.api.Assertions.assertThat;
18+
import static org.assertj.core.api.Assertions.entry;
19+
import static org.assertj.core.api.Assertions.withPrecision;
20+
21+
public class AssertJCoreTest {
22+
23+
@Test
24+
public void whenComparingReferences_thenNotEqual() throws Exception {
25+
Dog fido = new Dog("Fido", 5.15f);
26+
Dog fidosClone = new Dog("Fido", 5.15f);
27+
28+
assertThat(fido).isNotEqualTo(fidosClone);
29+
}
30+
31+
@Test
32+
public void whenComparingFields_thenEqual() throws Exception {
33+
Dog fido = new Dog("Fido", 5.15f);
34+
Dog fidosClone = new Dog("Fido", 5.15f);
35+
36+
assertThat(fido).isEqualToComparingFieldByFieldRecursively(fidosClone);
37+
}
38+
39+
@Test
40+
public void whenCheckingForElement_thenContains() throws Exception {
41+
List<String> list = Arrays.asList("1", "2", "3");
42+
43+
assertThat(list)
44+
.contains("1");
45+
}
46+
47+
@Test
48+
public void whenCheckingForElement_thenMultipleAssertions() throws Exception {
49+
List<String> list = Arrays.asList("1", "2", "3");
50+
51+
assertThat(list).isNotEmpty();
52+
assertThat(list).startsWith("1");
53+
assertThat(list).doesNotContainNull();
54+
55+
assertThat(list)
56+
.isNotEmpty()
57+
.contains("1")
58+
.startsWith("1")
59+
.doesNotContainNull()
60+
.containsSequence("2", "3");
61+
}
62+
63+
@Test
64+
public void whenCheckingRunnable_thenIsInterface() throws Exception {
65+
assertThat(Runnable.class).isInterface();
66+
}
67+
68+
@Test
69+
public void whenCheckingCharacter_thenIsUnicode() throws Exception {
70+
char someCharacter = 'c';
71+
72+
assertThat(someCharacter)
73+
.isNotEqualTo('a')
74+
.inUnicode()
75+
.isGreaterThanOrEqualTo('b')
76+
.isLowerCase();
77+
}
78+
79+
@Test
80+
public void whenAssigningNSEExToException_thenIsAssignable() throws Exception {
81+
assertThat(Exception.class).isAssignableFrom(NoSuchElementException.class);
82+
}
83+
84+
@Test
85+
public void whenComparingWithOffset_thenEquals() throws Exception {
86+
assertThat(5.1).isEqualTo(5, withPrecision(1d));
87+
}
88+
89+
@Test
90+
public void whenCheckingString_then() throws Exception {
91+
assertThat("".isEmpty()).isTrue();
92+
}
93+
94+
@Test
95+
public void whenCheckingFile_then() throws Exception {
96+
final File someFile = File.createTempFile("aaa", "bbb");
97+
someFile.deleteOnExit();
98+
99+
assertThat(someFile)
100+
.exists()
101+
.isFile()
102+
.canRead()
103+
.canWrite();
104+
}
105+
106+
@Test
107+
public void whenCheckingIS_then() throws Exception {
108+
InputStream given = new ByteArrayInputStream("foo".getBytes());
109+
InputStream expected = new ByteArrayInputStream("foo".getBytes());
110+
111+
assertThat(given).hasSameContentAs(expected);
112+
}
113+
114+
@Test
115+
public void whenGivenMap_then() throws Exception {
116+
Map<Integer, String> map = Maps.newHashMap(2, "a");
117+
118+
assertThat(map)
119+
.isNotEmpty()
120+
.containsKey(2)
121+
.doesNotContainKeys(10)
122+
.contains(entry(2, "a"));
123+
}
124+
125+
@Test
126+
public void whenGivenException_then() throws Exception {
127+
Exception ex = new Exception("abc");
128+
129+
assertThat(ex)
130+
.hasNoCause()
131+
.hasMessageEndingWith("c");
132+
}
133+
134+
@Ignore // IN ORDER TO TEST, REMOVE THIS LINE
135+
@Test
136+
public void whenRunningAssertion_thenDescribed() throws Exception {
137+
Person person = new Person("Alex", 34);
138+
139+
assertThat(person.getAge())
140+
.as("%s's age should be equal to 100")
141+
.isEqualTo(100);
142+
}
143+
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
package com.baeldung.assertj.introduction;
2+
3+
import com.google.common.base.Optional;
4+
import com.google.common.collect.HashBasedTable;
5+
import com.google.common.collect.Multimap;
6+
import com.google.common.collect.Multimaps;
7+
import com.google.common.collect.Range;
8+
import com.google.common.collect.Sets;
9+
import com.google.common.collect.Table;
10+
import com.google.common.collect.TreeRangeMap;
11+
import com.google.common.io.Files;
12+
import org.assertj.guava.data.MapEntry;
13+
import org.junit.Test;
14+
15+
import java.io.File;
16+
import java.util.HashMap;
17+
18+
import static org.assertj.guava.api.Assertions.assertThat;
19+
import static org.assertj.guava.api.Assertions.entry;
20+
21+
public class AssertJGuavaTest {
22+
23+
@Test
24+
public void givenTwoEmptyFiles_whenComparingContent_thenEqual() throws Exception {
25+
final File temp = File.createTempFile("bael", "dung");
26+
final File temp2 = File.createTempFile("bael", "dung2");
27+
28+
assertThat(Files.asByteSource(temp))
29+
.hasSize(0)
30+
.hasSameContentAs(Files.asByteSource(temp2));
31+
}
32+
33+
@Test
34+
public void givenMultimap_whenVerifying_thenCorrect() throws Exception {
35+
final Multimap<Integer, String> mmap = Multimaps.newMultimap(new HashMap<>(), Sets::newHashSet);
36+
mmap.put(1, "one");
37+
mmap.put(1, "1");
38+
39+
assertThat(mmap)
40+
.hasSize(2)
41+
.containsKeys(1)
42+
.contains(entry(1, "one"))
43+
.contains(entry(1, "1"));
44+
}
45+
46+
@Test
47+
public void givenOptional_whenVerifyingContent_thenShouldBeEqual() throws Exception {
48+
final Optional<String> something = Optional.of("something");
49+
50+
assertThat(something)
51+
.isPresent()
52+
.extractingValue()
53+
.isEqualTo("something");
54+
}
55+
56+
@Test
57+
public void givenRange_whenVerifying_thenShouldBeCorrect() throws Exception {
58+
final Range<String> range = Range.openClosed("a", "g");
59+
60+
assertThat(range)
61+
.hasOpenedLowerBound()
62+
.isNotEmpty()
63+
.hasClosedUpperBound()
64+
.contains("b");
65+
}
66+
67+
@Test
68+
public void givenRangeMap_whenVerifying_thenShouldBeCorrect() throws Exception {
69+
final TreeRangeMap<Integer, String> map = TreeRangeMap.create();
70+
71+
map.put(Range.closed(0, 60), "F");
72+
map.put(Range.closed(61, 70), "D");
73+
74+
assertThat(map)
75+
.isNotEmpty()
76+
.containsKeys(0)
77+
.contains(MapEntry.entry(34, "F"));
78+
}
79+
80+
@Test
81+
public void givenTable_whenVerifying_thenShouldBeCorrect() throws Exception {
82+
final Table<Integer, String, String> table = HashBasedTable.create(2, 2);
83+
84+
table.put(1, "A", "PRESENT");
85+
table.put(1, "B", "ABSENT");
86+
87+
assertThat(table)
88+
.hasRowCount(1)
89+
.containsValues("ABSENT")
90+
.containsCell(1, "B", "ABSENT");
91+
}
92+
93+
94+
95+
96+
}

‎core-java-8/pom.xml‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@
6363
<scope>test</scope>
6464
</dependency>
6565

66+
<dependency>
67+
<groupId>org.assertj</groupId>
68+
<artifactId>assertj-core</artifactId>
69+
<version>3.4.1</version>
70+
</dependency>
71+
6672
<dependency>
6773
<groupId>org.mockito</groupId>
6874
<artifactId>mockito-core</artifactId>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.baeldung.dateapi;
2+
3+
import java.time.Instant;
4+
import java.time.ZoneId;
5+
import java.time.ZonedDateTime;
6+
import java.util.Date;
7+
import java.util.GregorianCalendar;
8+
import java.util.TimeZone;
9+
10+
public class ConversionExample {
11+
public static void main(String[] args) {
12+
Instant instantFromCalendar = GregorianCalendar.getInstance().toInstant();
13+
ZonedDateTime zonedDateTimeFromCalendar = new GregorianCalendar().toZonedDateTime();
14+
Date dateFromInstant = Date.from(Instant.now());
15+
GregorianCalendar calendarFromZonedDateTime = GregorianCalendar.from(ZonedDateTime.now());
16+
Instant instantFromDate = new Date().toInstant();
17+
ZoneId zoneIdFromTimeZone = TimeZone.getTimeZone("PST").toZoneId();
18+
}
19+
}

0 commit comments

Comments
 (0)