1/*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package vogar.target.junit;
18
19import java.util.Comparator;
20import org.junit.runner.Describable;
21import org.junit.runner.Description;
22
23/**
24 * A comparator of {@link Describable} instances.
25 *
26 * <p>Compares two {@link Describable} objects by comparing their
27 * {@link Describable#getDescription() Description} using the
28 * {@link DescriptionComparator#getInstance()}.
29 */
30public class DescribableComparator implements Comparator<Describable> {
31
32    private static final DescribableComparator DESCRIBABLE_COMPARATOR =
33            new DescribableComparator();
34    private DescriptionComparator descriptionComparator = DescriptionComparator.getInstance();
35
36    public static DescribableComparator getInstance() {
37        return DESCRIBABLE_COMPARATOR;
38    }
39
40    private DescribableComparator() {
41    }
42
43    @Override
44    public int compare(Describable d1, Describable d2) {
45        return descriptionComparator.compare(d1.getDescription(), d2.getDescription());
46    }
47}
48