Skip to content

Commit

Permalink
Text addon tests now use the simple container
Browse files Browse the repository at this point in the history
  • Loading branch information
gastaldi committed Aug 6, 2015
1 parent 9212472 commit aa9bb8a
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 73 deletions.
7 changes: 0 additions & 7 deletions text/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,6 @@
<classifier>forge-addon</classifier>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.jboss.forge.furnace.container</groupId>
<artifactId>cdi</artifactId>
<classifier>forge-addon</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.forge.furnace.test</groupId>
<artifactId>furnace-test-harness</artifactId>
Expand Down
39 changes: 22 additions & 17 deletions text/src/main/java/org/jboss/forge/addon/text/Highlighter.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
import org.jboss.forge.addon.text.highlight.Encoder;
import org.jboss.forge.addon.text.highlight.Scanner;
import org.jboss.forge.addon.text.highlight.Syntax;
import org.jboss.forge.furnace.Furnace;
import org.jboss.forge.furnace.container.simple.lifecycle.SimpleContainer;
import org.jboss.forge.furnace.services.Imported;

public class Highlighter
{
private Imported<Scanner> importedScanners;

public Highlighter() {
public Highlighter()
{
Syntax.builtIns();
}

Expand All @@ -24,11 +24,14 @@ public void byType(String contentType, String content, OutputStream out)
throw new IllegalArgumentException("contentType must be specified");
}
Imported<Scanner> scanners = resolveScanners();
for(Scanner scanner : scanners) {
if(scanner.getType().getName().equalsIgnoreCase(contentType)) {
for (Scanner scanner : scanners)
{
if (scanner.getType().getName().equalsIgnoreCase(contentType))
{
try
{
execute(scanner, content, out);;
execute(scanner, content, out);
;
}
finally
{
Expand All @@ -47,11 +50,14 @@ public void byFileName(String fileName, String content, OutputStream out)
throw new IllegalArgumentException("contentType must be specified");
}
Imported<Scanner> scanners = resolveScanners();
for(Scanner scanner : scanners) {
if(scanner.getType().supports(fileName)) {
for (Scanner scanner : scanners)
{
if (scanner.getType().supports(fileName))
{
try
{
execute(scanner, content, out);;
execute(scanner, content, out);
;
}
finally
{
Expand Down Expand Up @@ -79,18 +85,17 @@ private void execute(Scanner scanner, String content, OutputStream out)
}

Syntax.Builder.create()
.encoderType(Encoder.Type.TERMINAL)
.output(out)
.scanner(scanner)
.execute(content);
.encoderType(Encoder.Type.TERMINAL)
.output(out)
.scanner(scanner)
.execute(content);
}

private Imported<Scanner> resolveScanners() {
if(importedScanners == null)
private Imported<Scanner> resolveScanners()
{
if (importedScanners == null)
{
Furnace furnace = SimpleContainer.getFurnace(this.getClass().getClassLoader());
if(furnace != null)
this.importedScanners = furnace.getAddonRegistry().getServices(Scanner.class);
importedScanners = SimpleContainer.getServices(getClass().getClassLoader(), Scanner.class);
}
return importedScanners;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,24 @@
*/
package org.jboss.forge.addon.text;

import javax.inject.Inject;

import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.forge.arquillian.AddonDeployment;
import org.jboss.forge.arquillian.AddonDeployments;
import org.jboss.forge.arquillian.archive.AddonArchive;
import org.jboss.forge.furnace.repositories.AddonDependencyEntry;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.forge.furnace.container.simple.lifecycle.SimpleContainer;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

@RunWith(Arquillian.class)
public class InflectorServiceTest
{
@Deployment
@AddonDeployments({
@AddonDeployment(name = "org.jboss.forge.addon:text"),
@AddonDeployment(name = "org.jboss.forge.furnace.container:cdi") })
public static AddonArchive getDeployment()
{
AddonArchive archive = ShrinkWrap.create(AddonArchive.class)
.addBeansXML()
.addAsAddonDependencies(
AddonDependencyEntry.create("org.jboss.forge.furnace.container:cdi"),
AddonDependencyEntry.create("org.jboss.forge.addon:text")
);
private Inflector inflector;

return archive;
@Before
public void setUp()
{
inflector = SimpleContainer.getServices(getClass().getClassLoader(), Inflector.class).get();
}

@Inject
private Inflector inflector;

@Test
public void testInflectorInjection() throws Exception
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,84 +2,91 @@

import java.io.ByteArrayOutputStream;

import javax.inject.Inject;

import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.forge.addon.text.Highlighter;
import org.jboss.forge.arquillian.AddonDeployment;
import org.jboss.forge.arquillian.AddonDeployments;
import org.jboss.forge.arquillian.AddonDependencies;
import org.jboss.forge.arquillian.AddonDependency;
import org.jboss.forge.arquillian.archive.AddonArchive;
import org.jboss.forge.furnace.repositories.AddonDependencyEntry;
import org.jboss.forge.furnace.container.simple.Service;
import org.jboss.forge.furnace.container.simple.lifecycle.SimpleContainer;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

@RunWith(Arquillian.class)
public class HighlighterTestCase {

public class HighlighterTestCase
{
@Deployment
@AddonDeployments({
@AddonDeployment(name = "org.jboss.forge.addon:text"),
@AddonDeployment(name = "org.jboss.forge.furnace.container:cdi") })
@AddonDependencies({
@AddonDependency(name = "org.jboss.forge.addon:text"),
@AddonDependency(name = "org.jboss.forge.furnace.container:simple")
})
public static AddonArchive getDeployment()
{
AddonArchive archive = ShrinkWrap.create(AddonArchive.class)
.addBeansXML()
.addAsAddonDependencies(
AddonDependencyEntry.create("org.jboss.forge.furnace.container:cdi"),
AddonDependencyEntry.create("org.jboss.forge.addon:text")
).addClass(TestScanner.class);

return archive;
return ShrinkWrap.create(AddonArchive.class)
.addClass(TestScanner.class)
.addAsServiceProvider(Service.class, HighlighterTestCase.class, TestScanner.class);
}

@Inject
private Highlighter highlighter;

@Before
public void setUp()
{
highlighter = SimpleContainer.getServices(getClass().getClassLoader(), Highlighter.class).get();
}

@Test
public void shouldFindImportedScannerServiceByType() {
public void shouldFindImportedScannerServiceByType()
{
ByteArrayOutputStream out = new ByteArrayOutputStream();
highlighter.byType(TestScanner.TYPE.getName(), "", out);

Assert.assertTrue(out.toString().contains(TestScanner.TEST_STRING));
}

@Test
public void shouldFindImportedScannerServiceByFileName() {
public void shouldFindImportedScannerServiceByFileName()
{
ByteArrayOutputStream out = new ByteArrayOutputStream();
highlighter.byFileName("something.test", "", out);

Assert.assertTrue(out.toString().contains(TestScanner.TEST_STRING));
}

@Test
public void shouldFindBuiltInScannerByType() {
public void shouldFindBuiltInScannerByType()
{
ByteArrayOutputStream out = new ByteArrayOutputStream();
highlighter.byType("JAVA", "public void should()", out);

Assert.assertTrue(out.toString().contains("public"));
}

@Test
public void shouldFindBuiltInScannerByFileName() {
public void shouldFindBuiltInScannerByFileName()
{
ByteArrayOutputStream out = new ByteArrayOutputStream();
highlighter.byFileName("test.java", "public void should()", out);

Assert.assertTrue(out.toString().contains("public"));
}

@Test
public void shouldFindScannerByAnyTypeCase() {
public void shouldFindScannerByAnyTypeCase()
{
ByteArrayOutputStream out = new ByteArrayOutputStream();
highlighter.byType("JAva", "public void should()", out);

Assert.assertTrue(out.toString().contains("public"));
}

@Test
public void shouldFindScannerByAnyFileNameCase() {
public void shouldFindScannerByAnyFileNameCase()
{
ByteArrayOutputStream out = new ByteArrayOutputStream();
highlighter.byFileName("tAsE.JavA", "public void should()", out);

Expand Down

0 comments on commit aa9bb8a

Please sign in to comment.