Метод get не работает корректно в HashMap

Дана задача прочитать файл и при запуску теста метод get возвращает null хотя в мапе есть ключ и значение

public class Config {

    private final String path;
    private final Map<String, String> values = new HashMap<String, String>();
    private String temp;

    public Config(final String path) {
        this.path = path;
    }

    public void load() {
        StringJoiner out = new StringJoiner(System.lineSeparator());

        try (BufferedReader read = new BufferedReader(new FileReader(this.path))) {
           loadHelper(read);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void loadHelper(BufferedReader read) throws IOException {

        int count = 0;
        String one = null;
        String two = null;

        temp = read.readLine();
        while (temp != null) {
            if (temp.contains("#") || temp.length() == 0) {
                temp = read.readLine();
                continue;
            }
            for (String tmp : temp.split("=")) {
                if (count == 0) {
                    one = tmp;
                    count++;
                } else {
                    two = tmp;
                    count = 0;
                }
            }
            values.putIfAbsent(one, two);
            temp = read.readLine();
        }
    }



    public String value(String key) {
        String result = null;
        if (key == null && values.get(key).isEmpty()) {
            throw new UnsupportedOperationException("Don't impl this method yet!");
        } else {
            result = values.get(key);  эта строчка !
        }
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        return super.equals(obj);
    }

    @Override
    public int hashCode() {
        return super.hashCode();
    }

    @Override
    public String toString() {
        StringJoiner out = new StringJoiner(System.lineSeparator());
        try (BufferedReader read = new BufferedReader(new FileReader(this.path))) {
            read.lines().forEach(out::add);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return out.toString();
    }
}


    @Test
    public void whenPairWithoutComment() {
        String path = "data/pair_without_comment.properties";
        Config config = new Config(path);
        config.load();
        assertThat(config.value("name"), is("John Connor"));
    }

и файл откуда считывает информацию

pair_without_comment.properties в папке дата содержит name = John Connor


Ответы (0 шт):