Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
slavisa-baeldung committed Jul 9, 2016
2 parents 955ba97 + 79ec294 commit ce4bbd0
Show file tree
Hide file tree
Showing 204 changed files with 8,568 additions and 893 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

The "REST with Spring" Classes
==============================
After 5 months of work, here's the Master Class: <br/>
After 5 months of work, here's the Master Class of REST With Spring: <br/>
**[>> 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)**


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

- import the included **formatter** in Eclipse:
`https://github.com/eugenp/tutorials/tree/master/eclipse`


CI - Jenkins
================================
This tutorials project is being built **[>> HERE](https://rest-security.ci.cloudbees.com/job/tutorials/)**
49 changes: 49 additions & 0 deletions assertj/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.baeldung</groupId>
<artifactId>assertj</artifactId>
<version>1.0.0-SNAPSHOT</version>

<dependencies>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>19.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.4.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-guava</artifactId>
<version>3.0.0</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.baeldung.assertj.introduction.domain;

public class Dog {
private String name;
private Float weight;

public Dog(String name, Float weight) {
this.name = name;
this.weight = weight;
}

public String getName() {
return name;
}

public Float getWeight() {
return weight;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.baeldung.assertj.introduction.domain;

public class Person {
private String name;
private Integer age;

public Person(String name, Integer age) {
this.name = name;
this.age = age;
}

public String getName() {
return name;
}

public Integer getAge() {
return age;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
package com.baeldung.assertj.introduction;

import com.baeldung.assertj.introduction.domain.Dog;
import com.baeldung.assertj.introduction.domain.Person;
import org.assertj.core.util.Maps;
import org.junit.Ignore;
import org.junit.Test;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.InputStream;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.entry;
import static org.assertj.core.api.Assertions.withPrecision;

public class AssertJCoreTest {

@Test
public void whenComparingReferences_thenNotEqual() throws Exception {
Dog fido = new Dog("Fido", 5.15f);
Dog fidosClone = new Dog("Fido", 5.15f);

assertThat(fido).isNotEqualTo(fidosClone);
}

@Test
public void whenComparingFields_thenEqual() throws Exception {
Dog fido = new Dog("Fido", 5.15f);
Dog fidosClone = new Dog("Fido", 5.15f);

assertThat(fido).isEqualToComparingFieldByFieldRecursively(fidosClone);
}

@Test
public void whenCheckingForElement_thenContains() throws Exception {
List<String> list = Arrays.asList("1", "2", "3");

assertThat(list)
.contains("1");
}

@Test
public void whenCheckingForElement_thenMultipleAssertions() throws Exception {
List<String> list = Arrays.asList("1", "2", "3");

assertThat(list).isNotEmpty();
assertThat(list).startsWith("1");
assertThat(list).doesNotContainNull();

assertThat(list)
.isNotEmpty()
.contains("1")
.startsWith("1")
.doesNotContainNull()
.containsSequence("2", "3");
}

@Test
public void whenCheckingRunnable_thenIsInterface() throws Exception {
assertThat(Runnable.class).isInterface();
}

@Test
public void whenCheckingCharacter_thenIsUnicode() throws Exception {
char someCharacter = 'c';

assertThat(someCharacter)
.isNotEqualTo('a')
.inUnicode()
.isGreaterThanOrEqualTo('b')
.isLowerCase();
}

@Test
public void whenAssigningNSEExToException_thenIsAssignable() throws Exception {
assertThat(Exception.class).isAssignableFrom(NoSuchElementException.class);
}

@Test
public void whenComparingWithOffset_thenEquals() throws Exception {
assertThat(5.1).isEqualTo(5, withPrecision(1d));
}

@Test
public void whenCheckingString_then() throws Exception {
assertThat("".isEmpty()).isTrue();
}

@Test
public void whenCheckingFile_then() throws Exception {
final File someFile = File.createTempFile("aaa", "bbb");
someFile.deleteOnExit();

assertThat(someFile)
.exists()
.isFile()
.canRead()
.canWrite();
}

@Test
public void whenCheckingIS_then() throws Exception {
InputStream given = new ByteArrayInputStream("foo".getBytes());
InputStream expected = new ByteArrayInputStream("foo".getBytes());

assertThat(given).hasSameContentAs(expected);
}

@Test
public void whenGivenMap_then() throws Exception {
Map<Integer, String> map = Maps.newHashMap(2, "a");

assertThat(map)
.isNotEmpty()
.containsKey(2)
.doesNotContainKeys(10)
.contains(entry(2, "a"));
}

@Test
public void whenGivenException_then() throws Exception {
Exception ex = new Exception("abc");

assertThat(ex)
.hasNoCause()
.hasMessageEndingWith("c");
}

@Ignore // IN ORDER TO TEST, REMOVE THIS LINE
@Test
public void whenRunningAssertion_thenDescribed() throws Exception {
Person person = new Person("Alex", 34);

assertThat(person.getAge())
.as("%s's age should be equal to 100")
.isEqualTo(100);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package com.baeldung.assertj.introduction;

import com.google.common.base.Optional;
import com.google.common.collect.HashBasedTable;
import com.google.common.collect.Multimap;
import com.google.common.collect.Multimaps;
import com.google.common.collect.Range;
import com.google.common.collect.Sets;
import com.google.common.collect.Table;
import com.google.common.collect.TreeRangeMap;
import com.google.common.io.Files;
import org.assertj.guava.data.MapEntry;
import org.junit.Test;

import java.io.File;
import java.util.HashMap;

import static org.assertj.guava.api.Assertions.assertThat;
import static org.assertj.guava.api.Assertions.entry;

public class AssertJGuavaTest {

@Test
public void givenTwoEmptyFiles_whenComparingContent_thenEqual() throws Exception {
final File temp = File.createTempFile("bael", "dung");
final File temp2 = File.createTempFile("bael", "dung2");

assertThat(Files.asByteSource(temp))
.hasSize(0)
.hasSameContentAs(Files.asByteSource(temp2));
}

@Test
public void givenMultimap_whenVerifying_thenCorrect() throws Exception {
final Multimap<Integer, String> mmap = Multimaps.newMultimap(new HashMap<>(), Sets::newHashSet);
mmap.put(1, "one");
mmap.put(1, "1");

assertThat(mmap)
.hasSize(2)
.containsKeys(1)
.contains(entry(1, "one"))
.contains(entry(1, "1"));
}

@Test
public void givenOptional_whenVerifyingContent_thenShouldBeEqual() throws Exception {
final Optional<String> something = Optional.of("something");

assertThat(something)
.isPresent()
.extractingValue()
.isEqualTo("something");
}

@Test
public void givenRange_whenVerifying_thenShouldBeCorrect() throws Exception {
final Range<String> range = Range.openClosed("a", "g");

assertThat(range)
.hasOpenedLowerBound()
.isNotEmpty()
.hasClosedUpperBound()
.contains("b");
}

@Test
public void givenRangeMap_whenVerifying_thenShouldBeCorrect() throws Exception {
final TreeRangeMap<Integer, String> map = TreeRangeMap.create();

map.put(Range.closed(0, 60), "F");
map.put(Range.closed(61, 70), "D");

assertThat(map)
.isNotEmpty()
.containsKeys(0)
.contains(MapEntry.entry(34, "F"));
}

@Test
public void givenTable_whenVerifying_thenShouldBeCorrect() throws Exception {
final Table<Integer, String, String> table = HashBasedTable.create(2, 2);

table.put(1, "A", "PRESENT");
table.put(1, "B", "ABSENT");

assertThat(table)
.hasRowCount(1)
.containsValues("ABSENT")
.containsCell(1, "B", "ABSENT");
}




}
6 changes: 6 additions & 0 deletions core-java-8/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.4.1</version>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.baeldung.dateapi;

import java.time.Instant;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.TimeZone;

public class ConversionExample {
public static void main(String[] args) {
Instant instantFromCalendar = GregorianCalendar.getInstance().toInstant();
ZonedDateTime zonedDateTimeFromCalendar = new GregorianCalendar().toZonedDateTime();
Date dateFromInstant = Date.from(Instant.now());
GregorianCalendar calendarFromZonedDateTime = GregorianCalendar.from(ZonedDateTime.now());
Instant instantFromDate = new Date().toInstant();
ZoneId zoneIdFromTimeZone = TimeZone.getTimeZone("PST").toZoneId();
}
}
Loading

0 comments on commit ce4bbd0

Please sign in to comment.