### Question:
SpiLoader { public static <T> List<T> loadInstanceListSorted(Class<T> clazz) { try { String key = clazz.getName(); ServiceLoader<T> serviceLoader = SERVICE_LOADER_MAP.get(key); if (serviceLoader == null) { serviceLoader = ServiceLoaderUtil.getServiceLoader(clazz); SERVICE_LOADER_MAP.put(key, serviceLoader); } List<SpiOrderWrapper<T>> orderWrappers = new ArrayList<>(); for (T spi : serviceLoader) { int order = SpiOrderResolver.resolveOrder(spi); SpiOrderResolver.insertSorted(orderWrappers, spi, order); RecordLog.info("[SpiLoader] Found {} SPI: {} with order {}", clazz.getSimpleName(), spi.getClass().getCanonicalName(), order); } List<T> list = new ArrayList<>(orderWrappers.size()); for (int i = 0; i < orderWrappers.size(); i++) { list.add(orderWrappers.get(i).spi); } return list; } catch (Throwable t) { RecordLog.error("[SpiLoader] ERROR: loadInstanceListSorted failed", t); t.printStackTrace(); return new ArrayList<>(); } } private  SpiLoader(); static T loadFirstInstance(Class<T> clazz); static T loadFirstInstanceOrDefault(Class<T> clazz, Class<? extends T> defaultClass); static T loadHighestPriorityInstance(Class<T> clazz); static List<T> loadInstanceList(Class<T> clazz); static List<T> loadInstanceListSorted(Class<T> clazz); static List<T> loadPrototypeInstanceListSorted(Class<T> clazz);  }### Answer:
@Test public void testLoadInstanceListSorted() { List<ProcessorSlot> sortedSlots = SpiLoader.loadInstanceListSorted(ProcessorSlot.class); assertNotNull(sortedSlots); assertEquals(8, sortedSlots.size()); int index = 0; assertTrue(sortedSlots.get(index++) instanceof NodeSelectorSlot); assertTrue(sortedSlots.get(index++) instanceof ClusterBuilderSlot); assertTrue(sortedSlots.get(index++) instanceof LogSlot); assertTrue(sortedSlots.get(index++) instanceof StatisticSlot); assertTrue(sortedSlots.get(index++) instanceof AuthoritySlot); assertTrue(sortedSlots.get(index++) instanceof SystemSlot); assertTrue(sortedSlots.get(index++) instanceof FlowSlot); assertTrue(sortedSlots.get(index++) instanceof DegradeSlot); List<ProcessorSlot> sortedSlots2 = SpiLoader.loadInstanceListSorted(ProcessorSlot.class); assertNotSame(sortedSlots, sortedSlots2); assertEquals(sortedSlots.size(), sortedSlots2.size()); for (int i = 0; i < sortedSlots.size(); i++) { ProcessorSlot slot = sortedSlots.get(i); ProcessorSlot slot2 = sortedSlots2.get(i); assertEquals(slot.getClass(), slot2.getClass()); assertSame(slot, slot2); } }