Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fb add pg #774

Closed
wants to merge 2 commits into from
Closed
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
26 changes: 13 additions & 13 deletions src/main/java/ch/heigvd/res/chill/domain/Bartender.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@

public class Bartender {

public GreetingsResponse greet(GreetingsRequest request) {
return new GreetingsResponse("hello, how can I help you?");
}
public GreetingsResponse greet(GreetingsRequest request) {
return new GreetingsResponse("hello, how can I help you?");
}

public OrderResponse order(OrderRequest request) {
String productName = request.getProductName();
public OrderResponse order(OrderRequest request) {
String productName = request.getProductName();

try {
// let Java reflection do its magic
IProduct product = (IProduct) Class.forName(productName).newInstance();
BigDecimal totalPrice = product.getPrice().multiply(new BigDecimal(request.getQuantity()));
return new OrderResponse(totalPrice);
} catch (Exception e) {
return null;
try {
// let Java reflection do its magic
IProduct product = (IProduct) Class.forName(productName).newInstance();
BigDecimal totalPrice = product.getPrice().multiply(new BigDecimal(request.getQuantity()));
return new OrderResponse(totalPrice);
} catch (Exception e) {
return null;
}
}
}

}
5 changes: 3 additions & 2 deletions src/main/java/ch/heigvd/res/chill/domain/IProduct.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

public interface IProduct {

String getName();
BigDecimal getPrice();
String getName();

BigDecimal getPrice();

}
22 changes: 22 additions & 0 deletions src/main/java/ch/heigvd/res/chill/domain/sjaubain/PG.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package ch.heigvd.res.chill.domain.sjaubain;

import ch.heigvd.res.chill.domain.IProduct;

import java.math.BigDecimal;

public class PG implements IProduct {

public final static String NAME = "Biere Prix Garantie";
public final static BigDecimal PRICE = new BigDecimal(0.5);

@Override
public String getName() {
return NAME;
}

@Override
public BigDecimal getPrice() {
return PRICE;
}

}
14 changes: 7 additions & 7 deletions src/test/java/ch/heigvd/res/chill/domain/BartenderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@

class BartenderTest {

@Test
void aBartenderShouldReplyToGreetings() {
Bartender john = new Bartender();
GreetingsRequest request = new GreetingsRequest("Hi there");
GreetingsResponse response = john.greet(request);
assertEquals("hello, how can I help you?", response.getText());
}
@Test
void aBartenderShouldReplyToGreetings() {
Bartender john = new Bartender();
GreetingsRequest request = new GreetingsRequest("Hi there");
GreetingsResponse response = john.greet(request);
assertEquals("hello, how can I help you?", response.getText());
}

}
33 changes: 33 additions & 0 deletions src/test/java/ch/heigvd/res/chill/domain/sjaubain/PGTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package ch.heigvd.res.chill.domain.sjaubain;

import ch.heigvd.res.chill.domain.Bartender;
import ch.heigvd.res.chill.domain.wasadigi.Boxer;
import ch.heigvd.res.chill.protocol.OrderRequest;
import ch.heigvd.res.chill.protocol.OrderResponse;
import org.junit.jupiter.api.Test;

import java.math.BigDecimal;

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

class PGTest {

@Test
void thePriceAndNameForGrimbergenShouldBeCorrect() {
PG beer = new PG();
assertEquals(beer.getName(), PG.NAME);
assertEquals(beer.getPrice(), PG.PRICE);
}

@Test
void aBartenderShouldAcceptAnOrderForPG() {

Bartender jane = new Bartender();
String productName = "ch.heigvd.res.chill.domain.sjaubain.PG";
OrderRequest request = new OrderRequest(3, productName);
OrderResponse response = jane.order(request);
BigDecimal expectedTotalPrice = PG.PRICE.multiply(new BigDecimal(3));
assertEquals(expectedTotalPrice, response.getTotalPrice());
}

}