Skip to content

Commit 742e895

Browse files
committed
fixing maintainability, and intentionality issues
1 parent f2a409c commit 742e895

File tree

13 files changed

+113
-143
lines changed

13 files changed

+113
-143
lines changed

entity-component-system/src/main/java/com/iluwatar/App.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public class App {
3838
* @param args Command-line arguments (not used in this application)
3939
*/
4040
public static void main(String[] args) {
41-
System.out.print("Hello, World!");
41+
4242

4343
Entity entity1 = new Entity("Entity1");
4444
Entity entity2 = new Entity("Entity2");

entity-component-system/src/main/java/com/iluwatar/Component.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public abstract class Component {
3939
* Default constructor for the component.
4040
* Initializes a new component with default values.
4141
*/
42-
public Component() {
42+
protected Component() {
4343
// Constructor left empty intentionally, no specific initialization required
4444
}
4545

entity-component-system/src/main/java/com/iluwatar/Entity.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,6 @@ public void setEnabled(boolean enabled) {
158158
}
159159
}
160160

161-
public boolean getEnabled() {
162-
return isEnabled;
163-
}
164-
165161
/**
166162
* Updates the entity and its components.
167163
*
@@ -214,9 +210,9 @@ public List<Component> getComponents() {
214210
* Renders the entity and its components.
215211
*/
216212
public void renderEntity() {
217-
for (Component component : components) {
213+
//for (Component component : components) {
218214
// Render each component
219-
}
215+
//}
220216
}
221217

222218
// Getters and Setters for fields

entity-component-system/src/main/java/com/iluwatar/GameSystem.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,9 @@ public void update(float deltaTime) {
112112
* Renders the system (rendering logic can be implemented as needed).
113113
*/
114114
public void renderSystem() {
115-
for (Entity entity : entities) {
115+
//for (Entity entity : entities) {
116116
// Implement rendering logic
117-
}
117+
//}
118118
}
119119

120120
/**

entity-component-system/src/main/java/com/iluwatar/HealthComponent.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@
3333
*/
3434
public class HealthComponent extends Component {
3535

36-
private static final Logger logger = Logger.getLogger(HealthComponent.class.getName());
37-
3836
private float currentHealth;
3937
private float maxHealth;
4038
private boolean isAlive;

entity-component-system/src/main/java/com/iluwatar/VelocityComponent.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
*/
3333
public class VelocityComponent extends Component {
3434

35-
private static final Logger logger = Logger.getLogger(VelocityComponent.class.getName());
3635

3736
private float velocityX; // The velocity in the X direction
3837
private float velocityY; // The velocity in the Y direction

entity-component-system/src/test/java/com/iluwatar/AppTest.java

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import java.io.ByteArrayOutputStream;
3131
import java.io.PrintStream;
3232

33-
public class AppTest {
33+
class AppTest {
3434

3535
private Entity entity1;
3636
private Entity entity2;
@@ -42,7 +42,7 @@ public class AppTest {
4242
new float[]{0.0f, 45.0f, 0.0f}, new float[]{1.0f, 1.0f, 1.0f});
4343

4444
@BeforeEach
45-
public void setUp() {
45+
void setUp() {
4646
entity1 = new Entity("Entity1");
4747
entity2 = new Entity("Entity2");
4848

@@ -56,25 +56,20 @@ public void setUp() {
5656
entity1.addComponent(velocity1);
5757
}
5858
@Test
59-
public void testMain_shouldPrintHelloWorld() {
60-
61-
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
62-
System.setOut(new PrintStream(outputStream));
63-
64-
App.main(new String[]{});
65-
66-
assertEquals("Hello, World!", outputStream.toString(), "The output should be 'Hello, World!'");
59+
void testMain_DoesNotThrowException() {
60+
assertDoesNotThrow(() -> App.main(new String[]{}), "Child entity should not throw an exception if the parent is disabled.");
6761
}
62+
6863
@Test
69-
public void testHealthComponentApplyDamage() {
64+
void testHealthComponentApplyDamage() {
7065

7166
health1.applyDamage(30);
7267

7368
assertEquals(70, health1.getCurrentHealth(), "Health should be reduced by 30");
7469
}
7570

7671
@Test
77-
public void testVelocityComponentApplyForce() {
72+
void testVelocityComponentApplyForce() {
7873

7974
velocity1.applyForce(0.5f, 0.0f, 0.0f);
8075

@@ -84,7 +79,7 @@ public void testVelocityComponentApplyForce() {
8479
}
8580

8681
@Test
87-
public void testEntityUpdate() {
82+
void testEntityUpdate() {
8883

8984
float deltaTime = 1.0f / 60.0f;
9085
velocity1.setVelocityY(12.0f);
@@ -95,7 +90,7 @@ public void testEntityUpdate() {
9590
}
9691

9792
@Test
98-
public void testEntityHealthAfterDamageAndForce() {
93+
void testEntityHealthAfterDamageAndForce() {
9994

10095
health1.applyDamage(40);
10196

@@ -108,7 +103,7 @@ public void testEntityHealthAfterDamageAndForce() {
108103
}
109104

110105
@Test
111-
public void testFinalEntityStateAfterSimulation() {
106+
void testFinalEntityStateAfterSimulation() {
112107

113108
GameSystem gameSystem = new GameSystem();
114109
gameSystem.addEntity(entity1);
@@ -134,13 +129,13 @@ public void testFinalEntityStateAfterSimulation() {
134129
}
135130

136131
@Test
137-
public void testAddTransformComponent() {
132+
void testAddTransformComponent() {
138133
entity1.addComponent(transform1);
139134
assertTrue(entity1.getComponents().contains(transform1), "Entity1 should contain the added TransformComponent.");
140135
}
141136

142137
@Test
143-
public void testGameLoopUpdatesEntityState() {
138+
void testGameLoopUpdatesEntityState() {
144139
GameSystem gameSystem = new GameSystem();
145140
gameSystem.addEntity(entity1);
146141

@@ -154,15 +149,15 @@ public void testGameLoopUpdatesEntityState() {
154149
}
155150

156151
@Test
157-
public void testHealthReductionOverMultipleDamages() {
152+
void testHealthReductionOverMultipleDamages() {
158153
health1.applyDamage(20);
159154
health1.applyDamage(30);
160155

161156
assertEquals(50, health1.getCurrentHealth(), "Health should be reduced by 50 after two damage applications.");
162157
}
163158

164159
@Test
165-
public void testEntityRemovalFromGameSystem() {
160+
void testEntityRemovalFromGameSystem() {
166161
GameSystem gameSystem = new GameSystem();
167162
gameSystem.addEntity(entity1);
168163

@@ -173,15 +168,15 @@ public void testEntityRemovalFromGameSystem() {
173168
}
174169

175170
@Test
176-
public void testEntityWithoutComponents() {
171+
void testEntityWithoutComponents() {
177172
Entity entity = new Entity("EmptyEntity");
178173
entity.removeComponent(entity.getTransformComponent());
179174
assertTrue(entity.getComponents().isEmpty(), "Entity should have no components.");
180175
assertEquals("EmptyEntity", entity.getName(), "Entity should have the correct name.");
181176
}
182177

183178
@Test
184-
public void testSetParentAndChildren() {
179+
void testSetParentAndChildren() {
185180
Entity parentEntity = new Entity("ParentEntity");
186181
Entity childEntity = new Entity("ChildEntity");
187182

@@ -192,9 +187,8 @@ public void testSetParentAndChildren() {
192187
}
193188

194189
@Test
195-
public void testVelocityComponentReset() {
190+
void testVelocityComponentReset() {
196191
velocity1.applyForce(1.0f, 0.0f, 0.0f);
197-
float newVelocityX = velocity1.getVelocityX();
198192

199193
velocity1.resetVelocity();
200194

@@ -204,7 +198,7 @@ public void testVelocityComponentReset() {
204198
}
205199

206200
@Test
207-
public void testHealthAndForceAppliedTogether() {
201+
void testHealthAndForceAppliedTogether() {
208202
health1.applyDamage(20);
209203
velocity1.applyForce(0.5f, 0.0f, 0.0f);
210204

entity-component-system/src/test/java/com/iluwatar/ComponentTest.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,25 @@
2828

2929
import static org.junit.jupiter.api.Assertions.*;
3030

31-
public class ComponentTest {
31+
class ComponentTest {
3232
@Test
33-
public void testGetName() {
34-
Component component = new HealthComponent(100);
33+
void testGetName() {
34+
Component component = new HealthComponent(10);
3535
component.setName("Health");
3636

37-
assertEquals("Health", component.getName(), "getName should return 'TestComponent'");
37+
assertEquals("Health", component.getName(), "getName should return 'Health'");
3838
}
3939

4040
@Test
41-
public void testSetName() {
41+
void testSetName() {
4242
Component component = new HealthComponent(100);
43-
component.setName("Health");
44-
45-
assertEquals("Health", component.getName(), "getName should return 'TestComponent'");
43+
component.setName("Velocity");
44+
component.setName("Transform");
45+
assertEquals("Transform", component.getName(), "getName should return 'Transform'");
4646
}
4747

4848
@Test
49-
public void testComponentEnabled() {
49+
void testComponentEnabled() {
5050
Component component = new HealthComponent(100);
5151
component.setEnabled(true);
5252

@@ -57,7 +57,7 @@ public void testComponentEnabled() {
5757
}
5858

5959
@Test
60-
public void testComponentParent() {
60+
void testComponentParent() {
6161
Component component = new HealthComponent(100);
6262
Entity parentEntity = new Entity("ParentEntity");
6363

0 commit comments

Comments
 (0)