Changeset 16436 in josm for trunk/test/unit


Ignore:
Timestamp:
2020-05-17T12:08:17+02:00 (5 years ago)
Author:
simon04
Message:

see #19251 - Java 8: use Stream

Location:
trunk/test/unit/org/openstreetmap/josm
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/data/osm/ChangesetTest.java

    r13813 r16436  
    1313import java.util.HashMap;
    1414import java.util.Map;
     15import java.util.stream.Collectors;
     16import java.util.stream.IntStream;
    1517
    1618import org.junit.Assert;
     
    6567        // Add a map with too long values => IllegalArgumentException
    6668        keys = new HashMap<>();
    67         StringBuilder b = new StringBuilder(MAX_CHANGESET_TAG_LENGTH + 1);
    68         for (int i = 0; i < MAX_CHANGESET_TAG_LENGTH + 1; i++) {
    69            b.append("x");
    70         }
    71         keys.put("test", b.toString());
     69        // Java 11: use String.repeat
     70        keys.put("test", IntStream.range(0, MAX_CHANGESET_TAG_LENGTH + 1).mapToObj(i -> "x").collect(Collectors.joining()));
    7271        try {
    7372            cs.setKeys(keys);
  • trunk/test/unit/org/openstreetmap/josm/data/projection/ProjectionRegressionTest.java

    r16099 r16436  
    1313import java.util.ArrayList;
    1414import java.util.HashMap;
    15 import java.util.HashSet;
    1615import java.util.List;
    1716import java.util.Map;
     
    1918import java.util.Set;
    2019import java.util.TreeSet;
     20import java.util.stream.Collectors;
    2121
    2222import org.junit.BeforeClass;
     
    160160    public void testNonRegression() throws IOException {
    161161        List<TestData> allData = readData();
    162         Set<String> dataCodes = new HashSet<>();
    163         for (TestData data : allData) {
    164             dataCodes.add(data.code);
    165         }
     162        Set<String> dataCodes = allData.stream().map(data -> data.code).collect(Collectors.toSet());
    166163
    167164        StringBuilder fail = new StringBuilder();
  • trunk/test/unit/org/openstreetmap/josm/io/GeoJSONReaderTest.java

    r16311 r16436  
    1515import java.util.List;
    1616import java.util.Optional;
     17import java.util.stream.IntStream;
    1718
    1819import org.junit.Rule;
     
    160161            return false;
    161162        }
    162         for (int i = 0; i < ((Way) p1).getNodes().size(); i++) {
    163             if (!areEqualNodes(((Way) p1).getNode(i), ((Way) p2).getNode(i))) {
    164                 return false;
    165             }
    166         }
    167         return true;
     163        return IntStream.range(0, ((Way) p1).getNodes().size())
     164                .allMatch(i -> areEqualNodes(((Way) p1).getNode(i), ((Way) p2).getNode(i)));
    168165    }
    169166}
  • trunk/test/unit/org/openstreetmap/josm/io/remotecontrol/RemoteControlTest.java

    r15469 r16436  
    1313import java.security.GeneralSecurityException;
    1414import java.security.KeyStore.TrustedCertificateEntry;
     15import java.util.stream.Collectors;
    1516
    1617import org.junit.After;
     
    8889        try (InputStream is = connection.getErrorStream()) {
    8990            // TODO this code should be refactored somewhere in Utils as it is used in several JOSM classes
    90             StringBuilder responseBody = new StringBuilder();
     91            String responseBody;
    9192            try (BufferedReader in = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8))) {
    92                 String s;
    93                 while ((s = in.readLine()) != null) {
    94                     responseBody.append(s);
    95                     responseBody.append("\n");
    96                 }
     93                responseBody = in.lines().collect(Collectors.joining("\n"));
    9794            }
    98             assert responseBody.toString().contains(RequestProcessor.getUsageAsHtml());
     95            assert responseBody.contains(RequestProcessor.getUsageAsHtml());
    9996        }
    10097    }
Note: See TracChangeset for help on using the changeset viewer.