Project[] (int projectCount) { Project[] projects = new Project[projectCount]; for (int i = 0; i < projects.length; i++) { String locationHash = "project_" + i; projects[i] = (Project)Proxy.newProxyInstance( GistStorageImplTest.class.getClassLoader(), new Class[]{Project.class}, (proxy, method, args) -> { if (method.getName().equals("getLocationHash")) { return locationHash; } throw new UnsupportedOperationException("Only .getLocationHash() method is supported by this Project proxy"); }); } return projects; }