This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ProductCatalogue { | |
private Multimap<Class, ? extends Item> catalogue = ArrayListMultimap.create(); | |
public void add(Item item) { | |
catalogue.put(item.getClass(), item); | |
} | |
public <T extends Item> Collection<Item> list(Class<T> clazz) { | |
return catalogue.get(clazz); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BiMap<String, String> languageCodes = HashBiMap.create(); | |
languageCodes.put("en", "English"); | |
languageCodes.put("fr", "French"); | |
languageCodes.put("zh", "Chinese"); | |
assert "English" == languageCodes.get("en"); | |
assert "en&" == languageCodes.inverse().get("English"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public Item(String id, String name) { | |
this.id = Preconditions.checkNotNull(id, "id must not be null"); | |
this.name = Preconditions.checkNotNull(name, "name must not be null"); | |
Preconditions.checkArgument(name.length() < 6, "name must be longer than 6 chars"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Voyage { | |
private Country targetcountry; | |
private int capacity; | |
private List<Cargo> items = Constraints.constrainedList(new ArrayList<Cargo>(), new Constraint<Cargo>() { | |
@Override | |
public Cargo checkElement(Cargo cargo) { | |
Preconditions.checkNotNull(cargo); | |
Preconditions.checkArgument(targetcountry.allows(cargo)); | |
Preconditions.checkArgument(cargo.getUnits() > 0); | |
return cargo; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Predicate<Item> heavyItemPolicy = new Predicate<Item>() { | |
@Override | |
public boolean apply(Item item) { | |
if(item.getWeight() > 1000){ | |
return true; | |
} | |
return false; | |
} | |
}; | |
Collection<Item> heavyItems = Collections2.filter(order, heavyItemPolicy); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function currencyConverter = new Function<Double, Item>() { | |
@Override | |
public Double apply(Item item) { | |
return item.getPrice() * ANOTHER_CURRENCY; | |
} | |
} | |
Collection<Double> prices = Collections2.transform(order, currencyConverter); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
InMemoryStorage storage = new InMemoryStorage(); | |
// add a few Item.class objects to storage | |
Criteria middleprice = field("price").is(largerThan(100)).and(lessThan(200)); | |
Criteria expired = field("expires").is(after(currentDate)); | |
Collection<Item> result = storage.select(middleprice.and(not(expired))).from(Item.class); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RunWith(JUnitRunner.class) | |
public class JUnitRunnerDemoTest { | |
@Test | |
public void demoFixtureArguments(FixtureExample one, FixtureExample two, FixtureExample three) { | |
System.out.println("demonstrateFixtureArguments(" + one + ", " + two + ", " + three + ")"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
demonstrateFixtureArguments(0, 0, 0) | |
demonstrateFixtureArguments(1, 0, 0) | |
demonstrateFixtureArguments(0, 1, 0) | |
demonstrateFixtureArguments(1, 1, 0) | |
demonstrateFixtureArguments(0, 0, 1) | |
demonstrateFixtureArguments(1, 0, 1) | |
demonstrateFixtureArguments(0, 1, 1) | |
demonstrateFixtureArguments(1, 1, 1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DummyTest { | |
@Rule | |
public IgnoreLeadingFailure ilf = new IgnoreLeadingFailure(); | |
@Test | |
public void testTest() { | |
assertTrue(false); | |
} | |
} |