Index: /applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/PTAssistantValidatorTest.java
===================================================================
--- /applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/PTAssistantValidatorTest.java	(revision 33424)
+++ /applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/PTAssistantValidatorTest.java	(revision 33425)
@@ -329,5 +329,5 @@
 
     /**
-     * Carries out the second stage of the testing: sorting
+     * Carries out the second stage of the testing: sorting and segments
      *
      * @param r
@@ -341,69 +341,30 @@
         List<TestError> routeCheckerErrors = routeChecker.getErrors();
 
-        /*- At this point, there are 3 variants:
-         *
-         * 1) There are no errors => route is correct
-         * 2) There is only a sorting error (can only be 1), but otherwise
-         * correct.
-         * 3) There are some other errors/gaps that cannot be fixed by
-         * sorting => start further test (stop-by-stop)
-         *
-         * */
-
-        if (!routeCheckerErrors.isEmpty()) {
-            // Variant 2
-            // If there is only the sorting error, add it
-            this.errors.addAll(routeChecker.getErrors());
-        }
-
-        // if (!routeChecker.getHasGap()) {
-        // // Variant 1
-        // storeCorrectRouteSegments(r);
-        // }
-
-        // Variant 3:
-        proceedAfterSorting(r);
-
-    }
-
-    /**
-     * Carries out the stop-by-stop testing which includes building the route
-     * data model.
-     *
-     * @param r
-     *            route relation
-     */
-    private void proceedAfterSorting(Relation r) {
-
         SegmentChecker segmentChecker = new SegmentChecker(r, this);
-
-        // Check if the creation of the route data model in the segment checker
-        // worked. If it did not, it means the roles in the route relation do
-        // not match the tags of the route members.
-        if (!segmentChecker.getErrors().isEmpty()) {
-            this.errors.addAll(segmentChecker.getErrors());
-        }
-
         segmentChecker.performFirstStopTest();
         segmentChecker.performLastStopTest();
         segmentChecker.performStopNotServedTest();
 
-        boolean sortingErrorFound = false;
-        for (TestError error : this.errors) {
-            if (error.getCode() == ERROR_CODE_SORTING
-                    || error.getCode() == ERROR_CODE_PARTIAL_SORTING) {
-                sortingErrorFound = true;
-                break;
-            }
-        }
-        if (!sortingErrorFound) {
-            segmentChecker.performStopByStopTest();
-            segmentChecker.findFixes();
-        }
-
-        for (TestError error : segmentChecker.getErrors()) {
-            if (error.getCode() != PTAssistantValidatorTest.ERROR_CODE_RELATION_MEMBER_ROLES) {
-                this.errors.add(error);
-            }
+        //At this point, there are 3 variants:
+        if(routeCheckerErrors.isEmpty()) {
+             if (!routeChecker.getHasGap()) {
+                 //There are no errors => route is correct
+                 storeCorrectRouteSegments(r, segmentChecker.getManager(),
+                         segmentChecker.getAssigner());
+             } else {
+                 // There are some other errors/gaps that cannot be fixed by
+                 // sorting => start further test (stop-by-stop)
+                 segmentChecker.performStopByStopTest();
+                 segmentChecker.findFixes();
+             }
+        } else {
+            // There is only a sorting error (can only be 1), but otherwise
+            // correct
+            this.errors.addAll(routeChecker.getErrors());
+        }
+
+        //add eventual errors found
+        if (!segmentChecker.getErrors().isEmpty()) {
+            this.errors.addAll(segmentChecker.getErrors());
         }
     }
@@ -445,17 +406,15 @@
      *            route relation
      */
-    @SuppressWarnings("unused")
-    private void storeCorrectRouteSegments(Relation r) {
-        PTRouteDataManager manager = new PTRouteDataManager(r);
-        StopToWayAssigner assigner = new StopToWayAssigner(manager.getPTWays());
+    private void storeCorrectRouteSegments(Relation r,
+            PTRouteDataManager manager, StopToWayAssigner assigner) {
         if (manager.getPTStops().size() > 1) {
             for (int i = 1; i < manager.getPTStops().size(); i++) {
-                PTStop segmentStartStop = manager.getPTStops().get(i - 1);
-                PTStop segmentEndStop = manager.getPTStops().get(i);
-                Way segmentStartWay = assigner.get(segmentStartStop);
-                Way segmentEndWay = assigner.get(segmentEndStop);
-                List<PTWay> waysBetweenStops = manager.getPTWaysBetween(segmentStartWay, segmentEndWay);
-                PTRouteSegment routeSegment = new PTRouteSegment(segmentStartStop, segmentEndStop, waysBetweenStops, r);
-                SegmentChecker.addCorrectSegment(routeSegment);
+                PTStop startStop = manager.getPTStops().get(i - 1);
+                PTStop endStop = manager.getPTStops().get(i);
+                Way startWay = assigner.get(startStop);
+                Way endWay = assigner.get(endStop);
+                List<PTWay> waysBetweenStops = manager.getPTWaysBetween(startWay, endWay);
+                SegmentChecker.addCorrectSegment(
+                        new PTRouteSegment(startStop, endStop, waysBetweenStops, r));
             }
         }
Index: /applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/SegmentChecker.java
===================================================================
--- /applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/SegmentChecker.java	(revision 33424)
+++ /applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/SegmentChecker.java	(revision 33425)
@@ -66,7 +66,7 @@
         super(relation, test);
 
-        this.manager = new PTRouteDataManager(relation);
-
-        for (RelationMember rm : manager.getFailedMembers()) {
+        this.setManager(new PTRouteDataManager(relation));
+
+        for (RelationMember rm : getManager().getFailedMembers()) {
             List<Relation> primitives = new ArrayList<>(1);
             primitives.add(relation);
@@ -82,5 +82,5 @@
         }
 
-        this.assigner = new StopToWayAssigner(manager.getPTWays());
+        this.setAssigner(new StopToWayAssigner(getManager().getPTWays()));
 
     }
@@ -100,6 +100,5 @@
      * checking its correctness
      *
-     * @param segment
-     *            to add to the list of correct segments
+     * @param segment to add to the list of correct segments
      */
     public static synchronized void addCorrectSegment(PTRouteSegment segment) {
@@ -125,5 +124,5 @@
     public void performFirstStopTest() {
 
-        performEndStopTest(manager.getFirstStop());
+        performEndStopTest(getManager().getFirstStop());
 
     }
@@ -131,5 +130,5 @@
     public void performLastStopTest() {
 
-        performEndStopTest(manager.getLastStop());
+        performEndStopTest(getManager().getLastStop());
 
     }
@@ -237,5 +236,5 @@
         boolean contains = false;
 
-        List<PTWay> ptways = manager.getPTWays();
+        List<PTWay> ptways = getManager().getPTWays();
         for (PTWay ptway : ptways) {
             List<Way> ways = ptway.getWays();
@@ -260,6 +259,6 @@
 
     public void performStopNotServedTest() {
-        for (PTStop stop : manager.getPTStops()) {
-            Way way = assigner.get(stop);
+        for (PTStop stop : getManager().getPTStops()) {
+            Way way = getAssigner().get(stop);
             if (way == null) {
                 createStopError(stop);
@@ -274,5 +273,5 @@
     public void performStopByStopTest() {
 
-        if (manager.getPTStopCount() < 2) {
+        if (getManager().getPTStopCount() < 2) {
             return;
         }
@@ -281,16 +280,16 @@
 
         // Check each route segment:
-        for (int i = 1; i < manager.getPTStopCount(); i++) {
-
-            PTStop startStop = manager.getPTStops().get(i - 1);
-            PTStop endStop = manager.getPTStops().get(i);
-
-            Way startWay = assigner.get(startStop);
-            Way endWay = assigner.get(endStop);
-            if (startWay == null || endWay == null || (startWay == endWay && startWay == manager.getLastWay())) {
+        for (int i = 1; i < getManager().getPTStopCount(); i++) {
+
+            PTStop startStop = getManager().getPTStops().get(i - 1);
+            PTStop endStop = getManager().getPTStops().get(i);
+
+            Way startWay = getAssigner().get(startStop);
+            Way endWay = getAssigner().get(endStop);
+            if (startWay == null || endWay == null || (startWay == endWay && startWay == getManager().getLastWay())) {
                 continue;
             }
 
-            List<PTWay> segmentWays = manager.getPTWaysBetween(startWay, endWay);
+            List<PTWay> segmentWays = getManager().getPTWaysBetween(startWay, endWay);
 
             Node firstNode = findFirstNodeOfRouteSegmentInDirectionOfTravel(segmentWays.get(0));
@@ -319,12 +318,6 @@
             PTWay wronglySortedPtway = existingWaySortingIsWrong(segmentWays.get(0), firstNode,
                     segmentWays.get(segmentWays.size() - 1));
-            if (wronglySortedPtway == null) { // i.e. if the sorting is correct:
+            if (wronglySortedPtway != null) {  // i.e. if the sorting is wrong:
                 PTRouteSegment routeSegment = new PTRouteSegment(startStop, endStop, segmentWays, relation);
-                addCorrectSegment(routeSegment);
-            } else { // i.e. if the sorting is wrong:
-                PTRouteSegment routeSegment = new PTRouteSegment(startStop, endStop, segmentWays, relation);
-                // TestError error = this.errors.get(this.errors.size() - 1);
-                // wrongSegments.put(error, routeSegment);
-
                 List<Relation> primitives = new ArrayList<>(1);
                 primitives.add(relation);
@@ -381,9 +374,9 @@
         // 2) failing that, check which node this startWay shares with the
         // following way:
-        PTWay nextWay = manager.getNextPTWay(startWay);
+        PTWay nextWay = getManager().getNextPTWay(startWay);
         if (nextWay == null) {
             return null;
         }
-        PTWay wayAfterNext = manager.getNextPTWay(nextWay);
+        PTWay wayAfterNext = getManager().getNextPTWay(nextWay);
         Node[] nextWayEndnodes = nextWay.getEndNodes();
         if ((startWayEndnodes[0] == nextWayEndnodes[0] && startWayEndnodes[1] == nextWayEndnodes[1])
@@ -412,5 +405,5 @@
     private boolean isDeadendNode(Node node) {
         int count = 0;
-        for (PTWay ptway : manager.getPTWays()) {
+        for (PTWay ptway : getManager().getPTWays()) {
             List<Way> ways = ptway.getWays();
             for (Way way : ways) {
@@ -478,9 +471,9 @@
             // matter which of the geometrically equal PTWays it finds
 
-            PTWay nextPTWayAccortingToExistingSorting = manager.getNextPTWay(current);
+            PTWay nextPTWayAccortingToExistingSorting = getManager().getNextPTWay(current);
 
             // if current contains an unsplit roundabout:
             if (current.containsUnsplitRoundabout()) {
-                currentNode = manager.getCommonNode(current, nextPTWayAccortingToExistingSorting);
+                currentNode = getManager().getCommonNode(current, nextPTWayAccortingToExistingSorting);
                 if (currentNode == null) {
 
@@ -578,5 +571,5 @@
         List<PTWay> nextPtways = new ArrayList<>();
 
-        List<PTWay> ptways = manager.getPTWays();
+        List<PTWay> ptways = getManager().getPTWays();
 
         for (PTWay ptway : ptways) {
@@ -643,12 +636,8 @@
 
         for (Builder builder : wrongSegmentBuilders.keySet()) {
-
             if (wrongSegmentBuilders.get(builder).getRelation() == this.relation) {
-
                 findFix(builder);
-
-            }
-        }
-
+            }
+        }
     }
 
@@ -1134,3 +1123,19 @@
     }
 
+    public PTRouteDataManager getManager() {
+        return manager;
+    }
+
+    public void setManager(PTRouteDataManager manager) {
+        this.manager = manager;
+    }
+
+    public StopToWayAssigner getAssigner() {
+        return assigner;
+    }
+
+    public void setAssigner(StopToWayAssigner assigner) {
+        this.assigner = assigner;
+    }
+
 }
