Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
* 08:20:10.165436 - [Result{name='C3'}, Result{name='C1'}, Result{name='C2'}]
* </pre>
*/
@SuppressWarnings("StreamToString")
public class So61957439 {

public static void main(String[] args) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ void testDate() throws Exception {
assertEquals(45, d.getMinute());
assertEquals(30, d.getSecond());

d.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME);
assertEquals("2009-06-15T13:45:30", d.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*
* @author Mincong Huang
*/
@SuppressWarnings("EqualsHashCode") // hashCode() unimplemented for demo purpose
public class AthleteOnlyOverrideEquals {

private String email;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.mincongh.hashcode.bad;

/** @author Mincong Huang */
@SuppressWarnings("EqualsHashCode") // hashCode() unimplemented for demo purpose
public class PhoneNumberNoHash {

private final short areaCode;
Expand Down
5 changes: 0 additions & 5 deletions immutables/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,10 @@
<artifactId>java-examples-immutables</artifactId>
<name>Java Examples - Immutables</name>

<properties>
<immutables.version>2.8.8</immutables.version>
</properties>

<dependencies>
<dependency>
<groupId>org.immutables</groupId>
<artifactId>value</artifactId>
<version>${immutables.version}</version>
<scope>provided</scope>
</dependency>
<!--
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import static org.junit.jupiter.api.Assertions.fail;

import java.util.*;
import java.util.function.Predicate;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -71,13 +71,13 @@ private void assertListValues(List<Integer> list) {
assertEquals(3, list.get(2).intValue());
}

private <T> void assertOperationSupported(List<T> list, Predicate<List<T>> predicate) {
predicate.test(list);
private <T> void assertOperationSupported(List<T> list, Consumer<List<T>> action) {
action.accept(list);
}

private <T> void assertOperationUnsupported(List<T> list, Predicate<List<T>> predicate) {
private <T> void assertOperationUnsupported(List<T> list, Consumer<List<T>> action) {
try {
predicate.test(list);
action.accept(list);
fail();
} catch (UnsupportedOperationException e) {
// Ok
Expand Down
7 changes: 0 additions & 7 deletions jmh/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

<properties>
<commons.codec.version>1.15</commons.codec.version>
<jmh.version>1.26</jmh.version>
</properties>

<dependencies>
Expand All @@ -32,12 +31,6 @@
<version>${jmh.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-generator-annprocess</artifactId>
<version>${jmh.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public void testLegalArrayDeclaration() {

/** Question 31. */
@Test
@SuppressWarnings("ReturnValueIgnored")
public void testLocalDateImmutability() {
LocalDate date = LocalDate.of(2018, Month.APRIL, 30);
date.plusDays(2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public void comparingObjects() throws Exception {
* Cannot use a `Float` object to retrieve the value that was
* added to a `HashMap` using a `Double` instance.
*/
@SuppressWarnings("CollectionIncompatibleType")
String value2 = map.get(new Float(2.0));
assertThat(value2).isNull();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ public int hashCode() {
}

/** Only {@link #equals(Object)} is overridden. */
@SuppressWarnings("EqualsHashCode")
private static class Person_E extends Person {

Person_E(String name) {
Expand Down
1 change: 1 addition & 0 deletions ocp/src/test/java/io/mincong/ocpjp/date/Java8DateTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public void localDate_constructWithMonth() throws Exception {
}

@Test
@SuppressWarnings("TemporalAccessorGetChronoField") // Fail on purpose
public void localDate_temporalField() throws Exception {
LocalDate d = LocalDate.of(2018, 1, 2);
assertThat(d.get(ChronoField.YEAR)).isEqualTo(2018);
Expand Down
7 changes: 4 additions & 3 deletions ocp/src/test/java/io/mincong/ocpjp/nio/PathTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.mincong.ocpjp.nio;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.*;

import java.io.FileInputStream;
import java.io.IOException;
Expand Down Expand Up @@ -102,9 +102,10 @@ public void toAbsolutePath_nonexistent() throws Exception {
assertThat(p.getFileName().toString()).isEqualTo("nonexistent");
}

@Test(expected = NoSuchFileException.class)
@Test
public void toRealPath_nonexistent() throws Exception {
r.resolve("nonexistent").toRealPath();
assertThatThrownBy(() -> r.resolve("nonexistent").toRealPath())
.isInstanceOf(NoSuchFileException.class);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
*
* @author Mincong Huang
*/
@SuppressWarnings({"FormatString", "ArrayToString"})
public class FormattingTest {

@Rule public final TemporaryFolder tempFolder = new TemporaryFolder();
Expand Down
37 changes: 37 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@

<!-- Dependency versions -->
<assertjVersion>3.17.2</assertjVersion>
<immutablesVersion>2.8.8</immutablesVersion>
<jacksonVersion>2.11.3</jacksonVersion>
<jmh.version>1.26</jmh.version>
<junitVersion>4.13.1</junitVersion>
<junit5Version>5.7.0</junit5Version>
<errorProneVersion>2.4.0</errorProneVersion>
</properties>

<modules>
Expand Down Expand Up @@ -99,6 +102,11 @@
<artifactId>assertj-core</artifactId>
<version>${assertjVersion}</version>
</dependency>
<dependency>
<groupId>org.immutables</groupId>
<artifactId>value</artifactId>
<version>${immutablesVersion}</version>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down Expand Up @@ -157,7 +165,36 @@
</plugin>
</plugins>
</pluginManagement>

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<compilerArgs>
<arg>-XDcompilePolicy=simple</arg>
<arg>-Xplugin:ErrorProne</arg>
</compilerArgs>
<annotationProcessorPaths>
<!-- https://errorprone.info/docs/installation -->
<path>
<groupId>com.google.errorprone</groupId>
<artifactId>error_prone_core</artifactId>
<version>${errorProneVersion}</version>
</path>
<path>
<groupId>org.immutables</groupId>
<artifactId>value</artifactId>
<version>${immutablesVersion}</version>
</path>
<path>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-generator-annprocess</artifactId>
<version>${jmh.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
Expand Down
1 change: 1 addition & 0 deletions vavr/src/test/java/io/mincongh/vavr/JavaListTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ public void remove_ArraysArrayList() {
}

@Test
@SuppressWarnings("CollectionIncompatibleType")
public void remove_ArrayList() {
List<String> animals = new ArrayList<>();
animals.add("🐱");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ public int hashCode() {

@Override
public String toString() {
return String.format(Locale.ENGLISH, "+%.2d %s", code, number);
return String.format(Locale.ENGLISH, "+%02d %s", code, number);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package io.mincongh.xml.xstream.model;

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

import org.junit.jupiter.api.Test;

class PhoneNumberTest {

@Test
void toStr() {
var phoneNumber = new PhoneNumber(1, "2345");
assertThat(String.valueOf(phoneNumber)).isEqualTo("+01 2345");
}
}