Skip to content

Commit

Permalink
Refactor AddReparationInteractorTest (+1 squashed commits)
Browse files Browse the repository at this point in the history
Squashed commits:

[156093a] Refactor AddReparationInteractorTest
  • Loading branch information
palpa committed Mar 15, 2015
1 parent 7ce5bd1 commit 3119f9c
Show file tree
Hide file tree
Showing 21 changed files with 199 additions and 277 deletions.
Original file line number Diff line number Diff line change
@@ -1,19 +1,7 @@
package org.reparationservice.inmemory;

import org.reparationservice.inmemory.entities.devicetype.DeviceTypeImpl;
import org.reparationservice.inmemory.entities.worker.WorkerImpl;
import org.reparationservice.inmemory.entities.customer.CustomerImpl;
import org.reparationservice.inmemory.entities.customer.DeviceImpl;
import org.reparationservice.inmemory.entities.customer.ReparationImpl;
import org.reparationservice.entities.customer.Customer;
import org.reparationservice.entities.customer.CustomerGateway;
import org.reparationservice.entities.customer.Device;
import org.reparationservice.entities.customer.Reparation;
import org.reparationservice.entities.customer.ReparationDTO;
import org.reparationservice.entities.devicetype.DeviceType;
import org.reparationservice.entities.devicetype.DeviceTypeGateway;
import org.reparationservice.entities.worker.Worker;
import org.reparationservice.entities.worker.WorkerDTO;
import org.reparationservice.entities.worker.WorkerGateway;

public final class InMemoryConfigurator {
Expand All @@ -33,23 +21,4 @@ public static WorkerGateway getWorkerGateway() {
return new ReparationServiceImpl();
}

public static Customer getNewCustomer(long customerId) {
return new CustomerImpl(customerId);
}

public static Device getNewDevice(long deviceSerialNumber) {
return new DeviceImpl(deviceSerialNumber);
}

public static DeviceType getNewDeviceType(String deviceTypeDescription) {
return new DeviceTypeImpl(deviceTypeDescription);
}

public static Reparation getNewReparation(ReparationDTO reparationDTO) {
return new ReparationImpl(reparationDTO);
}

public static Worker getNewWorker(WorkerDTO workerDTO) {
return new WorkerImpl(workerDTO);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
import org.reparationservice.entities.devicetype.DeviceType;
import org.reparationservice.entities.worker.Worker;
import org.reparationservice.entities.worker.WorkerDTO;
import org.reparationservice.inmemory.entities.customer.CustomerImpl;
import org.reparationservice.inmemory.entities.devicetype.DeviceTypeImpl;
import org.reparationservice.inmemory.entities.worker.WorkerImpl;

public class ReparationServiceImpl implements
ReparationService {
Expand All @@ -18,7 +21,7 @@ public class ReparationServiceImpl implements

@Override
public void addWorker(WorkerDTO workerDTO) {
Worker worker = InMemoryConfigurator.getNewWorker(workerDTO);
Worker worker = new WorkerImpl(workerDTO);
workers.put(workerDTO.getUserName(), worker);
}

Expand All @@ -36,8 +39,8 @@ public Worker getWorkerByUserName(String workerUserName) {

@Override
public void addDeviceType(String deviceTypeDescription) {
this.deviceTypes.put(deviceTypeDescription,
InMemoryConfigurator.getNewDeviceType(deviceTypeDescription));
this.deviceTypes.put(deviceTypeDescription,
new DeviceTypeImpl(deviceTypeDescription));
}

@Override
Expand All @@ -56,6 +59,6 @@ public Customer getCustomerById(long customerId) {

@Override
public void addCustomer(long customerId) {
customers.put(customerId, InMemoryConfigurator.getNewCustomer(customerId));
customers.put(customerId, new CustomerImpl(customerId));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import org.reparationservice.entities.customer.Customer;
import org.reparationservice.entities.customer.Device;
import org.reparationservice.inmemory.InMemoryConfigurator;

import java.util.HashMap;
import java.util.Map;
Expand All @@ -29,7 +28,7 @@ public Device getDevice(long deviceSerialNumber) {

@Override
public void addDevice(long deviceSerialNumber) {
devices.put(deviceSerialNumber,
InMemoryConfigurator.getNewDevice(deviceSerialNumber));
devices.put(deviceSerialNumber,
new DeviceImpl(deviceSerialNumber));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import org.joda.time.DateTime;

import org.reparationservice.inmemory.InMemoryConfigurator;
import org.reparationservice.entities.customer.Device;
import org.reparationservice.entities.customer.Reparation;
import org.reparationservice.entities.customer.ReparationDTO;
Expand All @@ -30,7 +29,7 @@ public Reparation getReparation(DateTime creationDate) {

@Override
public void addReparation(ReparationDTO reparationDTO) {
reparations.put(reparationDTO.getCreationDate(),
InMemoryConfigurator.getNewReparation(reparationDTO));
reparations.put(reparationDTO.getCreationDate(),
new ReparationImpl(reparationDTO));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public final class ReparationImpl extends Reparation {

public ReparationImpl(ReparationDTO reparationDTO) {
this.creationDate = reparationDTO.getCreationDate();
this.failure = reparationDTO.getFailure();
this.failure = reparationDTO.getDeviceFailure();
}

@Override
Expand All @@ -20,7 +20,7 @@ public DateTime getCreationDate() {
}

@Override
public String getFailure() {
public String getDeviceFailure() {
return failure;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.reparationservice.inmemory.InMemoryConfigurator;
import org.reparationservice.entities.customer.Customer;
import org.reparationservice.entities.customer.Device;

Expand Down Expand Up @@ -59,6 +58,6 @@ private void assertDevice(Device device, long deviceSerialNumber) {
}

private Customer createCustomer(long customerId) {
return InMemoryConfigurator.getNewCustomer(customerId);
}
return new CustomerImpl(customerId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,58 +2,62 @@

import de.bechte.junit.runners.context.HierarchicalContextRunner;
import org.joda.time.DateTime;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.reparationservice.entities.customer.Device;
import org.reparationservice.entities.customer.Reparation;
import org.reparationservice.entities.customer.ReparationDTO;
import org.reparationservice.inmemory.InMemoryConfigurator;

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

@RunWith(HierarchicalContextRunner.class)
public class DeviceTest {
private static final DateTime REP_CREATION_DATE_1 = DateTime.now();
private static final DateTime REP_CREATION_DATE_2 = REP_CREATION_DATE_1
.plusDays(1);
private Device device;
private static final int SERIAL_NUMBER = 150;

@Before
public void givenDevice() {
device = InMemoryConfigurator.getNewDevice(SERIAL_NUMBER);
}

@Test
public void creation() {
assertThat(device).isNotNull();
assertThat(device.getSerialNumber()).isEqualTo(SERIAL_NUMBER);
}

public class ReparationOps
{
private static final String REP_FAILURE = "failure";

@Test
public void getReparation() {
device.addReparation(newRepDTO(REP_CREATION_DATE_1));
device.addReparation(newRepDTO(REP_CREATION_DATE_2));

Reparation reparation1 = device
.getReparation(REP_CREATION_DATE_1);
assertThat(reparation1).isNotNull();
assertThat(reparation1.getCreationDate()).isEqualTo(
REP_CREATION_DATE_1);
Reparation reparation2 = device
.getReparation(REP_CREATION_DATE_2);
assertThat(reparation2).isNotNull();
assertThat(reparation2.getCreationDate()).isEqualTo(
REP_CREATION_DATE_2);
}

private ReparationDTO newRepDTO(DateTime creationDate) {
return new ReparationDTO(creationDate, REP_FAILURE);
}
}
private static final int SERIAL_NUMBER = 150;
private static final DateTime REP_CREATION_DATE_1 = DateTime.now();
private static final DateTime REP_CREATION_DATE_2 = REP_CREATION_DATE_1
.plusDays(1);
private static final String REP_FAILURE = "failure";

@Test
public void addGetReparation() {
Device device = new DeviceImpl((long) SERIAL_NUMBER);
device.addReparation(newRepDTO(REP_CREATION_DATE_1));
device.addReparation(newRepDTO(REP_CREATION_DATE_2));

Reparation reparation1 = device
.getReparation(REP_CREATION_DATE_1);
assertThat(reparation1).isNotNull();
assertThat(reparation1.getCreationDate()).isEqualTo(
REP_CREATION_DATE_1);
assertThat(reparation1.getDeviceFailure()).isEqualTo(
REP_FAILURE);

Reparation reparation2 = device
.getReparation(REP_CREATION_DATE_2);
assertThat(reparation2).isNotNull();
assertThat(reparation2.getCreationDate()).isEqualTo(
REP_CREATION_DATE_2);
assertThat(reparation2.getDeviceFailure()).isEqualTo(
REP_FAILURE);
}

private ReparationDTO newRepDTO(final DateTime creationDate) {
return new ReparationDTO() {
@Override public DateTime getCreationDate() {
return creationDate;
}

@Override public String getDeviceFailure() {
return REP_FAILURE;
}

@Override public String getUrgency() {
return null;
}

@Override public String getObservations() {
return null;
}
};
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import org.junit.Test;
import org.reparationservice.entities.devicetype.DeviceType;
import org.reparationservice.inmemory.InMemoryConfigurator;

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

Expand All @@ -11,7 +10,7 @@ public class DeviceTypeTest {

@Test
public void testDeviceTypeImpl() {
DeviceType device = InMemoryConfigurator.getNewDeviceType(DEVICE_DESCRIPTION);
DeviceType device = new DeviceTypeImpl(DEVICE_DESCRIPTION);
assertThat(device).isNotNull();
assertThat(device.getDescription()).isEqualTo(DEVICE_DESCRIPTION);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import org.junit.Test;
import org.reparationservice.entities.worker.Worker;
import org.reparationservice.entities.worker.WorkerDTO;
import org.reparationservice.inmemory.InMemoryConfigurator;

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

Expand All @@ -12,7 +11,7 @@ public class WorkerTest {

@Test
public void createWorker() {
Worker worker = InMemoryConfigurator.getNewWorker(new WorkerDTO(USER_NAME));
Worker worker = new WorkerImpl(new WorkerDTO(USER_NAME));
assertThat(worker).isNotNull();
assertThat(worker.getUserName()).isEqualTo(USER_NAME);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
public abstract class Reparation {
public static final Reparation NULL = new Reparation() {
@Override
public String getFailure() {
public String getDeviceFailure() {
return "";
}

Expand All @@ -17,5 +17,5 @@ public DateTime getCreationDate() {

public abstract DateTime getCreationDate();

public abstract String getFailure();
public abstract String getDeviceFailure();
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,12 @@

import org.joda.time.DateTime;

public final class ReparationDTO {
private final DateTime creationDate;
private final String failure;
public interface ReparationDTO {
DateTime getCreationDate();

public ReparationDTO(DateTime creationDate, String failure) {
this.creationDate = creationDate;
this.failure = failure;
}
String getDeviceFailure();

public DateTime getCreationDate() {
return creationDate;
}
String getUrgency();

public String getFailure() {
return failure;
}
String getObservations();
}
Loading

0 comments on commit 3119f9c

Please sign in to comment.