Java tutorial
/* Copyright 2013 Mael Le Guvel This work is free. You can redistribute it and/or modify it under the terms of the Do What The Fuck You Want To Public License, Version 2, as published by Sam Hocevar. See the COPYING file for more details. */ package fr.mael.microrss.service; import java.util.Collection; import java.util.List; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.transaction.annotation.Transactional; import fr.mael.microrss.BaseTest; import fr.mael.microrss.domain.Category; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = { "/fr/mael/microrss/conf/application-context-test.xml" }) @Transactional public class CategoryServiceTest extends BaseTest { @Autowired private CategoryService categoryService; @Test public void testNb() { login(17); List<Category> categories = categoryService.list(); Category cat1 = getCategory(1, categories); Category cat3 = getCategory(3, cat1.getCategories()); Assert.assertEquals(new Integer(2), new Integer(cat3.getUserFeeds().size())); } private Category getCategory(Integer id, Collection<Category> categories) { for (Category cat : categories) { if (cat.getId().equals(id)) { return cat; } } return null; } }