Path: blob/master/test/jdk/javax/sound/sampled/spi/MixerProvider/ExpectedNPEOnNull.java
41161 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 javax.sound.sampled.AudioSystem;24import javax.sound.sampled.Mixer;25import javax.sound.sampled.spi.MixerProvider;2627import static java.util.ServiceLoader.load;2829/**30* @test31* @bug 813510032* @author Sergey Bylokhov33*/34public final class ExpectedNPEOnNull {3536public static void main(final String[] args) throws Exception {37testAS();38for (final MixerProvider mp : load(MixerProvider.class)) {39testMP(mp);40}41testMP(customMP);42}4344/**45* Tests the part of AudioSystem API, which implemented via MixerProvider.46*/47private static void testAS() {48try {49AudioSystem.getMixer(null); // null should be accepted50} catch (final SecurityException | IllegalArgumentException ignored) {51// skip the specified exceptions only52}53}5455/**56* Tests the MixerProvider API directly.57*/58private static void testMP(MixerProvider mp) {59try {60mp.isMixerSupported(null);61throw new RuntimeException("NPE is expected: " + mp);62} catch (final NullPointerException ignored) {6364}65try {66mp.getMixer(null); // null should be accepted67} catch (SecurityException | IllegalArgumentException e) {68// skip the specified exceptions only69}70}7172/**73* Tests some default implementation of MixerProvider API, using the74* custom {@code MixerProvider}, which support nothing.75*/76static final MixerProvider customMP = new MixerProvider() {77@Override78public Mixer.Info[] getMixerInfo() {79return new Mixer.Info[0];80}8182@Override83public Mixer getMixer(Mixer.Info info) {84return null;85}86};87}888990