Reputation: 63
I am taking an introductory course in Object-Oriented Programming.
Our current assignment is to create a version of "Tower Defense", and to help us we are using Junit and Lombok. We have been provided with tons of code to help with the GUI and such, but I don't think that all code is necessary to understand what the problem is, since it is literally the first thing we are supposed to do in the assignment.
package edu.chl.hajo.td.model;
import org.junit.Test;
import java.util.Arrays;
import java.util.List;
import static edu.chl.hajo.td.model.TowerDefence.TILE_SIZE;
import static org.junit.Assert.*;
/*
JUnit testing of model
*/
public class ModelTest {
@Test
public void testPath() throws Exception {
List<String> strPts = Arrays.asList(
"0,3", "3,3", "3,9", "8,9", "8,4", "12,4",
"12,12", "3,12", "3,17", "17,17",
"17,6", "20,6");
Path p = new Path(0, strPts, TILE_SIZE);
assertTrue(p.get(0) != null);
// etc.
}
// Add more tests as needed
}
So the error message I get is "cannot resolve method 'get(int)'". Here is what I have written in the class 'Path':
import java.util.ArrayList;
import java.util.List;
import lombok.Data;
/*
* A path for creeps (waves) to follow
*/
public class Path {
@Getter
private final int id;
@Getter
private final int size;
@Getter
private final List<Point2D> points; //= null; // TODO
// TODO
public Path(int id, List list, int size) {
this.id = id;
this.points = list;
this.size = size;
}
}
But if I understand "Getters" correctly, the @Getter only creates methods like getId, getSize, and getPoints. What really is the test trying to do with get(0)? I feel like it would make sense if the thing we wanted to get something from was a list, but here we are trying to get something from a Path.
I hope some of this makes sense to someone.
Upvotes: 0
Views: 247
Reputation: 17292
I think you are supposed to implement the Path
class such that when the constructor is called as in the test the Path is created with a list of Point2D
for each coordinate. And get(int i)
is a method you have to implement to return that point from the path.
Lombok implements simple getters (like getId()
), but not necessarily a more complex get(int i)
method that returns a specific point from the path.
Upvotes: 1