Skip to content

Commit

Permalink
🎨 Gradle 6 - Format code
Browse files Browse the repository at this point in the history
  • Loading branch information
gilday committed Dec 20, 2019
1 parent 8b4cd9f commit e39b358
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@

import com.google.common.collect.ImmutableList;
import io.reactivex.Observable;

import java.util.List;

/** Demonstrates a library type that returns an RxJava type. */
public class RxHelloWorld {

/** @return an {@link Observable} that emits events "hello" and "world" before completing. */
public static Observable<String> hello() {
// Guava ImmutableList class is an implementation detail.
List<String> values = ImmutableList.of("hello", "world");
return Observable.fromIterable(values);
}
/** @return an {@link Observable} that emits events "hello" and "world" before completing. */
public static Observable<String> hello() {
// Guava ImmutableList class is an implementation detail.
List<String> values = ImmutableList.of("hello", "world");
return Observable.fromIterable(values);
}

private RxHelloWorld() {}
private RxHelloWorld() {
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package com.baeldung.gradle;

import static com.baeldung.gradle.RxHelloWorld.hello;

import org.junit.jupiter.api.Test;

import static com.baeldung.gradle.RxHelloWorld.hello;

/** Unit test for {@link RxHelloWorld}. */
final class RxHelloWorldUnitTest {

@Test
void it_emits_hello_world_values() {
hello().test().assertValues("hello", "world").assertComplete();
}
@Test void it_emits_hello_world_values() {
hello().test().assertValues("hello", "world").assertComplete();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,15 @@
import com.google.auto.service.AutoService;

/** Recursive implementation of the {@link FibonacciSequenceGenerator}. */
@AutoService(FibonacciSequenceGenerator.class)
public final class RecursiveFibonacci implements FibonacciSequenceGenerator {
@AutoService(FibonacciSequenceGenerator.class) public final class RecursiveFibonacci implements FibonacciSequenceGenerator {

@Override
public int generate(int nth) {
if (nth < 0) {
throw new IllegalArgumentException("sequence number must be 0 or greater");
@Override public int generate(int nth) {
if (nth < 0) {
throw new IllegalArgumentException("sequence number must be 0 or greater");
}
if (nth <= 1) {
return nth;
}
return generate(nth - 1) + generate(nth - 2);
}
if (nth <= 1) {
return nth;
}
return generate(nth - 1) + generate(nth - 2);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
* the fibonacci-spi project.
*/
final class RecursiveFibonacciUnitTest implements FibonacciSequenceGeneratorFixture {

@Override
public FibonacciSequenceGenerator provide() {
return new RecursiveFibonacci();
}
@Override public FibonacciSequenceGenerator provide() {
return new RecursiveFibonacci();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
/** Describes an SPI for a Fibonacci sequence generator function. */
public interface FibonacciSequenceGenerator {

/**
* @param nth the index of the number in the fibonacci sequence
* @return the nth number in the fibonacci sequence
*/
int generate(int nth);
/**
* @param nth the index of the number in the fibonacci sequence
* @return the nth number in the fibonacci sequence
*/
int generate(int nth);
}
Original file line number Diff line number Diff line change
@@ -1,31 +1,29 @@
package com.baeldung.fibonacci;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

import org.junit.jupiter.api.Test;

/**
* Reusable test fixture for {@link FibonacciSequenceGenerator} implementations. Tests will be
* skipped if no such implementation exists.
*/
public interface FibonacciSequenceGeneratorFixture {

/** @return the implementation of {@link FibonacciSequenceGenerator} to test. Must not be null */
FibonacciSequenceGenerator provide();
/** @return the implementation of {@link FibonacciSequenceGenerator} to test. Must not be null */
FibonacciSequenceGenerator provide();

@Test
default void when_sequence_index_is_negative_then_throws() {
final FibonacciSequenceGenerator generator = provide();
assertThrows(IllegalArgumentException.class, () -> generator.generate(-1));
}
@Test default void when_sequence_index_is_negative_then_throws() {
final FibonacciSequenceGenerator generator = provide();
assertThrows(IllegalArgumentException.class, () -> generator.generate(-1));
}

@Test
default void when_given_index_then_generates_fibonacci_number() {
final FibonacciSequenceGenerator generator = provide();
final int[] sequence = {0, 1, 1, 2, 3, 5, 8};
for (int i = 0; i < sequence.length; i++) {
assertEquals(sequence[i], generator.generate(i));
@Test default void when_given_index_then_generates_fibonacci_number() {
final FibonacciSequenceGenerator generator = provide();
final int[] sequence = { 0, 1, 1, 2, 3, 5, 8 };
for (int i = 0; i < sequence.length; i++) {
assertEquals(sequence[i], generator.generate(i));
}
}
}
}

0 comments on commit e39b358

Please sign in to comment.