| 1 |
/* |
| 2 |
* JBoss, Home of Professional Open Source. |
| 3 |
* Copyright 2014 Red Hat, Inc., and individual contributors |
| 4 |
* as indicated by the @author tags. |
| 5 |
* |
| 6 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 |
* you may not use this file except in compliance with the License. |
| 8 |
* You may obtain a copy of the License at |
| 9 |
* |
| 10 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 11 |
* |
| 12 |
* Unless required by applicable law or agreed to in writing, software |
| 13 |
* distributed under the License is distributed on an "AS IS" BASIS, |
| 14 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 |
* See the License for the specific language governing permissions and |
| 16 |
* limitations under the License. |
| 17 |
*/ |
| 18 |
|
| 19 |
package org.jboss.modules.ref; |
| 20 |
|
| 21 |
import org.jboss.modules.ref.Reference.Type; |
| 22 |
import org.junit.Test; |
| 23 |
|
| 24 |
/** |
| 25 |
* Test for {@link StrongReference}. |
| 26 |
* |
| 27 |
* @author <a href="mailto:[email protected]">Flavia Rainone</a> |
| 28 |
*/ |
| 29 |
public class StrongReferenceTestCase extends AbstractReferenceTest{ |
| 30 |
|
| 31 |
@Test |
| 32 |
public void plainStrongReference() { |
| 33 |
final Reference<String, String> reference = new StrongReference<String, String>("referent", "attachment"); |
| 34 |
assertReference(reference, "referent", "attachment"); |
| 35 |
} |
| 36 |
|
| 37 |
@Test |
| 38 |
public void noAttachmentReference() { |
| 39 |
final Reference<String, Void> reference = new StrongReference<String, Void>("noAttachmentReference"); |
| 40 |
assertReference(reference, "noAttachmentReference", null); |
| 41 |
} |
| 42 |
|
| 43 |
@Test |
| 44 |
public void nullReference() { |
| 45 |
final Reference<Object, String> reference = new StrongReference<Object, String>(null, "attachment of null reference"); |
| 46 |
assertReference(reference, null, "attachment of null reference"); |
| 47 |
} |
| 48 |
|
| 49 |
@Test |
| 50 |
public void nullReferenceWithoutAttachment() { |
| 51 |
final Reference<StringBuffer, Number> reference = new StrongReference<StringBuffer, Number>(null); |
| 52 |
assertReference(reference, null, null); |
| 53 |
} |
| 54 |
|
| 55 |
@Override |
| 56 |
<T, A> Reference<T, A> createReference(T value, A attachment) { |
| 57 |
return new StrongReference<T, A>(value, attachment); |
| 58 |
} |
| 59 |
|
| 60 |
@Override |
| 61 |
Type getTestedReferenceType() { |
| 62 |
return Type.STRONG; |
| 63 |
} |
| 64 |
} |