Skip to content

Commit 428f340

Browse files
Merge remote-tracking branch 'origin/master'
2 parents aaed043 + 57ed00a commit 428f340

38 files changed

Lines changed: 4091 additions & 67 deletions

File tree

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ target/
2727

2828
spring-openid/src/main/resources/application.properties
2929
.recommenders/
30+

‎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: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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>junit</groupId>
14+
<artifactId>junit</artifactId>
15+
<version>4.12</version>
16+
</dependency>
17+
<dependency>
18+
<groupId>org.assertj</groupId>
19+
<artifactId>assertj-core</artifactId>
20+
<version>3.4.1</version>
21+
<scope>test</scope>
22+
</dependency>
23+
</dependencies>
24+
25+
<build>
26+
<plugins>
27+
<plugin>
28+
<groupId>org.apache.maven.plugins</groupId>
29+
<artifactId>maven-compiler-plugin</artifactId>
30+
<version>3.3</version>
31+
<configuration>
32+
<source>1.8</source>
33+
<target>1.8</target>
34+
</configuration>
35+
</plugin>
36+
</plugins>
37+
</build>
38+
</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: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.baeldung.date_migration;
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 Conversion {
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+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package com.baeldung.date_migration;
2+
3+
import java.text.ParseException;
4+
import java.time.*;
5+
import java.time.format.DateTimeFormatter;
6+
import java.time.temporal.ChronoUnit;
7+
8+
public class NewApi {
9+
public void currentTime() {
10+
ZonedDateTime now = ZonedDateTime.now();
11+
}
12+
13+
public void specificTime() {
14+
LocalDate birthDay = LocalDate.of(1990, Month.DECEMBER, 15);
15+
}
16+
17+
public void extractMonth() {
18+
Month month = LocalDateTime.now().getMonth();
19+
}
20+
21+
public void subtractTime() {
22+
LocalDateTime fiveHoursBefore = LocalDateTime.now().minusHours(5);
23+
}
24+
25+
public void alterField() {
26+
LocalDateTime inJune = LocalDateTime.now().withMonth(Month.JUNE.getValue());
27+
}
28+
29+
public void truncate() {
30+
LocalTime truncated = LocalTime.now().truncatedTo(ChronoUnit.HOURS);
31+
}
32+
33+
public void convertTimeZone() {
34+
ZonedDateTime centralEastern = LocalDateTime.now().atZone(ZoneId.of("CET"));
35+
}
36+
37+
public void getTimeSpan() {
38+
LocalDateTime now = LocalDateTime.now();
39+
LocalDateTime hourLater = LocalDateTime.now().plusHours(1);
40+
Duration span = Duration.between(now, hourLater);
41+
}
42+
43+
public void formatAndParse() throws ParseException {
44+
LocalDate now = LocalDate.now();
45+
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
46+
String formattedDate = now.format(formatter);
47+
LocalDate parsedDate = LocalDate.parse(formattedDate, formatter);
48+
}
49+
50+
public void daysInMonth() {
51+
int daysInMonth = YearMonth.of(1990, 2).lengthOfMonth();
52+
}
53+
54+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package com.baeldung.date_migration;
2+
3+
import java.text.ParseException;
4+
import java.text.SimpleDateFormat;
5+
import java.util.Calendar;
6+
import java.util.Date;
7+
import java.util.GregorianCalendar;
8+
import java.util.TimeZone;
9+
10+
public class OldApi {
11+
public void currentTime() {
12+
Date now = new Date();
13+
}
14+
15+
public void specificTime () {
16+
Date birthDay = new GregorianCalendar(1990, Calendar.DECEMBER, 15).getTime();
17+
}
18+
19+
public void extractMonth() {
20+
int month = new GregorianCalendar().get(Calendar.MONTH);
21+
}
22+
23+
public void subtractTime() {
24+
GregorianCalendar calendar = new GregorianCalendar();
25+
calendar.add(Calendar.HOUR_OF_DAY, -5);
26+
Date fiveHoursBefore = calendar.getTime();
27+
}
28+
29+
public void alterField() {
30+
GregorianCalendar calendar = new GregorianCalendar();
31+
calendar.set(Calendar.MONTH, Calendar.JUNE);
32+
Date inJune = calendar.getTime();
33+
}
34+
35+
public void truncate() {
36+
Calendar now = Calendar.getInstance();
37+
now.set(Calendar.MINUTE, 0);
38+
now.set(Calendar.SECOND, 0);
39+
now.set(Calendar.MILLISECOND, 0);
40+
Date truncated = now.getTime();
41+
}
42+
43+
public void convertTimeZone() {
44+
GregorianCalendar calendar = new GregorianCalendar();
45+
calendar.setTimeZone(TimeZone.getTimeZone("CET"));
46+
Date centralEastern = calendar.getTime();
47+
}
48+
49+
public void getTimeSpan() {
50+
GregorianCalendar calendar = new GregorianCalendar();
51+
Date now = new Date();
52+
calendar.add(Calendar.HOUR, 1);
53+
Date hourLater = calendar.getTime();
54+
long elapsed = hourLater.getTime() - now.getTime();
55+
}
56+
57+
public void formatAndParse() throws ParseException {
58+
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
59+
Date now = new Date();
60+
String formattedDate = dateFormat.format(now);
61+
Date parsedDate = dateFormat.parse(formattedDate);
62+
}
63+
64+
public void daysInMonth() {
65+
Calendar calendar = new GregorianCalendar(1990, Calendar.FEBRUARY, 20);
66+
int daysInMonth = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
67+
}
68+
}

‎core-java/.classpath‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
<attribute name="maven.pomderived" value="true"/>
2828
</attributes>
2929
</classpathentry>
30-
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
30+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
3131
<attributes>
3232
<attribute name="owner.project.facets" value="java"/>
3333
</attributes>

0 commit comments

Comments
 (0)