2 * Sonar, open source software quality management tool.
3 * Copyright (C) 2008-2012 SonarSource
4 * mailto:contact AT sonarsource DOT com
6 * Sonar is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
11 * Sonar is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with Sonar; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
20 package org.sonar.java.bytecode.loader;
22 import static org.hamcrest.CoreMatchers.nullValue;
23 import static org.hamcrest.Matchers.allOf;
24 import static org.hamcrest.Matchers.endsWith;
25 import static org.hamcrest.Matchers.notNullValue;
26 import static org.hamcrest.Matchers.startsWith;
27 import static org.junit.Assert.assertThat;
28 import static org.junit.Assert.fail;
33 import org.junit.Test;
34 import org.sonar.java.ast.SquidTestUtils;
36 public class FileSystemLoaderTest {
38 @Test(expected = IllegalArgumentException.class)
39 public void shouldThrowIllegalArgumentException() throws Exception {
40 new FileSystemLoader(null);
44 public void testFindResource() throws Exception {
45 File dir = SquidTestUtils.getFile("/bytecode/bin/");
46 FileSystemLoader loader = new FileSystemLoader(dir);
48 assertThat(loader.findResource("notfound"), nullValue());
50 URL url = loader.findResource("tags/TagName.class");
51 assertThat(url, notNullValue());
52 assertThat(url.toString(), allOf(startsWith("file:"), endsWith("TagName.class")));
57 loader.findResource("tags/TagName.class");
59 } catch (IllegalStateException e) {
65 public void testLoadBytes() throws Exception {
66 File dir = SquidTestUtils.getFile("/bytecode/bin/");
67 FileSystemLoader loader = new FileSystemLoader(dir);
69 assertThat(loader.loadBytes("notfound"), nullValue());
71 assertThat(loader.loadBytes("tags/TagName.class"), notNullValue());
76 loader.loadBytes("tags/TagName.class");
78 } catch (IllegalStateException e) {
84 public void closeCanBeCalledMultipleTimes() throws Exception {
85 File dir = SquidTestUtils.getFile("/bytecode/bin/");
86 FileSystemLoader loader = new FileSystemLoader(dir);