forked from TheAlgorithms/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAbstractShapeFactoryTest.java
46 lines (39 loc) · 1.66 KB
/
AbstractShapeFactoryTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package src.test.java.com.designpatterns.creational.abstractfactory;
import org.junit.Assert;
import org.junit.Test;
import src.main.java.com.designpatterns.creational.abstractfactory.*;
public class AbstractShapeFactoryTest {
@Test
public void testAbstractShapeFactory() {
String failReason = "";
// Tests for 2-D shape factory
// Test for Line
AbstractShapeFactory shapeFactory = FactoryProvider.getShapeFactory(FactoryType.TWO_D_FACTORY);
Shape shape = shapeFactory.getShape(ShapeType.LINE);
if (shape.getShapeType() != ShapeType.LINE) {
failReason += "Could not create an object for LINE.\n";
}
if (shape.surfaceArea(5) != 0) {
failReason += "Surface area of Line is incorrect!.\n";
}
// Test for circle
shape = shapeFactory.getShape(ShapeType.CIRCLE);
if (shape.getShapeType() != ShapeType.CIRCLE) {
failReason += "Could not create an object for CIRCLE.\n";
}
if (shape.surfaceArea(9) != 254.46900494077323) {
failReason += "Surface area of Circle is incorrect!.\n";
}
// Test for 3-D shape factory
// Test for Sphere
shapeFactory = FactoryProvider.getShapeFactory(FactoryType.THREE_D_FACTORY);
shape = shapeFactory.getShape(ShapeType.SPHERE);
if (shape.getShapeType() != ShapeType.SPHERE) {
failReason += "Could not create and object for SPHERE.\n";
}
if (shape.surfaceArea(6) != 452.3893421169302) {
failReason += "Surface area of Sphere is incorrect!.\n";
}
Assert.assertEquals(failReason, "", failReason);
}
}