|
2 | 2 |
|
3 | 3 | import com.badlogic.gdx.graphics.OrthographicCamera;
|
4 | 4 | import de.bitbrain.braingdx.util.GdxUtils;
|
| 5 | +import de.bitbrain.braingdx.util.Mutator; |
5 | 6 | import org.junit.Before;
|
6 | 7 | import org.junit.Test;
|
7 | 8 | import org.junit.runner.RunWith;
|
8 | 9 | import org.mockito.Mock;
|
9 | 10 | import org.mockito.runners.MockitoJUnitRunner;
|
10 | 11 |
|
| 12 | +import java.util.Comparator; |
| 13 | +import java.util.List; |
| 14 | + |
11 | 15 | import static org.assertj.core.api.Assertions.assertThat;
|
12 | 16 |
|
13 | 17 | @RunWith(MockitoJUnitRunner.class)
|
@@ -74,4 +78,58 @@ public void testUpdateWithListener() {
|
74 | 78 | world.update(0f);
|
75 | 79 | assertThat(object.getId()).isEqualTo(fakeIdSupplier.getCurrentId());
|
76 | 80 | }
|
| 81 | + |
| 82 | + @Test |
| 83 | + public void testGetObjects() { |
| 84 | + GameObject object1 = world.addObject(new Mutator<GameObject>() { |
| 85 | + @Override |
| 86 | + public void mutate(GameObject target) { |
| 87 | + target.setLeft(10); |
| 88 | + } |
| 89 | + }); |
| 90 | + GameObject object2 = world.addObject(new Mutator<GameObject>() { |
| 91 | + @Override |
| 92 | + public void mutate(GameObject target) { |
| 93 | + target.setLeft(30); |
| 94 | + } |
| 95 | + }); |
| 96 | + GameObject object3 = world.addObject(new Mutator<GameObject>() { |
| 97 | + @Override |
| 98 | + public void mutate(GameObject target) { |
| 99 | + target.setLeft(20); |
| 100 | + } |
| 101 | + }); |
| 102 | + List<GameObject> sorted = world.getObjects(); |
| 103 | + assertThat(sorted).containsExactly(object1, object2, object3); |
| 104 | + } |
| 105 | + |
| 106 | + @Test |
| 107 | + public void testGetObjectsSorted() { |
| 108 | + GameObject object1 = world.addObject(new Mutator<GameObject>() { |
| 109 | + @Override |
| 110 | + public void mutate(GameObject target) { |
| 111 | + target.setLeft(10); |
| 112 | + } |
| 113 | + }); |
| 114 | + GameObject object2 = world.addObject(new Mutator<GameObject>() { |
| 115 | + @Override |
| 116 | + public void mutate(GameObject target) { |
| 117 | + target.setLeft(30); |
| 118 | + } |
| 119 | + }); |
| 120 | + GameObject object3 = world.addObject(new Mutator<GameObject>() { |
| 121 | + @Override |
| 122 | + public void mutate(GameObject target) { |
| 123 | + target.setLeft(20); |
| 124 | + } |
| 125 | + }); |
| 126 | + List<GameObject> sorted = world.getObjects(new Comparator<GameObject>() { |
| 127 | + |
| 128 | + @Override |
| 129 | + public int compare(GameObject o1, GameObject o2) { |
| 130 | + return (int) (o1.getLeft() - o2.getLeft()); |
| 131 | + } |
| 132 | + }); |
| 133 | + assertThat(sorted).containsExactly(object1, object3, object2); |
| 134 | + } |
77 | 135 | }
|
0 commit comments