Path: blob/master/test/jdk/javax/sound/midi/spi/MidiDeviceProvider/FakeInfo.java
41154 views
/*1* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import java.util.Collection;24import java.util.HashSet;2526import javax.sound.midi.MidiDevice;27import javax.sound.midi.MidiDevice.Info;28import javax.sound.midi.MidiSystem;29import javax.sound.midi.MidiUnavailableException;30import javax.sound.midi.spi.MidiDeviceProvider;3132import static java.util.ServiceLoader.load;3334/**35* @test36* @bug 805974337* @summary MidiDeviceProvider shouldn't returns incorrect results in case of38* some unknown MidiDevice.Info39* @author Sergey Bylokhov40*/41public final class FakeInfo {4243private static final class Fake extends Info {4445Fake() {46super("a", "b", "c", "d");47}48}4950public static void main(final String[] args) {51final Info fake = new Fake();52// MidiSystem API53try {54MidiSystem.getMidiDevice(fake);55throw new RuntimeException("IllegalArgumentException expected");56} catch (final MidiUnavailableException e) {57throw new RuntimeException("IllegalArgumentException expected", e);58} catch (final IllegalArgumentException ignored) {59// expected60}61// MidiDeviceProvider API62final Collection<String> errors = new HashSet<>();63for (final MidiDeviceProvider mdp : load(MidiDeviceProvider.class)) {64try {65if (mdp.isDeviceSupported(fake)) {66throw new RuntimeException("fake is supported");67}68final MidiDevice device = mdp.getDevice(fake);69System.err.println("MidiDevice: " + device);70throw new RuntimeException("IllegalArgumentException expected");71} catch (final IllegalArgumentException e) {72errors.add(e.getMessage());73}74}75if (errors.size() != 1) {76throw new RuntimeException("Wrong number of messages:" + errors);77}78}79}808182