ConvertRecord { public static List<Todo> convertTodos(List<CSVRecord> records) { List<Todo> list = new ArrayList<>(records.size()); for (CSVRecord record : records) { if (record.size() < 2) break; String id = record.get(0); String text = record.get(1); Todo todo = new Todo().setTodoId(Integer.parseInt(id)).setText(text); String developmentString = record.get(2); if (!"NULL".equals(developmentString)) { boolean development = parseBoolean(developmentString); todo.setDevelopment(development); } String distributionString = record.get(3); if (!"NULL".equals(distributionString)) { boolean distribution = parseBoolean(distributionString); todo.setDistribution(distribution); } if(record.size() >= 5) { Optional.ofNullable(record.get(4)) .filter(json -> ! "NULL".equals(json)) .map(json -> (Map<String, String>) gson.fromJson(json, new TypeToken<Map<String, String>>() { }.getType())) .ifPresent(todo::setExternalIds); } list.add(todo); } return list; } private  ConvertRecord(); static List<RiskCategory> convertRiskCategories(List<CSVRecord> records); static Serializer<RiskCategory> riskCategorySerializer(); static List<Risk> convertRisks(List<CSVRecord> records, Map<Integer, RiskCategory> categories); static Serializer<Risk> riskSerializer(); static Map<String, Set<String>> convertCustomProperties(List<CSVRecord> records); static Map<Integer, PropertyWithValue> convertCustomPropertiesById(List<CSVRecord> records); static void fillTodoCustomPropertyInfo(List<Todo> todos, List<PropertyWithValueAndId> customProperties, SetMultimap<Integer, Integer> todoCustomPropertyMap); static Serializer<PropertyWithValueAndId> customPropertiesSerializer(); static List<Todo> convertTodos(List<CSVRecord> records); static Serializer<Todo> todoSerializer(); static List<Obligation> convertObligation(List<CSVRecord> records); static Serializer<Obligation> obligationSerializer(); static void putToTodos(Map<Integer, Obligation> obligations, Map<Integer, Todo> todos, Map<Integer, Set<Integer>> obligationTodo); static List<LicenseType> convertLicenseTypes(List<CSVRecord> records); static Serializer<LicenseType> licenseTypeSerializer(); static List<License> fillLicenses(List<CSVRecord> records, Map<Integer, LicenseType> licenseTypeMap, Map<Integer, Todo> todoMap, Map<Integer, Risk> riskMap, Map<String, Set<Integer>> licenseTodo, Map<String, Set<Integer>> licenseRisk); static Serializer<License> licenseSerializer(); static Map<String, Set<Integer>> convertRelationalTable(List<CSVRecord> records); static Map<Integer, Set<Integer>> convertRelationalTableWithIntegerKeys(List<CSVRecord> records); @NotNull static SetMultimap<Integer, Integer> getTodoToObligationMap(List<Todo> todos); @NotNull static SetMultimap<String, Integer> getLicenseToTodoMap(List<License> licenses); @NotNull static SetMultimap<String, Integer> getLicenseToRiskMap(List<License> licenses); static void addLicenses(LicenseService.Iface licenseClient, List<License> licensesToAdd, Logger log, User user); static List<List<String>> serialize(List<T> in, Serializer<T> serializer); static List<List<String>> serialize(List<T> in, List<String> headers, Function<T, List<String>> function); @NotNull static List<List<String>> serialize(SetMultimap<T, U> aToB, List<String> headers); static Gson gson; }
@Test public void testConvertTodosEmpty() throws Exception { List<Todo> todos = convertTodos(emptyRecord); assertThat(todos.size(), is(0)); }
@Test public void testConvertTodosFull() throws Exception { List<Todo> todos = convertTodos(fullTodoRecord); assertThat(todos.size(), is(2)); assertThat(todos.get(0).getText(), is("text1")); assertThat(todos.get(0).getTodoId(), is(1)); assertThat(todos.get(0).isDevelopment(), is(true)); assertThat(todos.get(0).isDistribution(), is(true)); assertThat(todos.get(1).getText(), is("text2")); assertThat(todos.get(1).getTodoId(), is(2)); assertThat(todos.get(1).isDevelopment(), is(false)); assertThat(todos.get(1).isDistribution(), is(false)); assertThat(todos.get(1).getExternalIds().size(), is(1)); assertThat(todos.get(1).getExternalIds().get("key"), is("value")); }