Skip to content

Commit

Permalink
updating dependencies and upgrading the app
Browse files Browse the repository at this point in the history
  • Loading branch information
pwittchen committed Aug 13, 2019
1 parent d01dc54 commit d0b80d0
Show file tree
Hide file tree
Showing 14 changed files with 31 additions and 132 deletions.
16 changes: 8 additions & 8 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,16 @@ repositories {
}

dependencies {
implementation 'io.javalin:javalin:2.1.1'
implementation 'org.slf4j:slf4j-simple:1.7.25'
implementation 'io.javalin:javalin:3.4.1'
implementation 'org.slf4j:slf4j-simple:1.7.26'
implementation 'org.joda:joda-money:1.0.1'
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'com.google.dagger:dagger:2.17'
apt 'com.google.dagger:dagger-compiler:2.17'
implementation 'com.google.dagger:dagger:2.24'
apt 'com.google.dagger:dagger-compiler:2.24'

testImplementation 'junit:junit:4.12'
testImplementation 'com.google.truth:truth:0.42'
testImplementation 'org.mockito:mockito-core:2.22.0'
testImplementation 'io.rest-assured:rest-assured:3.1.1'
testImplementation 'net.jodah:concurrentunit:0.4.3'
testImplementation 'com.google.truth:truth:1.0'
testImplementation 'org.mockito:mockito-core:3.0.0'
testImplementation 'io.rest-assured:rest-assured:4.0.0'
testImplementation 'net.jodah:concurrentunit:0.4.4'
}
17 changes: 9 additions & 8 deletions src/main/java/com/pwittchen/money/transfer/api/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
import com.pwittchen.money.transfer.api.controller.AccountController;
import com.pwittchen.money.transfer.api.controller.TransactionController;
import com.pwittchen.money.transfer.api.model.Response;
import io.javalin.ForbiddenResponse;
import io.javalin.Javalin;
import io.javalin.JavalinEvent;
import io.javalin.json.JavalinJson;
import io.javalin.http.ForbiddenResponse;
import io.javalin.plugin.json.JavalinJson;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -32,16 +31,18 @@ public static void main(String args[]) {
JavalinJson.setFromJsonMapper(gson::fromJson);
JavalinJson.setToJsonMapper(gson::toJson);

final Javalin app = Javalin.create()
.event(JavalinEvent.SERVER_STARTED, () -> LOG.info("server has started"))
.event(JavalinEvent.SERVER_START_FAILED, () -> LOG.error("server start has failed"))
.requestLogger((context, executionTimeMs) ->
final Javalin app = Javalin
.create(config -> config.requestLogger((context, executionTimeMs) ->
LOG.info("{} ms\t {}\t {} {}",
executionTimeMs,
context.req.getMethod(),
context.req.getRequestURI(),
context.req.getParameterMap().toString().replaceAll("^.|.$", "")
))
)))
.events(event -> {
event.serverStarted(() -> LOG.info("server has started"));
event.serverStartFailed(() -> LOG.error("server start has failed"));
})
.start(PORT);

app.get("/", context -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.pwittchen.money.transfer.api.model.Response;
import com.pwittchen.money.transfer.api.model.User;
import com.pwittchen.money.transfer.api.repository.AccountRepository;
import io.javalin.Context;
import io.javalin.http.Context;
import java.time.LocalDateTime;
import java.util.Optional;
import java.util.UUID;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.pwittchen.money.transfer.api.model.Transaction;
import com.pwittchen.money.transfer.api.repository.AccountRepository;
import com.pwittchen.money.transfer.api.repository.TransactionRepository;
import io.javalin.Context;
import io.javalin.http.Context;
import java.time.LocalDateTime;
import java.util.Optional;
import java.util.UUID;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.pwittchen.money.transfer.api.controller.context;

import io.javalin.Context;
import io.javalin.http.Context;

public interface ContextWrapper {
String pathParam(Context context, String param);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.pwittchen.money.transfer.api.controller.context;

import io.javalin.Context;
import io.javalin.http.Context;

public class DefaultContextWrapper implements ContextWrapper {

Expand Down
20 changes: 7 additions & 13 deletions src/main/java/com/pwittchen/money/transfer/api/model/Account.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,14 @@ public LocalDateTime updatedAt() {
}

@Override public boolean equals(Object o) {
if (this == o) {
return true;
}

if (o == null || getClass() != o.getClass()) {
return false;
}

if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Account account = (Account) o;
return Objects.equals(number, account.number)
&& Objects.equals(user, account.user)
&& Objects.equals(money, account.money)
&& Objects.equals(createdAt, account.createdAt)
&& Objects.equals(updatedAt, account.updatedAt);
return Objects.equals(number, account.number) &&
Objects.equals(user, account.user) &&
Objects.equals(money, account.money) &&
Objects.equals(createdAt, account.createdAt) &&
Objects.equals(updatedAt, account.updatedAt);
}

@Override public int hashCode() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ public interface AccountRepository {

Account create(Account account) throws Exception;

Account update(String number, Account account) throws Exception;

void withdrawMoney(Account account, Money money);

void putMoney(Account account, Money money);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,30 +50,6 @@ public InMemoryAccountRepository(AccountValidation accountValidation) {
return account;
}

@Override public Account update(String number, Account account) throws Exception {
if (!accounts.containsKey(number)) {
throw new AccountNotExistsException(account.number());
}

Optional<Exception> error = accountValidation.validate(account);

if (error.isPresent()) {
throw error.get();
}

final Account updatedAccount = Account.builder()
.number(number)
.user(account.user())
.money(account.money())
.createdAt(account.createdAt())
.updatedAt(LocalDateTime.now())
.build();

accounts.remove(number);
accounts.put(account.number(), updatedAccount);
return account;
}

@Override public void withdrawMoney(final Account account, final Money money) {
if (!accounts.containsKey(account.number())) {
throw new AccountNotExistsException(account.number());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.pwittchen.money.transfer.api.repository.AccountRepository;
import com.pwittchen.money.transfer.api.validation.exception.AccountAlreadyExistsException;
import com.pwittchen.money.transfer.api.validation.exception.AccountNotExistsException;
import io.javalin.Context;
import io.javalin.http.Context;
import java.util.HashMap;
import java.util.Optional;
import org.junit.Before;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import com.pwittchen.money.transfer.api.repository.AccountRepository;
import com.pwittchen.money.transfer.api.repository.TransactionRepository;
import com.pwittchen.money.transfer.api.validation.exception.TransferToTheSameAccountException;
import io.javalin.Context;
import io.javalin.http.Context;
import java.util.LinkedList;
import java.util.Optional;
import org.junit.Before;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,6 @@ public void objectsShouldNotBeEqualWhenOneIsNull() {
assertThat(account.equals(null)).isFalse();
}

@Test
public void objectsShouldBeInTheSameBucket() {
// when
Account accountOne = createAccount();
Account accountTwo = createAccount();

// then
assertThat(accountOne.hashCode() == accountTwo.hashCode()).isTrue();
}

@Test
public void shouldNotBeTheSameAsOtherObject() {
// given
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,67 +135,6 @@ public void shouldNotCreateAccountIfItErrorOccurred() throws Exception {
accountRepository.create(account);
}

@Test
@SuppressWarnings("OptionalGetWithoutIsPresent") // in this test, check is not needed
public void shouldUpdateAccount() throws Exception {
// given
Account account = createAccount();
Account anotherAccount = createAnotherAccount(account.number());
accountRepository.create(account);

// when
accountRepository.update(account.number(), anotherAccount);

// then
assertThat(accountRepository.get(account.number()).get()).isEqualTo(anotherAccount);
}

@Test
@SuppressWarnings("OptionalGetWithoutIsPresent") // in this test, check is not needed
public void shouldUpdateAccountAndItsNumber() throws Exception {
// given
Account account = createAccount();
String newAccountNumber = UUID.randomUUID().toString();
Account anotherAccount = createAnotherAccount(newAccountNumber);

accountRepository.create(account);

// when
accountRepository.update(account.number(), anotherAccount);

// then
assertThat(accountRepository.get(newAccountNumber).isPresent()).isTrue();
assertThat(accountRepository.get(account.number()).isPresent()).isFalse();
}

@Test
public void shouldNotUpdateAccountIfItDoesNotExist() throws Exception {
// given
Account account = createAccount();

// when
expectedException.expect(AccountNotExistsException.class);
expectedException.expectMessage(new AccountNotExistsException(account.number()).getMessage());

// then
accountRepository.update(account.number(), account);
}

@Test
public void shouldNotUpdateAccountIfErrorOccurred() throws Exception {
// given
Account account = createAccount();
when(accountValidation.validate(account)).thenReturn(Optional.of(new EmptyUserIdException()));

// when
expectedException.expect(EmptyUserIdException.class);
expectedException.expectMessage(new EmptyUserIdException().getMessage());

// then
accountRepository.create(account);
accountRepository.update(account.number(), account);
}

@Test
public void shouldWithdrawMoney() throws Exception {
// given
Expand Down
1 change: 1 addition & 0 deletions src/test/java/integration/RestApiIntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.junit.BeforeClass;
import org.junit.Test;

import static com.google.common.truth.Truth.assertThat;
import static io.restassured.RestAssured.delete;
import static io.restassured.RestAssured.get;
import static io.restassured.RestAssured.given;
Expand Down

0 comments on commit d0b80d0

Please sign in to comment.