OpenMonFactory { public OpenMon getInstance(String key) { String className = openMonFactoryMap.get(key); if (className == null) { className = openMonFactoryMap.get(key.toLowerCase()); } if (className == null) { System.err.println("Disabling Automon from " + getClass() + ": The OpenMon '" + key + "' is not in the map." + " Try one of the following: " + this); return defaultOpenMon; } OpenMon openMon = create(className); if (openMon == null) { return defaultOpenMon; } return openMon; } OpenMonFactory(OpenMon defaultOpenMon); void add(String... classNames); OpenMon getInstance(String key); OpenMon getFirstInstance(); String toString(); static final String JAMON; static final String JAVA_SIMON; static final String METRICS; static final String SYSOUT; static final String NULL_IMP; static final String NEW_RELIC; static final String STATSD; static final String MICROMETER; }
@Test public void testDefault() throws Exception { assertThat(factory.getInstance(OpenMonFactory.JAMON)).isInstanceOf(Jamon.class); assertThat(factory.getInstance(OpenMonFactory.JAVA_SIMON)).isInstanceOf(JavaSimon.class); assertThat(factory.getInstance(OpenMonFactory.METRICS)).isInstanceOf(Metrics.class); assertThat(factory.getInstance(OpenMonFactory.SYSOUT)).isInstanceOf(SysOut.class); assertThat(factory.getInstance(OpenMonFactory.NULL_IMP)).isInstanceOf(NullImp.class); assertThat(factory.getInstance(OpenMonFactory.NEW_RELIC)).isInstanceOf(NewRelicImp.class); assertThat(factory.getInstance(OpenMonFactory.STATSD)).isInstanceOf(StatsD.class); assertThat(factory.getInstance("jamon")).isInstanceOf(Jamon.class); assertThat(factory.getInstance("JAMon")).isInstanceOf(Jamon.class); assertThat(factory.getInstance("com.i.do.not.Exist")). describedAs("The default value should be returned if the constructor fails"). isEqualTo(defaultValue); }