11/*
2- * Copyright 2002-2014 the original author or authors.
2+ * Copyright 2002-2015 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
2020import java .util .Map ;
2121import javax .sql .DataSource ;
2222
23+ import org .junit .Rule ;
2324import org .junit .Test ;
25+ import org .junit .rules .ExpectedException ;
2426
2527import static org .junit .Assert .*;
2628
@@ -32,17 +34,22 @@ public final class MapDataSourceLookupTests {
3234
3335 private static final String DATA_SOURCE_NAME = "dataSource" ;
3436
37+ @ Rule
38+ public final ExpectedException exception = ExpectedException .none ();
3539
36- @ SuppressWarnings ("unchecked" )
37- @ Test (expected =UnsupportedOperationException .class )
38- public void testGetDataSourcesReturnsUnmodifiableMap () throws Exception {
39- MapDataSourceLookup lookup = new MapDataSourceLookup (new HashMap <String , DataSource >());
40+
41+ @ Test
42+ @ SuppressWarnings ({ "unchecked" , "rawtypes" })
43+ public void getDataSourcesReturnsUnmodifiableMap () throws Exception {
44+ MapDataSourceLookup lookup = new MapDataSourceLookup ();
4045 Map dataSources = lookup .getDataSources ();
46+
47+ exception .expect (UnsupportedOperationException .class );
4148 dataSources .put ("" , "" );
4249 }
4350
4451 @ Test
45- public void testLookupSunnyDay () throws Exception {
52+ public void lookupSunnyDay () throws Exception {
4653 Map <String , DataSource > dataSources = new HashMap <String , DataSource >();
4754 StubDataSource expectedDataSource = new StubDataSource ();
4855 dataSources .put (DATA_SOURCE_NAME , expectedDataSource );
@@ -54,7 +61,7 @@ public void testLookupSunnyDay() throws Exception {
5461 }
5562
5663 @ Test
57- public void testSettingDataSourceMapToNullIsAnIdempotentOperation () throws Exception {
64+ public void setDataSourcesIsAnIdempotentOperation () throws Exception {
5865 Map <String , DataSource > dataSources = new HashMap <String , DataSource >();
5966 StubDataSource expectedDataSource = new StubDataSource ();
6067 dataSources .put (DATA_SOURCE_NAME , expectedDataSource );
@@ -67,7 +74,7 @@ public void testSettingDataSourceMapToNullIsAnIdempotentOperation() throws Excep
6774 }
6875
6976 @ Test
70- public void testAddingDataSourcePermitsOverride () throws Exception {
77+ public void addingDataSourcePermitsOverride () throws Exception {
7178 Map <String , DataSource > dataSources = new HashMap <String , DataSource >();
7279 StubDataSource overridenDataSource = new StubDataSource ();
7380 StubDataSource expectedDataSource = new StubDataSource ();
@@ -80,19 +87,22 @@ public void testAddingDataSourcePermitsOverride() throws Exception {
8087 assertSame (expectedDataSource , dataSource );
8188 }
8289
83- @ SuppressWarnings ( "unchecked" )
84- @ Test ( expected = ClassCastException . class )
85- public void testGetDataSourceWhereSuppliedMapHasNonDataSourceTypeUnderSpecifiedKey () throws Exception {
86- Map dataSources = new HashMap < String , DataSource > ();
90+ @ Test
91+ @ SuppressWarnings ({ "unchecked" , "rawtypes" } )
92+ public void getDataSourceWhereSuppliedMapHasNonDataSourceTypeUnderSpecifiedKey () throws Exception {
93+ Map dataSources = new HashMap ();
8794 dataSources .put (DATA_SOURCE_NAME , new Object ());
88- MapDataSourceLookup lookup = new MapDataSourceLookup ();
89- lookup .setDataSources (dataSources );
95+ MapDataSourceLookup lookup = new MapDataSourceLookup (dataSources );
96+
97+ exception .expect (ClassCastException .class );
9098 lookup .getDataSource (DATA_SOURCE_NAME );
9199 }
92100
93- @ Test ( expected = DataSourceLookupFailureException . class )
94- public void testGetDataSourceWhereSuppliedMapHasNoEntryForSpecifiedKey () throws Exception {
101+ @ Test
102+ public void getDataSourceWhereSuppliedMapHasNoEntryForSpecifiedKey () throws Exception {
95103 MapDataSourceLookup lookup = new MapDataSourceLookup ();
104+
105+ exception .expect (DataSourceLookupFailureException .class );
96106 lookup .getDataSource (DATA_SOURCE_NAME );
97107 }
98108
0 commit comments