Skip to content

Commit

Permalink
Add test for issue assertj#1146
Browse files Browse the repository at this point in the history
  • Loading branch information
joel-costigliola committed Jan 14, 2018
1 parent 277bae8 commit 1f77fbe
Showing 1 changed file with 40 additions and 38 deletions.
78 changes: 40 additions & 38 deletions src/test/java/org/assertj/core/api/SoftAssertionsTest.java
Expand Up @@ -12,18 +12,16 @@
*/
package org.assertj.core.api;

import static java.lang.String.format;
import static java.util.Arrays.asList;
import static java.util.concurrent.CompletableFuture.completedFuture;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.Assertions.fail;
import static org.assertj.core.api.Assertions.shouldHaveThrown;
import static org.assertj.core.api.Assertions.tuple;
import static org.assertj.core.api.SoftAssertions.assertSoftly;
import static org.assertj.core.util.Arrays.array;
import static org.assertj.core.util.DateUtil.parseDatetime;
import static org.assertj.core.util.Sets.newLinkedHashSet;
import org.assertj.core.api.ThrowableAssert.ThrowingCallable;
import org.assertj.core.api.iterable.Extractor;
import org.assertj.core.api.test.ComparableExample;
import org.assertj.core.data.MapEntry;
import org.assertj.core.test.CartoonCharacter;
import org.assertj.core.test.Maps;
import org.assertj.core.test.Name;
import org.assertj.core.util.Lists;
import org.junit.Before;
import org.junit.Test;

import java.io.ByteArrayInputStream;
import java.io.File;
Expand All @@ -33,14 +31,7 @@
import java.time.LocalTime;
import java.time.OffsetTime;
import java.time.ZoneOffset;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.OptionalDouble;
import java.util.OptionalInt;
import java.util.OptionalLong;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.concurrent.atomic.AtomicBoolean;
Expand All @@ -59,16 +50,14 @@
import java.util.stream.LongStream;
import java.util.stream.Stream;

import org.assertj.core.api.ThrowableAssert.ThrowingCallable;
import org.assertj.core.api.iterable.Extractor;
import org.assertj.core.api.test.ComparableExample;
import org.assertj.core.data.MapEntry;
import org.assertj.core.test.CartoonCharacter;
import org.assertj.core.test.Maps;
import org.assertj.core.test.Name;
import org.assertj.core.util.Lists;
import org.junit.Before;
import org.junit.Test;
import static java.lang.String.format;
import static java.util.Arrays.asList;
import static java.util.concurrent.CompletableFuture.completedFuture;
import static org.assertj.core.api.Assertions.*;
import static org.assertj.core.api.SoftAssertions.assertSoftly;
import static org.assertj.core.util.Arrays.array;
import static org.assertj.core.util.DateUtil.parseDatetime;
import static org.assertj.core.util.Sets.newLinkedHashSet;

/**
* Tests for <code>{@link SoftAssertions}</code>.
Expand Down Expand Up @@ -145,11 +134,11 @@ public void should_be_able_to_catch_exceptions_thrown_by_map_assertions() {
} catch (SoftAssertionError e) {
List<String> errors = e.getErrors();
assertThat(errors).contains(String.format("%nExpecting:%n"
+ " <{\"54\"=\"55\"}>%n"
+ "to contain:%n"
+ " <[MapEntry[key=\"1\", value=\"2\"]]>%n"
+ "but could not find:%n"
+ " <[MapEntry[key=\"1\", value=\"2\"]]>%n"));
+ " <{\"54\"=\"55\"}>%n"
+ "to contain:%n"
+ " <[MapEntry[key=\"1\", value=\"2\"]]>%n"
+ "but could not find:%n"
+ " <[MapEntry[key=\"1\", value=\"2\"]]>%n"));

}
}
Expand Down Expand Up @@ -825,6 +814,7 @@ public TolkienCharacterAssert hasAge(int age) {
return this;
}
}

public static class TolkienSoftAssertions extends SoftAssertions {

public TolkienCharacterAssert assertThat(TolkienCharacter actual) {
Expand Down Expand Up @@ -882,17 +872,29 @@ public void should_assert_using_assertSoftly() {
.hasMessageContaining("blue");
}

public void should_work_with_atomic() throws Exception {
@Test
public void should_work_with_atomic() {
// simple atomic value
softly.assertThat(new AtomicBoolean(true)).isTrue();
softly.assertThat(new AtomicInteger(1)).hasValueGreaterThan(0);
softly.assertThat(new AtomicLong(1L)).hasValueGreaterThan(0L);
softly.assertThat(new AtomicReference<>("abc")).hasValue("abc");
// atomic array value
softly.assertThat(new AtomicIntegerArray(new int[] { 1, 2, 3 })).containsExactly(1, 2, 3);
softly.assertThat(new AtomicLongArray(new long[] {1L, 2L, 3L})).containsExactly(1L, 2L, 3L);
softly.assertThat(new AtomicLongArray(new long[] { 1L, 2L, 3L })).containsExactly(1L, 2L, 3L);
softly.assertThat(new AtomicReferenceArray<>(array("a", "b", "c"))).containsExactly("a", "b", "c");
softly.assertAll();
}


@Test
public void name() {
Map<String, String> data = new HashMap<>();
data.put("one", "1");
data.put("two", "2");
data.put("three", "3");
try (final AutoCloseableSoftAssertions softly = new AutoCloseableSoftAssertions()) {
// softly.assertThat(data).containsExactly(entry("one", "2"));
softly.assertThat(data).extracting("one", "two");
}
}
}

0 comments on commit 1f77fbe

Please sign in to comment.