Java Code Examples for java.nio.file.ProviderMismatchException

Following code examples demonstrate how to use java.nio.file.ProviderMismatchExceptionfrom java. These examples are extracted from various highly rated open source projects. You can directly use these code snippets or view their entire linked source code. These snippets are extracted to provide contextual information about how to use this class in the real world. These samples also let you understand some good practices on how to use java.nio.file.ProviderMismatchExceptionand various code implementation of this class.

    public void test_constructor() {
        ProviderMismatchException exception = new ProviderMismatchException();
        assertEquals(null, exception.getMessage());
        assertTrue(exception instanceof IllegalArgumentException);
    } 


    @Test
    public default void verifyGenericType()
    throws Exception {
        final Class<SUT> sut = createNewSUT();
        assertTrue("This j8unit test interface is used with a generic type that is illegaly not assignable to ProviderMismatchException.class!",
                   ProviderMismatchException.class.isAssignableFrom(sut));
    } 

    @Category(Draft.class)
    public void create_ProviderMismatchException()
    throws Exception {
        @SuppressWarnings("unused")
        final ProviderMismatchException sut = new ProviderMismatchException();
    } 

  public static GeneratorType generator(final String generatorName) {

    List<GeneratorType> generators = services.stream()
        .filter(service -> service.getClass().getSimpleName().toUpperCase().startsWith(generatorName.toUpperCase()))
        .collect(Collectors.toList());

    if (generators.isEmpty()) {
      throw new ProviderNotFoundException(
          String.format("Generator type '%s' was not found", generatorName.toUpperCase()));
    } else if (generators.size() > 1) {
      throw new ProviderMismatchException("The provider name is ambigous. There are multiple match");
    }

    return generators.get(0);

  } 

    @Override
    public WatchKey register(WatchService watcher,
                             WatchEvent.Kind<?>[] events,
                             WatchEvent.Modifier... modifiers)
            throws IOException {
        if (watcher == null)
            throw new NullPointerException();
        if (!(watcher instanceof AbstractWatchService))
            throw new ProviderMismatchException();
        return ((AbstractWatchService) watcher).register(path, events, modifiers);
    } 

Advertisement
Javadoc
Unchecked exception thrown when an attempt is made to invoke a method on an object created by one fi

le system provider with a parameter created by a different file system provider.

Read More
Advertisement